feat: улучшения блога - убрана нумерация с H3 подзаголовков, эмодзи в статьях без дублирования в оглавлении
This commit is contained in:
parent
0f7a83c9e9
commit
9ad9fe4927
5 changed files with 667 additions and 8 deletions
|
|
@ -63,9 +63,10 @@ const { items } = Astro.props;
|
|||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
/* Поддержка level=1 (из HTML h2) и level=2/3 */
|
||||
/* Номера только для H2 (level-1/2), H3 без номеров */
|
||||
.toc-item.level-1, .toc-item.level-2 { counter-reset: toc-h3; counter-increment: toc-h2; }
|
||||
.toc-item.level-3 { counter-increment: toc-h3; padding-left: 1.25rem; }
|
||||
.toc-item.level-3 { padding-left: 1.25rem; counter-increment: toc-h3; }
|
||||
.toc-item.level-3 .toc-link::before { content: none; }
|
||||
|
||||
/* h2 = level 1 в HTML */
|
||||
.toc-item.level-1, .toc-item.level-2 {
|
||||
|
|
@ -98,7 +99,7 @@ const { items } = Astro.props;
|
|||
text-align: center;
|
||||
}
|
||||
.toc-item.level-1 .toc-link::before, .toc-item.level-2 .toc-link::before { content: counter(toc-h2) "."; }
|
||||
.toc-item.level-3 .toc-link::before { content: counter(toc-h2) "." counter(toc-h3) "."; font-size: 0.85em; opacity: 0.7; }
|
||||
/* H3 без номеров */
|
||||
|
||||
.toc-link:hover { color: #1e3050; background: #f1f5f9; }
|
||||
|
||||
|
|
|
|||
|
|
@ -70,15 +70,16 @@ const views = await getPostViews(post.id).catch(() => 0);
|
|||
// Конвертируем markdown в HTML
|
||||
const contentHtml = marked(post.content || '');
|
||||
|
||||
// Извлекаем заголовки для оглавления (поддержка HTML и Markdown)
|
||||
const headingRegex = /<h([2-3])[^>]*>([^<]+)<\/?h[2-3]>/gi;
|
||||
// Извлекаем ТОЛЬКО h2 заголовки для оглавления
|
||||
const headingRegex = /<h2[^>]*>([^<]+)<\/?h2>/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 = parseInt(match[1]); // Теперь 2 или 3
|
||||
const text = match[2].trim();
|
||||
const level = 2; // Только h2
|
||||
// Убираем эмодзи из текста для оглавления
|
||||
const text = match[1].replace(/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F1E0}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/gu, '').trim();
|
||||
tocItems.push({ level, id: `heading-${headingIndex++}`, text });
|
||||
}
|
||||
const formatDate = (date: string) => {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ html, body {
|
|||
.post-content { counter-reset: post-h2; }
|
||||
.post-content h2 { counter-reset: post-h3; }
|
||||
.post-content h2::before { counter-increment: post-h2; content: counter(post-h2) "."; margin-right: 0.5rem; color: #1e3050; font-weight: 700; }
|
||||
.post-content h3::before { counter-increment: post-h3; content: counter(post-h2) "." counter(post-h3) "."; margin-right: 0.4rem; color: #1e3050; font-weight: 600; font-size: 0.9em; }
|
||||
/* H3 без нумерации */
|
||||
.post-content h3::before { content: none; }
|
||||
|
||||
/* ТАБЛИЦЫ В ПОСТАХ */
|
||||
.post-content table {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue