fix: url canonicalization now part of rendering, not preview server

This commit is contained in:
2026-02-22 08:06:45 +01:00
parent 8f983b5999
commit b437d79230
4 changed files with 108 additions and 71 deletions

View File

@@ -597,6 +597,18 @@ export function normalizePreviewHref(rawHref: string, rewriteContext: HtmlRewrit
return `${canonical ?? `/posts/${slug}`}${suffix}`;
}
const mediaMatch = pathPart.match(/^\/?media\/(\d{4})\/(\d{2})\/([^\s]+)$/i);
if (mediaMatch) {
const [, year, month, filename] = mediaMatch;
const sourceKey = `media/${year}/${month}/${filename}`.toLowerCase();
const canonicalPath = rewriteContext.canonicalMediaPathBySourcePath.get(sourceKey);
if (canonicalPath) {
return `${canonicalPath}${suffix}`;
}
return `/media/${year}/${month}/${filename}${suffix}`;
}
return rawHref;
}