feat: make archive page dynamic (#469)
Some checks failed
Code quality / quality (push) Failing after 4s
Build and Check / Astro Check for Node.js 22 (push) Failing after 4s
Build and Check / Astro Check for Node.js 23 (push) Failing after 4s
Build and Check / Astro Build for Node.js 22 (push) Failing after 4s
Build and Check / Astro Build for Node.js 23 (push) Failing after 3s

This commit is contained in:
saica.go
2025-05-30 00:21:07 +08:00
committed by GitHub
parent c5d95736ac
commit 2d89e4d53f
12 changed files with 172 additions and 201 deletions

View File

@@ -1,32 +0,0 @@
/**
* Utility functions for ensuring consistent URL encoding
*/
/**
* Ensure consistent URL encoding across all tags and categories
*
* @param value The string to encode
* @returns The encoded string
*/
export function encodePathSegment(value: string): string {
if (!value) return "";
return encodeURIComponent(value.trim());
}
/**
* Decode from the URL path
*
* @param value String to decode
* @returns Decoded string
*/
export function decodePathSegment(value: string): string {
if (!value) return "";
try {
return decodeURIComponent(value);
} catch (e) {
console.error(`Failed to decode path segment: ${value}`, e);
return value;
}
}

View File

@@ -1,7 +1,3 @@
import i18nKey from "@i18n/i18nKey";
import { i18n } from "@i18n/translation";
import { encodePathSegment } from "./encoding-utils";
export function pathsEqual(path1: string, path2: string) {
const normalizedPath1 = path1.replace(/^\/|\/$/g, "").toLowerCase();
const normalizedPath2 = path2.replace(/^\/|\/$/g, "").toLowerCase();
@@ -18,26 +14,13 @@ export function getPostUrlBySlug(slug: string): string {
}
export function getTagUrl(tag: string): string {
if (!tag) return url("/archive/tag/");
// use common encoding function
const encodedTag = encodePathSegment(tag);
const tagUrl = `/archive/tag/${encodedTag}/`;
console.log(`Generating URL for tag "${tag.trim()}" => "${tagUrl}"`);
return url(tagUrl);
if (!tag) return url("/archive/");
return url(`/archive/?tag=${encodeURIComponent(tag.trim())}`);
}
export function getCategoryUrl(category: string): string {
console.log(`category: ${category}`);
if (!category) return url("/archive/category/");
const trimmedCategory = category.trim();
if (trimmedCategory === i18n(i18nKey.uncategorized))
return url("/archive/category/uncategorized/");
return url(
`/archive/category/${encodeURIComponent(trimmedCategory).replace(/%20/g, "+")}/`,
);
if (!category) return url("/archive/");
return url(`/archive/?category=${encodeURIComponent(category.trim())}`);
}
export function getDir(path: string): string {