X Tutup
The Wayback Machine - https://web.archive.org/web/20230218233857/https://github.com/nodejs/node/commit/8099bfb35c
Skip to content
Permalink
Browse files
doc: remove TOC summary for pages with no TOC
Remove the table of contents summary for pages with no table of
contents. Currently, this affects at least index.html.

PR-URL: #37043
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
Trott authored and targos committed May 1, 2021
1 parent b0c9b1f commit 8099bfb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
@@ -55,10 +55,7 @@ <h1>Node.js __VERSION__ Documentation</h1>
<hr>
</header>

<details id="toc" open>
<summary>Table of Contents</summary>
__TOC__
</details>
__TOC__

<div id="apicontent">
__CONTENT__
@@ -59,9 +59,11 @@ let all = toc.replace(/index\.html/g, 'all.html')
all = all.replace(/<title>.*?\| /, '<title>');

// Insert the combined table of contents.
const tocStart = /<\w+ id="toc"[^>]*>\s*<\w+>.*?<\/\w+>\s*/.exec(all);
const tocStart = /<!-- TOC -->/.exec(all);
all = all.slice(0, tocStart.index + tocStart[0].length) +
'<details id="toc" open><summary>Table of contents</summary>\n' +
'<ul>\n' + contents + '</ul>\n' +
'</details>\n' +
all.slice(tocStart.index + tocStart[0].length);

// Replace apicontent with the concatenated set of apicontents from each source.
@@ -382,13 +382,19 @@ function buildToc({ filename, apilinks }) {
node.children.push({ type: 'html', value: anchor });
});

file.toc = unified()
.use(markdown)
.use(gfm)
.use(remark2rehype, { allowDangerousHtml: true })
.use(raw)
.use(htmlStringify)
.processSync(toc).toString();
if (toc !== '') {
file.toc = '<details id="toc" open><summary>Table of contents</summary>' +
unified()
.use(markdown)
.use(gfm)
.use(remark2rehype, { allowDangerousHtml: true })
.use(raw)
.use(htmlStringify)
.processSync(toc).toString() +
'</details>';
} else {
file.toc = '<!-- TOC -->';
}
};
}

0 comments on commit 8099bfb

Please sign in to comment.
X Tutup