-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
babf835
commit 121676f
Showing
6 changed files
with
124 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"tech-stack":1,"python":2,"http":1,"backend":2,"nextjs":1,"relay":2,"graphql":2,"typescript":1,"frontend":2,"fastapi":1,"strawberry-graphql":1,"react":1,"javascript":1} | ||
{"nextjs":1,"relay":2,"graphql":2,"typescript":1,"frontend":2,"tech-stack":1,"python":2,"http":1,"backend":2,"fastapi":1,"strawberry-graphql":1,"react":1,"javascript":1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import TOCInline from 'pliny/ui/TOCInline' | ||
import Pre from './Pre' | ||
import BlogNewsletterForm from 'pliny/ui/BlogNewsletterForm' | ||
import type { MDXComponents } from 'mdx/types' | ||
import Image from './Image' | ||
import CustomLink from './Link' | ||
import TableWrapper from './TableWrapper' | ||
import TOCInline from "./TOCInline"; | ||
import Pre from "./Pre"; | ||
import BlogNewsletterForm from "pliny/ui/BlogNewsletterForm"; | ||
import type { MDXComponents } from "mdx/types"; | ||
import Image from "./Image"; | ||
import CustomLink from "./Link"; | ||
import TableWrapper from "./TableWrapper"; | ||
|
||
export const components: MDXComponents = { | ||
Image, | ||
TOCInline, | ||
a: CustomLink, | ||
pre: Pre, | ||
table: TableWrapper, | ||
BlogNewsletterForm, | ||
} | ||
Image, | ||
TOCInline, | ||
a: CustomLink, | ||
pre: Pre, | ||
table: TableWrapper, | ||
BlogNewsletterForm, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"use client"; | ||
|
||
import type { TocItem } from "pliny/mdx-plugins/remark-toc-headings"; | ||
import type { NestedTocItem, TOCInlineProps } from "pliny/ui/TOCInline"; | ||
import ScrollSpy from "react-scrollspy-navigation"; | ||
|
||
const createNestedList = (items: TocItem[]): NestedTocItem[] => { | ||
const nestedList: NestedTocItem[] = []; | ||
const stack: NestedTocItem[] = []; | ||
|
||
items.forEach((item) => { | ||
const newItem: NestedTocItem = { ...item }; | ||
|
||
while (stack.length > 0 && stack[stack.length - 1].depth >= newItem.depth) { | ||
stack.pop(); | ||
} | ||
|
||
const parent = stack.length > 0 ? stack[stack.length - 1] : null; | ||
|
||
if (parent) { | ||
parent.children = parent.children || []; | ||
parent.children.push(newItem); | ||
} else { | ||
nestedList.push(newItem); | ||
} | ||
|
||
stack.push(newItem); | ||
}); | ||
|
||
return nestedList; | ||
}; | ||
|
||
const TOCInline = ({ | ||
toc, | ||
fromHeading = 1, | ||
toHeading = 6, | ||
asDisclosure = false, | ||
exclude = "", | ||
collapse = false, | ||
ulClassName = "list-decimal", | ||
liClassName = "", | ||
}: TOCInlineProps) => { | ||
const re = Array.isArray(exclude) | ||
? new RegExp("^(" + exclude.join("|") + ")$", "i") | ||
: new RegExp("^(" + exclude + ")$", "i"); | ||
|
||
const filteredToc = toc.filter( | ||
(heading) => | ||
heading.depth >= fromHeading && | ||
heading.depth <= toHeading && | ||
!re.test(heading.value), | ||
); | ||
|
||
const createList = (items: NestedTocItem[] | undefined) => { | ||
if (!items || items.length === 0) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<ul className={ulClassName}> | ||
{items.map((item, index) => { | ||
return ( | ||
<li key={index} className={liClassName}> | ||
<a href={item.url} className="no-underline text-foreground"> | ||
{item.value} | ||
</a> | ||
{createList(item.children)} | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
); | ||
}; | ||
|
||
const nestedList = createNestedList(filteredToc); | ||
|
||
return ( | ||
<> | ||
{asDisclosure ? ( | ||
<details open={!collapse}> | ||
<summary className="ml-6 pb-2 pt-2 text-xl font-bold"> | ||
Table of Contents | ||
</summary> | ||
<div className="ml-6"> | ||
<ScrollSpy activeClass="font-bold"> | ||
<nav>{createList(nestedList)}</nav> | ||
</ScrollSpy> | ||
</div> | ||
</details> | ||
) : ( | ||
<ScrollSpy activeClass="font-bold"> | ||
<nav>{createList(nestedList)}</nav> | ||
</ScrollSpy> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default TOCInline; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters