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;
|
||||
}
|
||||
|
||||
export function encodePathSegment(value: string): string {
|
||||
return encodeURIComponent(value);
|
||||
}
|
||||
|
||||
@@ -51,13 +51,25 @@ export function buildSitemapXml(entries: SitemapUrlEntry[]): string {
|
||||
].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(
|
||||
template: string,
|
||||
vars: { id?: string; slug: string },
|
||||
): string {
|
||||
return template
|
||||
.replaceAll('{id}', vars.id != null ? encodeURIComponent(vars.id) : '')
|
||||
.replaceAll('{slug}', encodeURIComponent(vars.slug));
|
||||
.replaceAll('{id}', sanitizePathSegment(vars.id ?? ''))
|
||||
.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 {
|
||||
|
||||
Reference in New Issue
Block a user