From 63245d9afd327d3187019e687273d4ba13a4b481 Mon Sep 17 00:00:00 2001 From: rei Date: Mon, 13 Mar 2023 23:43:17 +0100 Subject: [PATCH] WIP: c9f5dfc Update 'content/projects/RE-Chess.md' --- pages/project/[slug].tsx | 9 ++++++++- styles/globals.css | 15 +++++++++------ utils/markdown.ts | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/pages/project/[slug].tsx b/pages/project/[slug].tsx index 7bf0c97..0dee3b0 100644 --- a/pages/project/[slug].tsx +++ b/pages/project/[slug].tsx @@ -1,7 +1,11 @@ import { GetStaticPaths, GetStaticProps } from "next"; import fs from "fs"; import { ParsedUrlQuery } from "querystring"; -import { getProjectContentBySlug, PROJECTS_PATH } from "../../utils/markdown"; +import { + getHeadings, + getProjectContentBySlug, + PROJECTS_PATH, +} from "../../utils/markdown"; import { MarkdownRenderingResult } from "../../types/types"; import { MainLayout } from "../../layouts/MainLayout"; import Link from "next/link"; @@ -52,6 +56,9 @@ export const getStaticProps: GetStaticProps = async ({ params, }) => { const markdownContent = getProjectContentBySlug(params?.slug as string); + + console.log(getHeadings(markdownContent.content)); + return { props: { frontMatter: markdownContent.frontMatter, diff --git a/styles/globals.css b/styles/globals.css index 45e513d..6e4d75f 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -27,14 +27,17 @@ pre > code { } .codeStyle { - @apply bg-transparent !important + @apply bg-transparent !important; } pre > div > div > button > svg:hover { @apply hover:text-action transition-all ease-in-out duration-100 !important; } -h1 > a, h2 > a, h3 > a, h4 > a { +h1 > a, +h2 > a, +h3 > a, +h4 > a { @apply cursor-pointer relative text-gray-800 dark:text-gray-100 decoration-transparent font-bold !important; } @@ -57,9 +60,9 @@ h4 > a:hover::before { @apply -left-4; } - -div > code, pre > code { - @apply p-0 m-0 !important +div > code, +pre > code { + @apply p-0 m-0 !important; } .slider { @@ -107,4 +110,4 @@ div > code, pre > code { opacity: 1; transition-duration: 0.5s; transform: scale(0.8); -} \ No newline at end of file +} diff --git a/utils/markdown.ts b/utils/markdown.ts index 8fc4b69..27d40ac 100644 --- a/utils/markdown.ts +++ b/utils/markdown.ts @@ -74,6 +74,24 @@ export const getAllProjectsFrontMatter = (): Post[] => { ); }; +export const getHeadings = (markdown: string): any => { + const headingOne = markdown.match(/^(#{1})\s(.*)/gm); + const headingTwo = markdown.match(/^(#{2})\s(.*)/gm); + const headingThree = markdown.match(/^(#{3})\s(.*)/gm); + const headingFour = markdown.match(/^(#{4})\s(.*)/gm); + + const headings = markdown.match(/^(#{1,4})\s(.*)/gm); + var tree: any[] = []; + var prev = ""; + headings?.forEach((heading) => { + if (headingOne?.includes(heading)) { + tree.push(heading); + } + }); + + return tree; +}; + export async function markdownToHtml(markdown: any) { const result = await remark().use(html).process(markdown); return result.toString();