Update content categorization and handle hierarchical documentation

Enhancements were implemented to support hierarchical documentation. Local CMS now respects parent ID and order attributes of content items, and content can be categories as 'blog' or 'documentation'. Changes were also made to the wordpress integration supporting these new categorizations. Introduced working with nested documentation pages.
This commit is contained in:
giancarlo
2024-04-03 21:06:54 +08:00
parent 3fd216ba6e
commit 53afd10f32
22 changed files with 350 additions and 156 deletions

View File

@@ -1,4 +1,4 @@
import { createCmsClient } from '@kit/cms';
import { Cms, createCmsClient } from '@kit/cms';
import { DocsNavigation } from '~/(marketing)/docs/_components/docs-navigation';
@@ -6,17 +6,13 @@ async function DocsLayout({ children }: React.PropsWithChildren) {
const cms = await createCmsClient();
const pages = await cms.getContentItems({
type: 'page',
categories: ['documentation'],
depth: 1,
});
console.log(pages);
return (
<div className={'container mx-auto'}>
<div className={'flex'}>
<DocsNavigation pages={pages} />
<DocsNavigation pages={buildDocumentationTree(pages)} />
<div className={'flex w-full flex-col items-center'}>{children}</div>
</div>
@@ -25,3 +21,37 @@ async function DocsLayout({ children }: React.PropsWithChildren) {
}
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);
}