fix: improve category URL handling with additional checks (#472)
* fix: improve category URL handling with additional checks * Update src/utils/url-utils.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
87eff4a087
commit
4b30ff2b7b
1 changed files with 9 additions and 1 deletions
|
|
@ -1,3 +1,6 @@
|
||||||
|
import I18nKey from "@i18n/i18nKey";
|
||||||
|
import { i18n } from "@i18n/translation";
|
||||||
|
|
||||||
export function pathsEqual(path1: string, path2: string) {
|
export function pathsEqual(path1: string, path2: string) {
|
||||||
const normalizedPath1 = path1.replace(/^\/|\/$/g, "").toLowerCase();
|
const normalizedPath1 = path1.replace(/^\/|\/$/g, "").toLowerCase();
|
||||||
const normalizedPath2 = path2.replace(/^\/|\/$/g, "").toLowerCase();
|
const normalizedPath2 = path2.replace(/^\/|\/$/g, "").toLowerCase();
|
||||||
|
|
@ -19,7 +22,12 @@ export function getTagUrl(tag: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCategoryUrl(category: string): string {
|
export function getCategoryUrl(category: string): string {
|
||||||
if (!category) return url("/archive/");
|
if (
|
||||||
|
!category ||
|
||||||
|
category.trim() === "" ||
|
||||||
|
category.trim().toLowerCase() === i18n(I18nKey.uncategorized).toLowerCase()
|
||||||
|
)
|
||||||
|
return url("/archive/");
|
||||||
return url(`/archive/?category=${encodeURIComponent(category.trim())}`);
|
return url(`/archive/?category=${encodeURIComponent(category.trim())}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue