Skip to content

Commit

Permalink
doc: remove TOC summary for pages with no TOC
Browse files Browse the repository at this point in the history
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 Feb 2, 2021
1 parent 181719d commit 9b9a180
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 1 addition & 4 deletions doc/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
4 changes: 3 additions & 1 deletion tools/doc/allhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 13 additions & 7 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->';
}
};
}

Expand Down

0 comments on commit 9b9a180

Please sign in to comment.