feat: untagged archive

This commit is contained in:
HPCesia 2025-01-22 23:28:12 +08:00
parent 593566ad72
commit 1564426c1d
5 changed files with 17 additions and 10 deletions

View File

@ -14,7 +14,7 @@ enum I18nKey {
untitled = 'untitled',
uncategorized = 'uncategorized',
noTags = 'noTags',
untagged = 'untagged',
wordCount = 'wordCount',
wordsCount = 'wordsCount',

View File

@ -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',

View File

@ -17,7 +17,7 @@ export const zh_CN: Translation = {
[Key.untitled]: '无标题',
[Key.uncategorized]: '未分类',
[Key.noTags]: '无标签',
[Key.untagged]: '无标签',
[Key.wordCount]: '字',
[Key.wordsCount]: '字',

View File

@ -17,7 +17,7 @@ export const zh_TW: Translation = {
[Key.untitled]: '無標題',
[Key.uncategorized]: '未分類',
[Key.noTags]: '無標籤',
[Key.untagged]: '無標籤',
[Key.wordCount]: '字',
[Key.wordsCount]: '字',

View File

@ -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();