dont append hash to every single url

This commit is contained in:
Percs 2025-04-27 18:43:33 -05:00
parent c2de733549
commit f329714037

View file

@ -47,14 +47,14 @@ export function rewriteUrl(url: string | URL, meta: URLMeta) {
const realUrl = tryCanParseURL(url, base); const realUrl = tryCanParseURL(url, base);
if (!realUrl) return url; if (!realUrl) return url;
const encodedHash = $scramjet.codec.encode(realUrl.hash.slice(1)); const encodedHash = $scramjet.codec.encode(realUrl.hash.slice(1));
const realHash = encodedHash ? "#" + encodedHash : "";
realUrl.hash = ""; realUrl.hash = "";
return ( return (
location.origin + location.origin +
$scramjet.config.prefix + $scramjet.config.prefix +
$scramjet.codec.encode(realUrl.href) + $scramjet.codec.encode(realUrl.href) +
"#" + realHash
encodedHash
); );
} }
} }
@ -80,10 +80,11 @@ export function unrewriteUrl(url: string | URL) {
const realUrl = tryCanParseURL(url); const realUrl = tryCanParseURL(url);
if (!realUrl) return url; if (!realUrl) return url;
const decodedHash = $scramjet.codec.decode(realUrl.hash.slice(1)); const decodedHash = $scramjet.codec.decode(realUrl.hash.slice(1));
const realHash = decodedHash ? "#" + decodedHash : "";
realUrl.hash = ""; realUrl.hash = "";
return $scramjet.codec.decode( return $scramjet.codec.decode(
realUrl.href.slice(prefixed.length) + "#" + decodedHash realUrl.href.slice(prefixed.length) + realHash
); );
} }
} }