mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 06:09:45 +00:00
Добавил парсер для слайдера в проектах
This commit is contained in:
1 parent
3b201e8a8b
commit
ec6275a4f2
2 files changed
+17
-1
No files matched your search
@@ -2,7 +2,8 @@ import Parse from "html-react-parser";
|
||||
|
||||
export type ParsedContent =
|
||||
| { type: "html"; element: any } // Сохраняем исходные HTML-элементы
|
||||
| { type: "mediablock"; value: string[] }; // Группируем медиа-элементы
|
||||
| { type: "mediablock"; value: string[] } // Группируем медиа-элементы
|
||||
| { type: "slider"; value: string[] }; // Группируем картинки под слайдер
|
||||
|
||||
export const parseContent = (html: string): ParsedContent[] => {
|
||||
const elements = Parse(html);
|
||||
@@ -33,6 +34,18 @@ export const parseContent = (html: string): ParsedContent[] => {
|
||||
mediaBuffer = [];
|
||||
}
|
||||
|
||||
if (node.props.className.includes('wp-block-gallery')) {
|
||||
const slider = [];
|
||||
for (const child of node.props.children) {
|
||||
const imgSrc = child.props?.children.props?.src;
|
||||
if (imgSrc) {
|
||||
slider.push(imgSrc);
|
||||
}
|
||||
}
|
||||
result.push({ type: "slider", value: slider })
|
||||
return;
|
||||
}
|
||||
|
||||
// Сохраняем текущий элемент как есть
|
||||
result.push({ type: "html", element: node });
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useResizeObserver } from "@/shared/lib/ResizeObserver/ResizeObserver";
|
||||
import { App } from "@/shared/types/app";
|
||||
|
||||
import "./Projects.scss";
|
||||
import Slider from "../Slider/Slider";
|
||||
|
||||
interface WpPostProps {
|
||||
post: App.WpPostPage;
|
||||
@@ -28,6 +29,8 @@ export default function WpPost({
|
||||
post.content.map((el, index) => {
|
||||
if (el.type === "mediablock") {
|
||||
return <MediaBlock key={index} images={el.value} />;
|
||||
} else if (el.type === "slider") {
|
||||
return <Slider images={el.value} />
|
||||
}
|
||||
return <div key={index}>{el.element}</div>;
|
||||
})}
|
||||
|
||||
Reference in new issue
Block a user