Keep Farsi characters readable in sitemap loc URLs.
Stop percent-encoding path slugs so <loc> shows UTF-8 Persian text while still sanitizing unsafe URL characters. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
7cef24336a
commit
df17925d3a
@@ -16,7 +16,3 @@ export function slugifyForUrl(value: string, fallback = 'item'): string {
|
|||||||
|
|
||||||
return slug || fallback;
|
return slug || fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function encodePathSegment(value: string): string {
|
|
||||||
return encodeURIComponent(value);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -51,13 +51,25 @@ export function buildSitemapXml(entries: SitemapUrlEntry[]): string {
|
|||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a path from a template. Keep Unicode (e.g. Farsi) readable in sitemap
|
||||||
|
* `<loc>` — do not percent-encode letters. XML escaping happens in buildSitemapXml.
|
||||||
|
* Only encode characters that break URL/path parsing.
|
||||||
|
*/
|
||||||
export function applyPathTemplate(
|
export function applyPathTemplate(
|
||||||
template: string,
|
template: string,
|
||||||
vars: { id?: string; slug: string },
|
vars: { id?: string; slug: string },
|
||||||
): string {
|
): string {
|
||||||
return template
|
return template
|
||||||
.replaceAll('{id}', vars.id != null ? encodeURIComponent(vars.id) : '')
|
.replaceAll('{id}', sanitizePathSegment(vars.id ?? ''))
|
||||||
.replaceAll('{slug}', encodeURIComponent(vars.slug));
|
.replaceAll('{slug}', sanitizePathSegment(vars.slug));
|
||||||
|
}
|
||||||
|
|
||||||
|
function sanitizePathSegment(value: string): string {
|
||||||
|
return value
|
||||||
|
.replace(/\\/g, '')
|
||||||
|
.replace(/[/?#]/g, '')
|
||||||
|
.replace(/\s+/g, '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildAbsoluteUrl(baseUrl: string, path: string): string {
|
export function buildAbsoluteUrl(baseUrl: string, path: string): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user