Насторил работу блога через Backend

This commit is contained in:
Web-serfer 2026-04-15 02:12:25 +05:00
parent 014439d565
commit edd730b438
33 changed files with 1019 additions and 200 deletions

View file

@ -1,29 +1,28 @@
---
import BlogCard from '@components/blog/BlogCard.astro';
interface CollectionEntry {
interface Post {
id: string;
data: {
title: string;
description: string;
category: string;
categoryColor: string;
date: Date;
readTime: string;
imageUrl: string;
};
slug: string;
title: string;
description: string;
category: string;
categoryColor: string;
date: string;
readTime: string;
imageUrl: string;
}
interface Props {
posts: CollectionEntry[];
posts: Post[];
currentSlug?: string;
}
const { posts, currentSlug } = Astro.props;
// Форматируем дату
const formatDate = (date: Date) => {
return date.toLocaleDateString('ru-RU', {
const formatDate = (date: string) => {
return new Date(date).toLocaleDateString('ru-RU', {
day: 'numeric',
month: 'long',
year: 'numeric'
@ -32,7 +31,7 @@ const formatDate = (date: Date) => {
// Фильтруем текущую статью
const filteredPosts = currentSlug
? posts.filter(post => post.id !== currentSlug).slice(0, 3)
? posts.filter(post => post.slug !== currentSlug).slice(0, 3)
: posts.slice(0, 3);
---
@ -42,14 +41,14 @@ const filteredPosts = currentSlug
<div class="related-grid">
{filteredPosts.map((post) => (
<BlogCard
title={post.data.title}
description={post.data.description}
category={post.data.category}
categoryColor={post.data.categoryColor}
date={formatDate(post.data.date)}
readTime={post.data.readTime}
imageUrl={post.data.imageUrl}
slug={`/blog/${post.id}`}
title={post.title}
description={post.description}
category={post.category}
categoryColor={post.categoryColor}
date={formatDate(post.date)}
readTime={post.readTime}
imageUrl={post.imageUrl}
slug={`/blog/${post.slug}`}
/>
))}
</div>