2026-04-09 22:22:55 +05:00
|
|
|
---
|
|
|
|
|
import ArticleLayout from '@layouts/ArticleLayout.astro';
|
|
|
|
|
import { SITE_URL } from '@constants';
|
|
|
|
|
import PostCommentForm from '@components/blog/PostCommentForm.astro';
|
|
|
|
|
import RelatedPosts from '@components/blog/RelatedPosts.astro';
|
2026-04-10 00:48:20 +05:00
|
|
|
import ArticleTableOfContents from '@components/blog/ArticleTableOfContents.astro';
|
2026-04-09 22:22:55 +05:00
|
|
|
import { getCollection, getEntry, render } from 'astro:content';
|
|
|
|
|
|
2026-04-14 23:17:38 +05:00
|
|
|
export const prerender = true;
|
2026-04-09 22:22:55 +05:00
|
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
|
const posts = await getCollection('blog') as { id: string; data: Record<string, any> }[];
|
|
|
|
|
return posts.map((post: { id: string }) => ({
|
|
|
|
|
params: { slug: post.id },
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const slug = Astro.params.slug;
|
|
|
|
|
|
|
|
|
|
if (!slug) {
|
|
|
|
|
return Astro.redirect('/blog');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const post = await getEntry('blog', slug);
|
|
|
|
|
|
|
|
|
|
if (!post) {
|
|
|
|
|
return Astro.redirect('/blog');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { Content } = await render(post);
|
|
|
|
|
|
2026-04-10 00:48:20 +05:00
|
|
|
// Извлекаем заголовки из MDX тела для оглавления
|
|
|
|
|
const body = post.body || '';
|
|
|
|
|
const headingRegex = /^(#{2,3})\s+(.+)$/gm;
|
|
|
|
|
const tocItems: { id: string; text: string; level: number }[] = [];
|
|
|
|
|
let match;
|
|
|
|
|
let headingIndex = 0;
|
|
|
|
|
while ((match = headingRegex.exec(body)) !== null) {
|
|
|
|
|
const level = match[1].length;
|
|
|
|
|
const text = match[2].trim();
|
|
|
|
|
// Генерируем ID из текста заголовка
|
|
|
|
|
const id = text.toLowerCase()
|
|
|
|
|
.replace(/[^\w\s-]/g, '')
|
|
|
|
|
.replace(/\s+/g, '-');
|
|
|
|
|
tocItems.push({ level, id: `heading-${headingIndex++}`, text });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('=== TOC ITEMS ===', tocItems);
|
|
|
|
|
|
2026-04-09 22:22:55 +05:00
|
|
|
// Форматируем дату
|
|
|
|
|
const formatDate = (date: Date) => {
|
|
|
|
|
return date.toLocaleDateString('ru-RU', {
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
month: 'long',
|
|
|
|
|
year: 'numeric'
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Логика авторизации (пока статичная переменная)
|
|
|
|
|
const isAuthorized = false;
|
|
|
|
|
|
|
|
|
|
// URL текущей страницы
|
|
|
|
|
const currentUrl = `${SITE_URL}/blog/${post.id}`;
|
|
|
|
|
|
|
|
|
|
// Получаем все посты для блока "Читайте также"
|
|
|
|
|
const allPosts = await getCollection('blog');
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<ArticleLayout
|
|
|
|
|
title={`${post.data.title} — автоюрист в Сургуте`}
|
|
|
|
|
description={post.data.description}
|
|
|
|
|
canonicalLink={`${SITE_URL}/blog/${post.id}`}
|
|
|
|
|
breadcrumbs={[
|
|
|
|
|
{ label: 'Главная', href: '/' },
|
|
|
|
|
{ label: 'Блог', href: '/blog' },
|
|
|
|
|
{ label: post.data.title }
|
|
|
|
|
]}
|
|
|
|
|
heroImage={post.data.imageUrl}
|
|
|
|
|
heroAlt={post.data.title}
|
|
|
|
|
category={post.data.category}
|
|
|
|
|
postTitle={post.data.title}
|
|
|
|
|
date={formatDate(post.data.date)}
|
|
|
|
|
author={post.data.author}
|
|
|
|
|
readTime={post.data.readTime}
|
|
|
|
|
postId={post.id}
|
|
|
|
|
postUrl={currentUrl}
|
|
|
|
|
initialLikes={12}
|
|
|
|
|
initialDislikes={2}
|
|
|
|
|
>
|
|
|
|
|
<!-- Содержимое статьи -->
|
|
|
|
|
<div class="post-content">
|
|
|
|
|
<Content />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Форма комментариев -->
|
2026-04-10 00:48:20 +05:00
|
|
|
<PostCommentForm
|
2026-04-09 22:22:55 +05:00
|
|
|
postId={post.id}
|
|
|
|
|
isAuthorized={isAuthorized}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<!-- Похожие статьи -->
|
|
|
|
|
<RelatedPosts
|
|
|
|
|
posts={allPosts}
|
|
|
|
|
currentSlug={post.id}
|
|
|
|
|
/>
|
2026-04-10 00:48:20 +05:00
|
|
|
|
|
|
|
|
<!-- Оглавление в сайдбаре -->
|
|
|
|
|
<ArticleTableOfContents items={tocItems} slot="sidebar" />
|
2026-04-09 22:22:55 +05:00
|
|
|
</ArticleLayout>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
/* Post Content */
|
|
|
|
|
.post-content {
|
2026-04-10 00:48:20 +05:00
|
|
|
padding: 0;
|
2026-04-09 22:22:55 +05:00
|
|
|
color: #334155;
|
|
|
|
|
line-height: 1.8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(h2) {
|
|
|
|
|
color: #1e293b;
|
|
|
|
|
font-size: 1.75rem;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
margin: 2rem 0 1rem;
|
|
|
|
|
letter-spacing: -0.02em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(h3) {
|
|
|
|
|
color: #1e293b;
|
|
|
|
|
font-size: 1.375rem;
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
margin: 1.75rem 0 1rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(p) {
|
|
|
|
|
margin: 0 0 1.25rem;
|
|
|
|
|
font-size: 1.05rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(ul), .post-content :global(ol) {
|
|
|
|
|
margin: 1rem 0;
|
|
|
|
|
padding-left: 1.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(li) {
|
|
|
|
|
margin: 0.5rem 0;
|
|
|
|
|
font-size: 1.05rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(blockquote) {
|
|
|
|
|
margin: 2rem 0;
|
|
|
|
|
padding: 1.5rem 2rem;
|
|
|
|
|
background: #f8fafc;
|
|
|
|
|
border-left: 4px solid #d4af37;
|
|
|
|
|
border-radius: 0 0.75rem 0.75rem 0;
|
|
|
|
|
font-style: italic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
.post-content {
|
2026-04-10 00:48:20 +05:00
|
|
|
padding: 2rem 0;
|
2026-04-09 22:22:55 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(h2) {
|
|
|
|
|
font-size: 1.5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.post-content :global(h3) {
|
|
|
|
|
font-size: 1.25rem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|