перенес структуру Севы со своими правками

This commit is contained in:
ifraimka1 committed 2025-04-01 15:25:46 +03:00
1 parent 3a1cac0dfe
commit 808d97eb4b
331 files changed
+12260 -19950

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
import Parse from "html-react-parser";
export type ParsedContent =
| { type: "html"; element: any } // Сохраняем исходные HTML-элементы
| { type: "mediablock"; value: string[] }; // Группируем медиа-элементы
export const parseContent = (html: string): ParsedContent[] => {
const elements = Parse(html);
const result: ParsedContent[] = [];
let mediaBuffer: string[] = [];
const processNode = (node: any) => {
if (typeof node === "string") {
// Пустые строки (например, переносы строк) игнорируем
if (node.trim() !== "") {
result.push({ type: "html", element: node });
}
return;
}
// Обработка медиа-элементов (img внутри figure)
if (node.type === "figure") {
const imgSrc = node.props.children?.props?.src;
if (imgSrc) {
mediaBuffer.push(imgSrc);
}
return; // Пропускаем добавление figure в результат
}
// Если есть накопленные медиа-элементы, добавляем их как mediablock
if (mediaBuffer.length > 0) {
result.push({ type: "mediablock", value: [...mediaBuffer] });
mediaBuffer = [];
}
// Сохраняем текущий элемент как есть
result.push({ type: "html", element: node });
};
if (Array.isArray(elements)) {
elements.forEach(processNode);
} else {
processNode(elements);
}
// Добавляем оставшиеся медиа-элементы, если они есть
if (mediaBuffer.length > 0) {
result.push({ type: "mediablock", value: [...mediaBuffer] });
}
return result;
};
+36
View File
@@ -0,0 +1,36 @@
import WPAPI from "wpapi";
export const wp = new WPAPI({
endpoint: "https://test.skbkit.ru/wp-json/",
username: "admin",
password: "admin",
});
export const skbEndpoint = wp._options.endpoint;
declare namespace App {
type MediaItem = {
id: number;
src: string;
category: string;
name: string;
};
type ProjectPost = {
id: number;
title: string;
content: ParsedContent[];
lab: string;
preview?: string;
};
type ParsedContent =
| { type: "text"; content: string }
| { type: "media"; urls: string[] };
type ContactFormData = {
name: string;
email: string;
message: string;
subject?: string;
};
}