Skip to content

Commit 9b9a180

Browse files
Trotttargos
authored andcommitted
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>
1 parent 181719d commit 9b9a180

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

doc/template.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ <h1>Node.js __VERSION__ Documentation</h1>
5555
<hr>
5656
</header>
5757

58-
<details id="toc" open>
59-
<summary>Table of Contents</summary>
60-
__TOC__
61-
</details>
58+
__TOC__
6259

6360
<div id="apicontent">
6461
__CONTENT__

tools/doc/allhtml.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ let all = toc.replace(/index\.html/g, 'all.html')
5959
all = all.replace(/<title>.*?\| /, '<title>');
6060

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

6769
// Replace apicontent with the concatenated set of apicontents from each source.

tools/doc/html.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,19 @@ function buildToc({ filename, apilinks }) {
382382
node.children.push({ type: 'html', value: anchor });
383383
});
384384

385-
file.toc = unified()
386-
.use(markdown)
387-
.use(gfm)
388-
.use(remark2rehype, { allowDangerousHtml: true })
389-
.use(raw)
390-
.use(htmlStringify)
391-
.processSync(toc).toString();
385+
if (toc !== '') {
386+
file.toc = '<details id="toc" open><summary>Table of contents</summary>' +
387+
unified()
388+
.use(markdown)
389+
.use(gfm)
390+
.use(remark2rehype, { allowDangerousHtml: true })
391+
.use(raw)
392+
.use(htmlStringify)
393+
.processSync(toc).toString() +
394+
'</details>';
395+
} else {
396+
file.toc = '<!-- TOC -->';
397+
}
392398
};
393399
}
394400

0 commit comments

Comments
 (0)