Добавил парсер для слайдера в проектах

This commit is contained in:
ifraimka1 committed 2025-05-02 12:41:15 +03:00
1 parent 3b201e8a8b
commit ec6275a4f2
2 files changed
+17 -1

No files matched your search

+14 -1
View File
@@ -2,7 +2,8 @@ import Parse from "html-react-parser";
export type ParsedContent = export type ParsedContent =
| { type: "html"; element: any } // Сохраняем исходные HTML-элементы | { type: "html"; element: any } // Сохраняем исходные HTML-элементы
| { type: "mediablock"; value: string[] }; // Группируем медиа-элементы | { type: "mediablock"; value: string[] } // Группируем медиа-элементы
| { type: "slider"; value: string[] }; // Группируем картинки под слайдер
export const parseContent = (html: string): ParsedContent[] => { export const parseContent = (html: string): ParsedContent[] => {
const elements = Parse(html); const elements = Parse(html);
@@ -33,6 +34,18 @@ export const parseContent = (html: string): ParsedContent[] => {
mediaBuffer = []; 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 }); result.push({ type: "html", element: node });
}; };
+3
View File
@@ -6,6 +6,7 @@ import { useResizeObserver } from "@/shared/lib/ResizeObserver/ResizeObserver";
import { App } from "@/shared/types/app"; import { App } from "@/shared/types/app";
import "./Projects.scss"; import "./Projects.scss";
import Slider from "../Slider/Slider";
interface WpPostProps { interface WpPostProps {
post: App.WpPostPage; post: App.WpPostPage;
@@ -28,6 +29,8 @@ export default function WpPost({
post.content.map((el, index) => { post.content.map((el, index) => {
if (el.type === "mediablock") { if (el.type === "mediablock") {
return <MediaBlock key={index} images={el.value} />; return <MediaBlock key={index} images={el.value} />;
} else if (el.type === "slider") {
return <Slider images={el.value} />
} }
return <div key={index}>{el.element}</div>; return <div key={index}>{el.element}</div>;
})} })}