Skip to content

Commit

Permalink
feat: add max level for toc headings
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickHeneise committed Apr 6, 2023
1 parent cba361e commit 23ef6c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ Can be used if the docs are not located in the root of the repository.
useMDX: true,
```
Limit the level of headings for the Table of Contents
```jsx
tocMaxDepth: 3,
```
Switch from Markdown to MDX.
```jsx
Expand Down
7 changes: 5 additions & 2 deletions src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ const defaults = {
repo: null,
tag: null,
assetsDestination: null,
debug: process.env.DEBUG === true
debug: process.env.DEBUG === true,
tocMaxDepth: 10
}

export async function pageProps(context, args) {
const options = { ...defaults, ...args }
const params = context.params
const { docsFolder, trailingSlash, skipPathPrefix, useMDX } = options
const { docsFolder, trailingSlash, skipPathPrefix, useMDX, tocMaxDepth } =
options

const slugger = new GithubSlugger()
const manifest = await fetchDocsManifest(docsFolder, options).catch(
Expand Down Expand Up @@ -154,6 +156,7 @@ export async function pageProps(context, args) {
const markdownTokens = marked.lexer(content)
const headings = markdownTokens
.filter((t) => t.type === 'heading')
.filter((t) => t.depth <= tocMaxDepth)
.map((heading) => {
heading.slug = slugger.slug(heading.text)
return heading
Expand Down

0 comments on commit 23ef6c9

Please sign in to comment.