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

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 =
| { 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 });
};