Skip to content

Commit

Permalink
Merge pull request #1631 from starknet-io/dev
Browse files Browse the repository at this point in the history
Merge dev into production
  • Loading branch information
nuno-aac authored Nov 13, 2023
2 parents 9c9eee7 + 1c7f2e9 commit 8ae705b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion workspaces/cms-config/src/collections/roadmapPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const roadmapStagesFields = [
icon: BiBullseye
},
{
label: "Backlog",
label: "Details are WIP",
value: "backlog",
icon: AiOutlineAppstore
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import remarkParse from "remark-parse";
import { unified } from "unified";
import { Index } from "unist-util-index";

import { TopLevelBlock } from "@starknet-io/cms-data/src/pages";
import { HeadingData } from "./TableOfContents";

/**
* `Node`type.
*/

type Node = {
children: Node[];
depth: number;
type: string;
value: string;
}

export function blocksToTOC(blocks: readonly TopLevelBlock[] = [], level: number, tableOfContents: HeadingData[] = []): readonly HeadingData[] {
blocks.forEach((block) => {
if(block.type === 'page_header'){
Expand Down Expand Up @@ -50,18 +60,21 @@ export function blocksToTOC(blocks: readonly TopLevelBlock[] = [], level: number
.use(() => {
return (tree: any) => {
const typeIndex = new Index("type", tree);
const headings = typeIndex.get("heading");

const headingItems: HeadingData[] = headings.map((node: any) => {
const textNode = node.children.find((n: any) => {
return n.type === "text";
const headings = typeIndex.get("heading") as Node[];
const headingItems = headings.map(node => {
const textNode = node?.children?.find(child => {
return (child.type === "text" || child.type === "strong") && node.depth < 4;
});

if (!textNode) {
return null;
}

return {
title: textNode?.value ?? "",
level
title: textNode?.value ?? textNode?.children[0].value ?? "",
level: node.depth - 1
};
});
}).filter(heading => !!heading) as HeadingData[];

tableOfContents.push(...headingItems);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface KeyValuePairs {
const stages: KeyValuePairs = {
"building-now": "Building now",
"building-next": "Building next",
"backlog": "Backlog",
"backlog": "Details are WIP",
};

export type RoadmapPostProps = {
Expand Down

0 comments on commit 8ae705b

Please sign in to comment.