Add page indexes to conversation manifests

This commit is contained in:
john
2026-07-02 22:03:59 +08:00
parent ab4dab6b38
commit b084f6d23c
3 changed files with 73 additions and 3 deletions
+23
View File
@@ -142,6 +142,27 @@ function artifactManifestEntry(artifact) {
};
}
function groupedManifestEntries(artifacts, keyField, idField) {
const groups = new Map();
for (const artifact of artifacts) {
const key = artifact[keyField];
if (!key) continue;
const existing = groups.get(key) ?? {
[idField]: key,
artifactIds: [],
createdAt: artifact.createdAt,
updatedAt: artifact.createdAt,
};
existing.artifactIds.push(artifact.id);
if (!existing.displayName && artifact.displayName) existing.displayName = artifact.displayName;
if (!existing.canonicalUrl && artifact.canonicalUrl) existing.canonicalUrl = artifact.canonicalUrl;
existing.createdAt = Math.min(existing.createdAt, artifact.createdAt);
existing.updatedAt = Math.max(existing.updatedAt, artifact.createdAt);
groups.set(key, existing);
}
return [...groups.values()].sort((a, b) => a.createdAt - b.createdAt || a[idField].localeCompare(b[idField]));
}
export function buildConversationPackageManifest({ packageRecord, artifacts = [] }) {
const record = createConversationPackageRecord(packageRecord);
const normalizedArtifacts = artifacts
@@ -161,6 +182,8 @@ export function buildConversationPackageManifest({ packageRecord, artifacts = []
createdAt: record.createdAt,
updatedAt: record.updatedAt,
artifacts: normalizedArtifacts.map(artifactManifestEntry),
pages: groupedManifestEntries(normalizedArtifacts, 'pageId', 'pageId'),
publications: groupedManifestEntries(normalizedArtifacts, 'publicationId', 'publicationId'),
};
}