Files
myeasycms-v2/apps/web/app/(marketing)/docs/layout.tsx
giancarlo 44373c0372 Update CMS client configuration and refactor content organization
The code changes involve a significant update to the configuration of our CMS client. The nature of retrieving content items has been refactored to be more granular, allowing for the identification and fetching of content from specified collections rather than general categories. These modifications improve the efficiency and specificity of content queries. Furthermore, other changes were made to provide a better alignment of our content structure, including the reorganization of content files and renaming of image paths in various components for consistency.
2024-04-10 15:52:26 +08:00

58 lines
1.2 KiB
TypeScript

import { Cms, createCmsClient } from '@kit/cms';
import { DocsNavigation } from '~/(marketing)/docs/_components/docs-navigation';
async function DocsLayout({ children }: React.PropsWithChildren) {
const cms = await createCmsClient();
const pages = await cms.getContentItems({
collection: 'documentation',
});
console.log(pages);
return (
<div className={'flex'}>
<DocsNavigation pages={buildDocumentationTree(pages)} />
{children}
</div>
);
}
export default DocsLayout;
// we want to place all the children under their parent
// based on the property parentId
function buildDocumentationTree(pages: Cms.ContentItem[]) {
const tree: Cms.ContentItem[] = [];
const map: Record<string, Cms.ContentItem> = {};
pages.forEach((page) => {
map[page.id] = page;
});
pages.forEach((page) => {
if (page.parentId) {
const parent = map[page.parentId];
if (!parent) {
return;
}
if (!parent.children) {
parent.children = [];
}
parent.children.push(page);
// sort children by order
parent.children.sort((a, b) => a.order - b.order);
} else {
tree.push(page);
}
});
return tree.sort((a, b) => a.order - b.order);
}