mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 15:22:52 +01:00
fix: unable to list uncategorized posts on the archive page (fix #471)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { getCollection } from "astro:content";
|
||||
import I18nKey from "@i18n/i18nKey";
|
||||
import { i18n } from "@i18n/translation";
|
||||
import { getCategoryUrl } from "@utils/url-utils.ts";
|
||||
|
||||
export async function getSortedPosts() {
|
||||
const allBlogPosts = await getCollection("posts", ({ data }) => {
|
||||
@@ -54,6 +55,7 @@ export async function getTagList(): Promise<Tag[]> {
|
||||
export type Category = {
|
||||
name: string;
|
||||
count: number;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export async function getCategoryList(): Promise<Category[]> {
|
||||
@@ -61,7 +63,7 @@ export async function getCategoryList(): Promise<Category[]> {
|
||||
return import.meta.env.PROD ? data.draft !== true : true;
|
||||
});
|
||||
const count: { [key: string]: number } = {};
|
||||
allBlogPosts.map((post: { data: { category: string | number } }) => {
|
||||
allBlogPosts.map((post: { data: { category: string | null } }) => {
|
||||
if (!post.data.category) {
|
||||
const ucKey = i18n(I18nKey.uncategorized);
|
||||
count[ucKey] = count[ucKey] ? count[ucKey] + 1 : 1;
|
||||
@@ -82,7 +84,11 @@ export async function getCategoryList(): Promise<Category[]> {
|
||||
|
||||
const ret: Category[] = [];
|
||||
for (const c of lst) {
|
||||
ret.push({ name: c, count: count[c] });
|
||||
ret.push({
|
||||
name: c,
|
||||
count: count[c],
|
||||
url: getCategoryUrl(c),
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export function getCategoryUrl(category: string): string {
|
||||
category.trim() === "" ||
|
||||
category.trim().toLowerCase() === i18n(I18nKey.uncategorized).toLowerCase()
|
||||
)
|
||||
return url("/archive/");
|
||||
return url("/archive/?uncategorized=true");
|
||||
return url(`/archive/?category=${encodeURIComponent(category.trim())}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user