Commit 1564426

HPCesia <me@hpcesia.com>
2025-01-22 15:28:12
feat: untagged archive
1 parent 593566a
Changed files (5)
src
src/i18n/langs/en.ts
@@ -17,7 +17,7 @@ export const en: Translation = {
 
   [Key.untitled]: 'Untitled',
   [Key.uncategorized]: 'Uncategorized',
-  [Key.noTags]: 'No Tags',
+  [Key.untagged]: 'No Tags',
 
   [Key.wordCount]: 'word',
   [Key.wordsCount]: 'words',
src/i18n/langs/zh_CN.ts
@@ -17,7 +17,7 @@ export const zh_CN: Translation = {
 
   [Key.untitled]: '无标题',
   [Key.uncategorized]: '未分类',
-  [Key.noTags]: '无标签',
+  [Key.untagged]: '无标签',
 
   [Key.wordCount]: '字',
   [Key.wordsCount]: '字',
src/i18n/langs/zh_TW.ts
@@ -17,7 +17,7 @@ export const zh_TW: Translation = {
 
   [Key.untitled]: '無標題',
   [Key.uncategorized]: '未分類',
-  [Key.noTags]: '無標籤',
+  [Key.untagged]: '無標籤',
 
   [Key.wordCount]: '字',
   [Key.wordsCount]: '字',
src/i18n/i18nKey.ts
@@ -14,7 +14,7 @@ enum I18nKey {
 
   untitled = 'untitled',
   uncategorized = 'uncategorized',
-  noTags = 'noTags',
+  untagged = 'untagged',
 
   wordCount = 'wordCount',
   wordsCount = 'wordsCount',
src/pages/archives/tags/[tag]/[page].astro
@@ -4,21 +4,28 @@ import PostPage from '@components/PostPage.astro';
 import { siteConfig } from '@/config';
 import GridLayout from '@layouts/GridLayout.astro';
 import ProfileCard from '@components/widgets/ProfileCard.astro';
+import I18nKey from '@i18n/I18nKey';
 
 export async function getStaticPaths() {
   const posts = await getSortedPosts();
-  const tags = [...new Set(posts.map((post) => post.data.tags).flat())];
+  const tags = [
+    ...new Set(
+      posts
+        .map((post) => (post.data.tags.length > 0 ? post.data.tags : [I18nKey.untagged]))
+        .flat()
+    ),
+  ];
   return tags
     .map((tag) => {
-      const tagPosts = posts.filter((post) => post.data.tags.includes(tag));
+      const tagPosts =
+        tag === I18nKey.untagged
+          ? posts.filter((post) => post.data.tags.length === 0)
+          : posts.filter((post) => post.data.tags.includes(tag));
       const pageNum = Math.ceil(tagPosts.length / siteConfig.postsPerPage);
       tag = tag.replaceAll(/[\\/]/g, '-');
       return Array.from({ length: pageNum }, (_, i) => ({
         params: { tag: tag, page: (i + 1).toString() },
-        props: {
-          posts: tagPosts.slice(i * siteConfig.postsPerPage, (i + 1) * siteConfig.postsPerPage),
-          currentPage: i + 1,
-        },
+        props: { posts: tagPosts, currentPage: i + 1 },
       }));
     })
     .flat();