2026-04-09 22:22:55 +05:00
|
|
|
---
|
|
|
|
|
import ArticleLayout from '@layouts/ArticleLayout.astro';
|
|
|
|
|
import { SITE_URL } from '@constants';
|
2026-04-18 18:25:10 +05:00
|
|
|
import Comments from '@components/blog/comments/Comments';
|
2026-04-09 22:22:55 +05:00
|
|
|
import RelatedPosts from '@components/blog/RelatedPosts.astro';
|
2026-04-10 00:48:20 +05:00
|
|
|
import ArticleTableOfContents from '@components/blog/ArticleTableOfContents.astro';
|
2026-04-17 17:35:17 +05:00
|
|
|
import { getPostBySlug, getPosts, getPostImageUrl, getPostVotesStats } from '@lib/pb';
|
2026-04-15 02:12:25 +05:00
|
|
|
import { marked } from 'marked';
|
2026-04-09 22:22:55 +05:00
|
|
|
|
2026-04-15 02:12:25 +05:00
|
|
|
export const prerender = false;
|
2026-04-09 22:22:55 +05:00
|
|
|
|
|
|
|
|
const slug = Astro.params.slug;
|
|
|
|
|
|
|
|
|
|
if (!slug) {
|
|
|
|
|
return Astro.redirect('/blog');
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 02:12:25 +05:00
|
|
|
const post = await getPostBySlug(slug);
|
2026-04-09 22:22:55 +05:00
|
|
|
|
|
|
|
|
if (!post) {
|
|
|
|
|
return Astro.redirect('/blog');
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-17 17:35:17 +05:00
|
|
|
const { likes = 0, dislikes = 0 } = await getPostVotesStats(post.id).catch(() => ({ likes: 0, dislikes: 0 }));
|
|
|
|
|
|
2026-04-15 02:12:25 +05:00
|
|
|
// Конвертируем markdown в HTML
|
|
|
|
|
const contentHtml = marked(post.content || '');
|
2026-04-09 22:22:55 +05:00
|
|
|
|
2026-04-15 02:12:25 +05:00
|
|
|
// Извлекаем заголовки для оглавления
|
2026-04-10 00:48:20 +05:00
|
|
|
const headingRegex = /^(#{2,3})\s+(.+)$/gm;
|
|
|
|
|
const tocItems: { id: string; text: string; level: number }[] = [];
|
2026-04-15 02:12:25 +05:00
|
|
|
const body = post.content || '';
|
2026-04-10 00:48:20 +05:00
|
|
|
let match;
|
|
|
|
|
let headingIndex = 0;
|
|
|
|
|
while ((match = headingRegex.exec(body)) !== null) {
|
|
|
|
|
const level = match[1].length;
|
|
|
|
|
const text = match[2].trim();
|
|
|
|
|
tocItems.push({ level, id: `heading-${headingIndex++}`, text });
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 22:22:55 +05:00
|
|
|
// Форматируем дату
|
2026-04-15 02:12:25 +05:00
|
|
|
const formatDate = (date: string) => {
|
|
|
|
|
return new Date(date).toLocaleDateString('ru-RU', {
|
2026-04-09 22:22:55 +05:00
|
|
|
day: 'numeric',
|
|
|
|
|
month: 'long',
|
|
|
|
|
year: 'numeric'
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-15 02:12:25 +05:00
|
|
|
// Для related posts берем те же категории
|
|
|
|
|
const { posts: relatedPosts } = await getPosts({ perPage: 4, category: post.category });
|
|
|
|
|
const filteredRelated = relatedPosts.filter(p => p.slug !== slug).slice(0, 3);
|
2026-04-09 22:22:55 +05:00
|
|
|
|
2026-04-15 02:12:25 +05:00
|
|
|
const currentUrl = `${SITE_URL}/blog/${slug}`;
|
2026-04-15 12:36:58 +05:00
|
|
|
const heroImage = getPostImageUrl(post);
|
2026-04-09 22:22:55 +05:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<ArticleLayout
|
2026-04-15 02:12:25 +05:00
|
|
|
title={`${post.title} — автоюрист в Сургуте`}
|
|
|
|
|
description={post.description}
|
|
|
|
|
canonicalLink={`${SITE_URL}/blog/${slug}`}
|
2026-04-09 22:22:55 +05:00
|
|
|
breadcrumbs={[
|
|
|
|
|
{ label: 'Главная', href: '/' },
|
|
|
|
|
{ label: 'Блог', href: '/blog' },
|
2026-04-15 02:12:25 +05:00
|
|
|
{ label: post.title }
|
2026-04-09 22:22:55 +05:00
|
|
|
]}
|
2026-04-15 12:36:58 +05:00
|
|
|
heroImage={heroImage}
|
2026-04-15 02:12:25 +05:00
|
|
|
heroAlt={post.title}
|
|
|
|
|
category={post.category}
|
|
|
|
|
postTitle={post.title}
|
|
|
|
|
date={formatDate(post.date)}
|
|
|
|
|
author={post.author}
|
|
|
|
|
readTime={post.readTime}
|
2026-04-18 18:25:10 +05:00
|
|
|
readmeTime={post.readmeTime}
|
2026-04-09 22:22:55 +05:00
|
|
|
postId={post.id}
|
|
|
|
|
postUrl={currentUrl}
|
2026-04-17 17:35:17 +05:00
|
|
|
initialLikes={likes}
|
|
|
|
|
initialDislikes={dislikes}
|
2026-04-09 22:22:55 +05:00
|
|
|
>
|
|
|
|
|
<!-- Содержимое статьи -->
|
2026-04-15 02:12:25 +05:00
|
|
|
<div class="post-content" set:html={contentHtml} />
|
2026-04-09 22:22:55 +05:00
|
|
|
|
2026-04-18 18:25:10 +05:00
|
|
|
<!-- Система комментариев -->
|
|
|
|
|
<div class="comments-wrapper">
|
|
|
|
|
<Comments client:only="solid-js" postSlug={post.slug} />
|
|
|
|
|
</div>
|
2026-04-09 22:22:55 +05:00
|
|
|
|
|
|
|
|
<!-- Похожие статьи -->
|
|
|
|
|
<RelatedPosts
|
2026-04-15 02:12:25 +05:00
|
|
|
posts={filteredRelated}
|
|
|
|
|
currentSlug={slug}
|
2026-04-09 22:22:55 +05:00
|
|
|
/>
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-15 02:12:25 +05:00
|
|
|
</style>
|