mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 02:59: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 });
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user