Новые изменения в компоенты

This commit is contained in:
Web-serfer 2026-04-26 22:45:19 +05:00
parent a14c18542e
commit faf02848ed
3 changed files with 33 additions and 19 deletions

View file

@ -26,18 +26,17 @@ const { likes = 0, dislikes = 0 } = await getPostVotesStats(post.id).catch(() =>
// Конвертируем markdown в HTML
const contentHtml = marked(post.content || '');
// Извлекаем заголовки для оглавления
const headingRegex = /^(#{2,3})\s+(.+)$/gm;
// Извлекаем заголовки для оглавления (поддержка HTML и Markdown)
const headingRegex = /<h([2-3])[^>]*>([^<]+)<\/?h[2-3]>/gi;
const tocItems: { id: string; text: string; level: number }[] = [];
const body = post.content || '';
let match;
let headingIndex = 0;
while ((match = headingRegex.exec(body)) !== null) {
const level = match[1].length;
const level = parseInt(match[1]); // Теперь 2 или 3
const text = match[2].trim();
tocItems.push({ level, id: `heading-${headingIndex++}`, text });
}
console.log('[DEBUG] tocItems:', JSON.stringify(tocItems));
const formatDate = (date: string) => {
const d = new Date(date);
const day = d.getDate().toString().padStart(2, '0');
@ -90,7 +89,7 @@ const heroImage = getPostImageUrl(post);
<RelatedPosts posts={filteredRelated} currentSlug={slug} />
*/}
<!-- Оглавление - пробуем без slot -->
<!-- Оглавление -->
<div slot="sidebar">
<ArticleTableOfContents items={tocItems} />
</div>