Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async ({ context, item }) => {
switch (item.type) {
case "page": {
if (!context.distinctParents.loaded) {
const ids = Object.keys(context.distinctParents.data);
await listPublishedPages({
args: { parent: ids },
context
}).then(results => {
for (let i = 0; i < results.length; i++) {
let { title, url, parent: id } = results[i];
context.distinctParents.data[id] = { id, title, url };
}
});
}
const page = context.distinctParents.data[item.page];
if (page) {
// First try to use the title set on the menu item. If none, use page title.
Object.assign(item, page, { title: item.title || page.title });
} else {
item.__cleanup__ = true;