import { generateBlockId, IBlockData } from "@schlechtenburg/core"; import { getDefaultData as getDefaultLayoutData, ILayoutData, name as layoutName } from "@schlechtenburg/layout"; import { getDefaultData as getDefaultHeadingData, name as headingName } from "@schlechtenburg/heading"; import { IPage } from "~~/composables/pages"; export const getNewPageBlock: () => IBlockData = () => ({ id: generateBlockId(), name: layoutName, data: getDefaultLayoutData({ children: [ { id: generateBlockId(), name: headingName, data: getDefaultHeadingData({ value: 'New page' }), } ], }), }); export const getPageParents = (page: IPage, pages: IPage[], parents: IPage[]):IPage[] => { const parent = pages.find(p => p.id === page.attributes?.parent?.data?.id); if (!parent) { return parents; } return getPageParents( parent, pages, [ parent, ...parents, ], ); }; export const getPagePath = (page: IPage, pages: IPage[]) => { const ancestors = [ ...getPageParents(page, pages, []), page, ]; return ancestors.reduce((path, page) => page.attributes?.slug ? `${path}/${page.attributes?.slug}` : path, ''); }