Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dev into production #1631

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading