-
-
+
- {post.date && (
-
- )}
-
-
-
-
+ {post.date && (
+
+ )}
+
+
+
+ diff --git a/src/components/Header/Header.astro b/src/components/Header/Header.astro index 0d8e9fa..5b9ddc3 100644 --- a/src/components/Header/Header.astro +++ b/src/components/Header/Header.astro @@ -15,8 +15,8 @@
) : (У автора пока нет статей
+)} \ No newline at end of file diff --git a/src/pages/load-more-posts.astro b/src/pages/load-more-posts.astro index 590af5d..819a81d 100644 --- a/src/pages/load-more-posts.astro +++ b/src/pages/load-more-posts.astro @@ -26,7 +26,7 @@ console.log('📥 Load more request:', { perLoad, after, type, slug, startIndex // Импортируем функции для получения данных -const { getLatestPosts, getPostsByCategory, getAuthorPosts, getTagPosts } = +const { getLatestPosts, getPostsByCategory, getAuthorPosts, getPostsByTag } = await import('../lib/api/posts'); let result; @@ -43,7 +43,7 @@ switch (type) { break; case 'tag': if (!slug) throw new Error('Slug required for tag'); - result = await getTagPosts(slug, perLoad, after); // Используем perLoad + result = await getPostsByTag(slug, perLoad, after); // Используем perLoad break; case 'latest': default: diff --git a/src/pages/tag/[slug]/[page].astro b/src/pages/tag/[slug]/[page].astro new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/tag/[slug]/___index.astro b/src/pages/tag/[slug]/___index.astro new file mode 100644 index 0000000..12349c3 --- /dev/null +++ b/src/pages/tag/[slug]/___index.astro @@ -0,0 +1,68 @@ +--- + +import { slugParse } from '@utils/slugParser'; + + +//api +import { getTag, getTagWithPostsById } from '@api/tags.js'; +import { getArchivePostsById } from '@/lib/api/archiveById'; + +import MainLayout from '@layouts/MainLayout.astro'; +import TagArchive from '@/templates/TagArchive.astro'; + +//ISR +export const prerender = false; + +const { slug } = Astro.params; + +// Используем функцию (правильное название) +const { slug: tagSlug, page: currentPage } = slugParse(slug); + +// Если slug пустой - 404 +if (!tagSlug) { + return Astro.redirect('/404'); +} + + +// Получаем данные тега +const tag = await getTag(tagSlug); + +if (!tag) { + return Astro.redirect('/404'); +} + + +// ---------------------------- +// fetch archive +// ---------------------------- + +const perPage = 35; + +const { posts, pageInfo } = await getArchivePostsById({ + type: 'tag', + id: tag.databaseId, + page: currentPage, + perPage, +}); + +// 404 если страница невалидна +if (!posts.length && currentPage > 1) { + return Astro.redirect('/404'); +} + +--- + +