fix: unable to list uncategorized posts on the archive page (fix #471)

This commit is contained in:
saicaca committed 2025-05-30 19:42:45 +08:00
1 parent 4b30ff2b7b
commit dde7835dd7
7 files changed
+17 -130

No files matched your search

+6 -4
View File
@@ -1,7 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import { UNCATEGORIZED } from "@constants/constants";
import I18nKey from "../i18n/i18nKey";
import { i18n } from "../i18n/translation";
import { getPostUrlBySlug } from "../utils/url-utils";
@@ -13,6 +12,7 @@ export let sortedPosts: Post[] = [];
const params = new URLSearchParams(window.location.search);
tags = params.has("tag") ? params.getAll("tag") : [];
categories = params.has("category") ? params.getAll("category") : [];
const uncategorized = params.get("uncategorized");
interface Post {
slug: string;
@@ -54,12 +54,14 @@ onMount(async () => {
if (categories.length > 0) {
filteredPosts = filteredPosts.filter(
(post) =>
(post.data.category && categories.includes(post.data.category)) ||
(!post.data.category && categories.includes(UNCATEGORIZED)),
(post) => post.data.category && categories.includes(post.data.category),
);
}
if (uncategorized) {
filteredPosts = filteredPosts.filter((post) => !post.data.category);
}
const grouped = filteredPosts.reduce(
(acc, post) => {
const year = post.data.published.getFullYear();