diff --git a/docs/api/config-file.md b/docs/api/config-file.md index e9c61e0..52e75e4 100644 --- a/docs/api/config-file.md +++ b/docs/api/config-file.md @@ -38,6 +38,7 @@ module.exports = new Promise((resolve, reject) => { | table\_of_contents | object | | | | table\_of_contents.page | boolean | `true` | Whether to enable the table of contents for headers in the page. | | table\_of_contents.folder | boolean | `true` | Whether to enable the table of contents for pages in a folder (shown in the [index page](/index-files).) | +| table\_of_contents.max_depth | number | `2` | Defines a maximum header level depth to render in the TOC. | | syntax | object | | | | syntax.theme | string | `atom-one-light` | The [syntax highlighting theme](/syntax-highlighting/#choosing-a-style) to use. | | syntax.renderer | string | `hljs` | The [syntax highlighting renderer](/syntax-highlighting/#choosing-a-renderer) to use. Options are `hljs` or `prism`. | diff --git a/src/core/hydrate.js b/src/core/hydrate.js index f4da4e7..fd7c434 100644 --- a/src/core/hydrate.js +++ b/src/core/hydrate.js @@ -6,6 +6,7 @@ const { mergeLeftByKey } = require('../utils/merge') const { getContent } = require('./filesystem') const { walkSource } = require('./source') const Sitemap = require('./sitemap') +const DEFAULT_TOC_DEPTH = 2 async function getMetaData (item, parentItems) { const data = item.type === 'file' @@ -54,7 +55,7 @@ async function tableOfContents (toc, { input, items }) { if (input) { if (toc.page) { toc.page = markdownToc(await getContent(input)) - .json.filter(i => i.lvl <= 2) + .json.filter(i => i.lvl <= (toc.max_depth || DEFAULT_TOC_DEPTH)) } if (toc.folder) { diff --git a/themes/default/markdown/overrides/Header.js b/themes/default/markdown/overrides/Header.js index 364f2ca..23c5082 100644 --- a/themes/default/markdown/overrides/Header.js +++ b/themes/default/markdown/overrides/Header.js @@ -48,7 +48,5 @@ export default function (props) { const element = React.createElement(levels[level], { style }, children) - return level <= 2 - ? {element} - : element + return {element} } diff --git a/themes/default/toc/page.js b/themes/default/toc/page.js index 66fe33a..4151009 100644 --- a/themes/default/toc/page.js +++ b/themes/default/toc/page.js @@ -8,7 +8,7 @@ const Toc = (props) => { // Create TOC hierarchy and link to headers const items = props.items.map(t => ( -