Add page indexes to conversation manifests
This commit is contained in:
@@ -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'),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user