@coveo/create-atomic
Version:
Coveo Atomic Generator
42 lines (41 loc) • 1.33 kB
JavaScript
export async function fetchPageManifest(client, pageId, type) {
const manifestGetters = [];
if (type !== 'legacy') {
manifestGetters.push(getNextGenManifest);
}
if (type !== 'next-gen') {
manifestGetters.push(getLegacyManifest);
}
for (const manifestGetter of manifestGetters) {
let manifest;
try {
manifest = await manifestGetter(client, pageId);
}
catch (_) {
continue;
}
return replaceResultsPlaceholder(manifest);
}
throw new Error('Could not fetch the page manifest');
}
function replaceResultsPlaceholder(manifestResponse) {
const resultManagerComponent = '<results-manager></results-manager>';
if (manifestResponse.results.placeholder) {
manifestResponse.markup = manifestResponse.markup.replace(manifestResponse.results.placeholder, resultManagerComponent);
}
return manifestResponse;
}
async function getLegacyManifest(client, pageId) {
return await client.searchInterfaces.manifest(pageId, {
pagePlaceholders: {
results: '--results--',
},
});
}
async function getNextGenManifest(client, pageId) {
return await client.nextGenSearchPages.manifest(pageId, {
pagePlaceholders: {
results: '--results--',
},
});
}