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

fix: Implement a TOC component #1127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export const SidebarLayout = ({ children }: { children: React.ReactNode }) => {
variant='sidebar'
/>
</div>
<div className='col-span-4 md:col-span-3 lg:mt-20 lg:w-5/6 mx-4 md:mx-0'>
<div className='col-span-4 md:col-span-3 lg:mt-20 mx-4 md:mx-0'>
{children}
</div>
</div>
Expand Down
120 changes: 51 additions & 69 deletions components/StyledMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,6 @@ export function TableOfContentMarkdown({
href={`#${slug}`}
className='block cursor-pointer mb-3 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ml-[-0.40rem] font-medium'
>
<span className='mr-1 text-blue-400/90 text-[1em] flex justify-center items-center'>
&#9679;
</span>
{children}
</a>
);
Expand All @@ -567,91 +564,76 @@ export function TableOfContentMarkdown({
h2:
depth === 0
? {
component: ({ children }) => {
const slug = slugifyMarkdownHeadline(children);
return (
<a
href={`#${slug}`}
className='block cursor-pointer mb-3 ml- text-slate-600 hover:text-primary active:text-primary dark:text-slate-300 leading-4 font-medium'
>
{children}
</a>
);
},
}
: depth >= 2
? {
component: ({ children }) => {
const slug = slugifyMarkdownHeadline(children);
const [isChrome, setIsChrome] = useState(false);

useEffect(() => {
const chromeCheck =
/Chrome/.test(navigator.userAgent) &&
/Google Inc/.test(navigator.vendor);
setIsChrome(chromeCheck);
}, []);

return (
// chromeClass
<a
href={`#${slug}`}
className='block cursor-pointer mb-3 text-slate-600 dark:text-slate-300 leading-4 font-medium'
className={`block cursor-pointer mb-3 ml-2 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ] max-sm:-ml-[6px] font-medium ${isChrome ? '-ml-[4.8px]' : '-ml-[6.5px]'}`}
>

{children}
</a>
);
},
}
: depth >= 2
? {
component: ({ children }) => {
const slug = slugifyMarkdownHeadline(children);
const [isChrome, setIsChrome] = useState(false);

useEffect(() => {
const chromeCheck =
/Chrome/.test(navigator.userAgent) &&
/Google Inc/.test(navigator.vendor);
setIsChrome(chromeCheck);
}, []);

return (
// chromeClass
<a
href={`#${slug}`}
className={`block cursor-pointer mb-3 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ] max-sm:-ml-[6px] font-medium ${isChrome ? '-ml-[4.8px]' : '-ml-[6.5px]'}`}
>
<span className='mr-1 text-blue-400 text-[0.7em]'>
&#9679;
</span>
{children}
</a>
);
},
}
: { component: () => null },
h3:
depth >= 3
? {
component: ({ children }) => {
const slug = slugifyMarkdownHeadline(children);
return (
<a
href={`#${slug}`}
className='flex flex-row items-center cursor-pointer mb-3 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ml-[-0.25rem]'
>
<span className='text-blue-400/40 font-extrabold text-[0.8em] max-sm:text-[1.2em] ml-1'>
&mdash;&mdash;
</span>
<span className='mr-1 text-blue-400/90 text-[0.7em] flex justify-center items-center'>
&#9679;
</span>
component: ({ children }) => {
const slug = slugifyMarkdownHeadline(children);
return (
<a
href={`#${slug}`}
className='flex flex-row items-center cursor-pointer mb-3 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ml-4'
>

{children}
</a>
);
},
}
{children}
</a>
);
},
}
: { component: () => null },
h4:
depth >= 4
depth <= 4
? {
component: ({ children }) => {
const slug = slugifyMarkdownHeadline(children);
return (
<a
href={`#${slug}`}
className='flex flex-row items-center cursor-pointer mb-3 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ml-[-0.25rem] '
>
<span className='text-blue-400/40 font-extrabold text-[0.8em] ml-1 max-sm:text-[1.2em]'>
&mdash;&mdash;&mdash;&mdash;
</span>
<span className='mr-1 text-blue-400/90 text-[0.7em] flex justify-center items-center'>
&#9679;
</span>

{children}
</a>
);
},
} /* eslint-enable */
component: ({ children }) => {
const slug = slugifyMarkdownHeadline(children);
return (
<a
href={`#${slug}`}
className='flex flex-row items-center cursor-pointer mb-3 max-sm:text-sm text-slate-600 dark:text-slate-300 leading-4 ml-8 '
>
{children}
</a>
);
},
} /* eslint-enable */
: { component: () => null },
...hiddenElements(
'strong',
Expand Down
26 changes: 20 additions & 6 deletions pages/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { Headline1 } from '~/components/Headlines';
import { SectionContext } from '~/context';
import { DocsHelp } from '~/components/DocsHelp';
import { TableOfContentMarkdown } from '~/components/StyledMarkdown';

Check failure on line 10 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Delete `·`

export async function getStaticPaths() {
return getStaticMarkdownPaths('pages');
Expand All @@ -26,12 +27,25 @@
const newTitle = 'JSON Schema - ' + frontmatter.title;
return (
<SectionContext.Provider value={frontmatter.section || null}>
<Head>
<title>{newTitle}</title>
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />

Check failure on line 30 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Replace `⏎······<div·className="flex·pt-4"` with `······<div·className='flex·pt-4'`
<div className="flex pt-4">

Check failure on line 31 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unexpected usage of doublequote
<div className="w-full pr-5">

Check failure on line 32 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Replace `"w-full·pr-5"` with `'w-full·pr-5'`

Check failure on line 32 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unexpected usage of doublequote
<Head>
<title>{newTitle}</title>
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
</div>
<div className="w-2/5 lg:block mt-10 hidden sticky top-24 h-[calc(100vh-6rem)] overflow-hidden">

Check failure on line 40 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Replace `"w-2/5·lg:block·mt-10·hidden·sticky·top-24·h-[calc(100vh-6rem)]·overflow-hidden"` with `'w-2/5·lg:block·mt-10·hidden·sticky·top-24·h-[calc(100vh-6rem)]·overflow-hidden'`

Check failure on line 40 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unexpected usage of doublequote
<div className="h-full overflow-y-auto scrollbar-hidden pl-5">

Check failure on line 41 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Replace `"h-full·overflow-y-auto·scrollbar-hidden·pl-5"` with `'h-full·overflow-y-auto·scrollbar-hidden·pl-5'`

Check failure on line 41 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unexpected usage of doublequote
<div className="uppercase text-xs text-slate-400 mb-4">

Check failure on line 42 in pages/[slug].page.tsx

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Replace `"uppercase·text-xs·text-slate-400·mb-4"` with `'uppercase·text-xs·text-slate-400·mb-4'`
On this page
</div>
<TableOfContentMarkdown markdown={content} depth={3} />
</div>
</div>
</div>
</SectionContext.Provider>
);
}
Expand Down
23 changes: 17 additions & 6 deletions pages/draft-05/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SectionContext } from '~/context';
import DocTable from '~/components/DocTable';
import { Headline1 } from '~/components/Headlines';
import { DocsHelp } from '~/components/DocsHelp';

import { TableOfContentMarkdown } from '~/components/StyledMarkdown';
export async function getStaticProps() {
const index = fs.readFileSync('pages/draft-05/index.md', 'utf-8');
const main = fs.readFileSync('pages/draft-05/release-notes.md', 'utf-8');
Expand Down Expand Up @@ -35,11 +35,22 @@ export default function ImplementationsPages({
}) {
return (
<SectionContext.Provider value={null}>
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<StyledMarkdown markdown={blocks.body} />
<DocsHelp />
<div className="flex pt-4">
<div className="w-full pr-5">
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<StyledMarkdown markdown={blocks.body} />
<DocsHelp />
</div>
<div className="w-2/5 lg:block mt-10 hidden sticky top-24 h-[calc(100vh-6rem)] overflow-hidden">
<div className="h-full overflow-y-auto scrollbar-hidden pl-5">
<div className="uppercase text-xs text-slate-400 mb-4">On this page</div>
<TableOfContentMarkdown markdown={blocks.index} depth={3} />
<TableOfContentMarkdown markdown={blocks.body} depth={3} />
</div>
</div>
</div>
</SectionContext.Provider>
);
}
Expand Down
12 changes: 11 additions & 1 deletion pages/draft-06/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps';
import { Headline1 } from '~/components/Headlines';
import { SectionContext } from '~/context';
import { DocsHelp } from '~/components/DocsHelp';

import { TableOfContentMarkdown } from '~/components/StyledMarkdown';
export async function getStaticPaths() {
return getStaticMarkdownPaths('pages/draft-06');
}
Expand All @@ -27,12 +27,22 @@ export default function StaticMarkdownPage({

return (
<SectionContext.Provider value={frontmatter.section || null}>
<div className="flex pt-4">
<div className="w-full pr-5">
<Head>
<title>{newTitle}</title>
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
</div>
<div className="w-2/5 lg:block mt-10 hidden sticky top-24 h-[calc(100vh-6rem)] overflow-hidden">
<div className="h-full overflow-y-auto scrollbar-hidden pl-5">
<div className="uppercase text-xs text-slate-400 mb-4">On this page</div>
<TableOfContentMarkdown markdown={content} depth={3} />
</div>
</div>
</div>
</SectionContext.Provider>
);
}
Expand Down
12 changes: 11 additions & 1 deletion pages/draft-06/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SectionContext } from '~/context';
import DocTable from '~/components/DocTable';
import { Headline1 } from '~/components/Headlines';
import { DocsHelp } from '~/components/DocsHelp';

import { TableOfContentMarkdown } from '~/components/StyledMarkdown';
export async function getStaticProps() {
const index = fs.readFileSync('pages/draft-06/index.md', 'utf-8');

Expand All @@ -33,10 +33,20 @@ export default function ImplementationsPages({
}) {
return (
<SectionContext.Provider value={null}>
<div className="flex pt-4">
<div className="w-full pr-5">
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<DocsHelp />
</div>
<div className="w-2/5 lg:block mt-10 hidden sticky top-24 h-[calc(100vh-6rem)] overflow-hidden">
<div className="h-full overflow-y-auto scrollbar-hidden pl-5">
<div className="uppercase text-xs text-slate-400 mb-4">On this page</div>
<TableOfContentMarkdown markdown={blocks.index} depth={3} />
</div>
</div>
</div>
</SectionContext.Provider>
);
}
Expand Down
12 changes: 11 additions & 1 deletion pages/draft-07/[slug].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getStaticMarkdownProps from '~/lib/getStaticMarkdownProps';
import { Headline1 } from '~/components/Headlines';
import { SectionContext } from '~/context';
import { DocsHelp } from '~/components/DocsHelp';

import { TableOfContentMarkdown } from '~/components/StyledMarkdown';
export async function getStaticPaths() {
return getStaticMarkdownPaths('pages/draft-07');
}
Expand All @@ -27,12 +27,22 @@ export default function StaticMarkdownPage({

return (
<SectionContext.Provider value={frontmatter.section || null}>
<div className="flex pt-4">
<div className="w-full pr-5">
<Head>
<title>{newTitle}</title>
</Head>
<Headline1>{frontmatter.title}</Headline1>
<StyledMarkdown markdown={content} />
<DocsHelp markdownFile={markdownFile} />
</div>
<div className="w-2/5 lg:block mt-10 hidden sticky top-24 h-[calc(100vh-6rem)] overflow-hidden">
<div className="h-full overflow-y-auto scrollbar-hidden pl-5">
<div className="uppercase text-xs text-slate-400 mb-4">On this page</div>
<TableOfContentMarkdown markdown={content} depth={3} />
</div>
</div>
</div>
</SectionContext.Provider>
);
}
Expand Down
12 changes: 11 additions & 1 deletion pages/draft-07/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SectionContext } from '~/context';
import DocTable from '~/components/DocTable';
import { Headline1 } from '~/components/Headlines';
import { DocsHelp } from '~/components/DocsHelp';

import { TableOfContentMarkdown } from '~/components/StyledMarkdown';
export async function getStaticProps() {
const index = fs.readFileSync('pages/draft-07/index.md', 'utf-8');

Expand All @@ -33,10 +33,20 @@ export default function ImplementationsPages({
}) {
return (
<SectionContext.Provider value={null}>
<div className="flex pt-4">
<div className="w-full pr-5">
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<DocsHelp />
</div>
<div className="w-2/5 lg:block mt-10 hidden sticky top-24 h-[calc(100vh-6rem)] overflow-hidden">
<div className="h-full overflow-y-auto scrollbar-hidden pl-5">
<div className="uppercase text-xs text-slate-400 mb-4">On this page</div>
<TableOfContentMarkdown markdown={blocks.index} depth={3} />
</div>
</div>
</div>
</SectionContext.Provider>
);
}
Expand Down
12 changes: 11 additions & 1 deletion pages/draft/2019-09/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SectionContext } from '~/context';
import DocTable from '~/components/DocTable';
import { Headline1 } from '~/components/Headlines';
import { DocsHelp } from '~/components/DocsHelp';

import { TableOfContentMarkdown } from '~/components/StyledMarkdown';
export async function getStaticProps() {
const index = fs.readFileSync('pages/draft/2019-09/index.md', 'utf-8');
const { content: indexContent, data: indexData } = matter(index);
Expand All @@ -32,10 +32,20 @@ export default function ImplementationsPages({
}) {
return (
<SectionContext.Provider value={null}>
<div className="flex pt-4">
<div className="w-full pr-5">
<Headline1>{frontmatter.title}</Headline1>
<DocTable frontmatter={frontmatter} />
<StyledMarkdown markdown={blocks.index} />
<DocsHelp />
</div>
<div className="w-2/5 lg:block mt-10 hidden sticky top-24 h-[calc(100vh-6rem)] overflow-hidden">
<div className="h-full overflow-y-auto scrollbar-hidden pl-5">
<div className="uppercase text-xs text-slate-400 mb-4">On this page</div>
<TableOfContentMarkdown markdown={blocks.index} depth={3} />
</div>
</div>
</div>
</SectionContext.Provider>
);
}
Expand Down
Loading
Loading