mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 07:12:52 +01:00
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
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user