diff --git a/apps/web/src/artifacts/html-links.ts b/apps/web/src/artifacts/html-links.ts
index 0eff1691d..0ea693097 100644
--- a/apps/web/src/artifacts/html-links.ts
+++ b/apps/web/src/artifacts/html-links.ts
@@ -81,12 +81,21 @@ function buildLatestHtmlFileIndex(projectFiles: readonly HtmlLinkProjectFile[]):
if (!isHtmlProjectFile(file)) continue;
const key = htmlFileFamilyKey(file.name);
if (!key) continue;
+ if (!htmlFileManifestMatchesFamily(file, key)) continue;
const current = latest.get(key);
if (!current || file.mtime > current.mtime) latest.set(key, file);
}
return new Map(Array.from(latest, ([key, file]) => [key, file.name]));
}
+function htmlFileManifestMatchesFamily(file: HtmlLinkProjectFile, familyKey: string): boolean {
+ const identifier = file.artifactManifest?.metadata?.identifier;
+ if (typeof identifier !== 'string') return false;
+ const normalizedIdentifier = normalizeArtifactIdentifier(identifier);
+ if (!normalizedIdentifier) return false;
+ return normalizedIdentifier === htmlFileFamilyIdentifier(familyKey);
+}
+
function isHtmlProjectFile(file: HtmlLinkProjectFile): boolean {
const name = file.name.toLowerCase();
return (
@@ -151,6 +160,21 @@ function htmlFileFamilyKey(pathname: string): string | null {
return `${directory}${familyStem}${ext}`.replace(/^\.\//, '');
}
+function htmlFileFamilyIdentifier(familyKey: string): string {
+ const slash = familyKey.lastIndexOf('/');
+ const fileName = slash >= 0 ? familyKey.slice(slash + 1) : familyKey;
+ const dot = fileName.lastIndexOf('.');
+ const stem = dot > 0 ? fileName.slice(0, dot) : fileName;
+ return normalizeArtifactIdentifier(stem);
+}
+
+function normalizeArtifactIdentifier(value: string): string {
+ return value
+ .toLowerCase()
+ .replace(/[^a-z0-9_-]+/g, '-')
+ .replace(/^-+|-+$/g, '');
+}
+
function preserveRelativePrefix(originalPathname: string, latestName: string): string {
if (originalPathname.startsWith('./') && !latestName.startsWith('./')) {
return `./${latestName}`;
diff --git a/apps/web/tests/artifacts/html-links.test.ts b/apps/web/tests/artifacts/html-links.test.ts
index 9b6214516..c7ac2cf32 100644
--- a/apps/web/tests/artifacts/html-links.test.ts
+++ b/apps/web/tests/artifacts/html-links.test.ts
@@ -89,10 +89,10 @@ describe('rewriteHtmlLinksToCurrentProjectFiles', () => {
'