From 263d40746ca3bc87a4d8ea4b7298e69b2975b872 Mon Sep 17 00:00:00 2001 From: techmannih Date: Sun, 5 Jan 2025 09:50:44 +0530 Subject: [PATCH] format code --- components/StyledMarkdown.tsx | 3 +- components/TOC.tsx | 117 +++++++++++++++++++++++++------ pages/blog/posts/[slug].page.tsx | 8 +-- pages/learn/[slug].page.tsx | 11 ++- pages/overview/[slug].page.tsx | 11 ++- 5 files changed, 109 insertions(+), 41 deletions(-) diff --git a/components/StyledMarkdown.tsx b/components/StyledMarkdown.tsx index 4ff79a73f..51eaf9446 100644 --- a/components/StyledMarkdown.tsx +++ b/components/StyledMarkdown.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext } from 'react'; import Markdown from 'markdown-to-jsx'; import Link from 'next/link'; import JsonEditor from '~/components/JsonEditor'; @@ -545,7 +545,6 @@ const StyledMarkdownBlock = ({ markdown }: { markdown: string }) => { ); }; - const checkHasContent = (reactNode: React.ReactChild) => { if (!reactNode) return false; if (typeof reactNode === 'string' || typeof reactNode === 'number') diff --git a/components/TOC.tsx b/components/TOC.tsx index cc71c6277..378334a3f 100644 --- a/components/TOC.tsx +++ b/components/TOC.tsx @@ -24,7 +24,11 @@ const hiddenElements = (...elements: string[]) => { }; // HeadingLink component to render each heading with a link -const HeadingLink: React.FC<{ children: React.ReactNode; level: number; isActive: boolean }> = ({ children, level, isActive }) => { +const HeadingLink: React.FC<{ + level: number; + isActive: boolean; + children: React.ReactNode; +}> = ({ level, isActive, children }) => { const text = getTextFromChildren(children); // Get the plain text for slug const slug = slugifyMarkdownHeadline(text); // Generate slug from text const paddingClass = `pl-${level * 2}`; // Adjust padding based on heading level @@ -45,7 +49,10 @@ interface TableOfContentMarkdownProps { depth?: number; } -export const TableOfContentMarkdown: React.FC = ({ markdown, depth = 2 }) => { +export const TableOfContentMarkdown: React.FC = ({ + markdown, + depth = 2, +}) => { const [activeSlug, setActiveSlug] = useState(null); useEffect(() => { @@ -69,34 +76,98 @@ export const TableOfContentMarkdown: React.FC = ({ }, []); return ( -
-
-
On this page
+
+
+
+ On this page +
( - + + {children} + ), }, h2: { - component: depth >= 3 ? ({ children }) => ( - - ) : () => null, + component: + depth >= 3 + ? ({ children }) => ( + + {children} + + ) + : () => null, }, h3: { - component: depth >= 3 ? ({ children }) => ( - - ) : () => null, + component: + depth >= 3 + ? ({ children }) => ( + + {children} + + ) + : () => null, }, h4: { - component: depth >= 3 ? ({ children }) => ( - - ) : () => null, + component: + depth >= 3 + ? ({ children }) => ( + + {children} + + ) + : () => null, }, - - ...hiddenElements('strong', 'p', 'a', 'ul', 'li', 'table', 'code', 'pre', 'blockquote', 'span', 'div', 'figure', 'Bigquote', 'Regularquote', 'specialBox'), + ...hiddenElements( + 'strong', + 'p', + 'a', + 'ul', + 'li', + 'table', + 'code', + 'pre', + 'blockquote', + 'span', + 'div', + 'figure', + 'Bigquote', + 'Regularquote', + 'specialBox', + ), }, }} > @@ -107,16 +178,18 @@ export const TableOfContentMarkdown: React.FC = ({ ); }; -export const TableOfContentLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => { +export const TableOfContentLayout: React.FC<{ children: React.ReactNode }> = ({ + children, +}) => { return ( -
-
+
+
{/* TOC on the left */} -
+
{/* Main content on the right */} -
+
{children}
diff --git a/pages/blog/posts/[slug].page.tsx b/pages/blog/posts/[slug].page.tsx index f52b2e430..21ad201f1 100644 --- a/pages/blog/posts/[slug].page.tsx +++ b/pages/blog/posts/[slug].page.tsx @@ -9,9 +9,7 @@ import readingTime from 'reading-time'; import { Headline1 } from '~/components/Headlines'; import { SectionContext } from '~/context'; import CarbonAds from '~/components/CarbonsAds'; -import { - TableOfContentMarkdown, -} from '~/components/TOC'; +import { TableOfContentMarkdown } from '~/components/TOC'; export async function getStaticPaths() { return getStaticMarkdownPaths('pages/blog/posts'); } @@ -92,8 +90,8 @@ export default function StaticMarkdownPage({ }, )}
-
- +
+
diff --git a/pages/learn/[slug].page.tsx b/pages/learn/[slug].page.tsx index 22817b37d..3c460a256 100644 --- a/pages/learn/[slug].page.tsx +++ b/pages/learn/[slug].page.tsx @@ -28,7 +28,6 @@ export default function StaticMarkdownPage({ const newTitle = 'JSON Schema - ' + frontmatter.title; return ( -
@@ -37,11 +36,11 @@ export default function StaticMarkdownPage({ {frontmatter.title} + prevLabel={frontmatter?.prev?.label} + prevURL={frontmatter?.prev?.url} + nextLabel={frontmatter?.next?.label} + nextURL={frontmatter?.next?.url} + />
diff --git a/pages/overview/[slug].page.tsx b/pages/overview/[slug].page.tsx index 2970df438..ea891b7ab 100644 --- a/pages/overview/[slug].page.tsx +++ b/pages/overview/[slug].page.tsx @@ -30,7 +30,6 @@ export default function StaticMarkdownPage({ return ( -
@@ -39,11 +38,11 @@ export default function StaticMarkdownPage({ {frontmatter.title} + prevLabel={frontmatter.prev?.label} + prevURL={frontmatter.prev?.url} + nextLabel={frontmatter.next.label} + nextURL={frontmatter.next.url} + />