Skip to content

Commit b9bbbbe

Browse files
rubystargos
authored andcommitted
tools: build all.json by combining generated JSON
Notes: 1) Removed a number of root properties that did not seem relevant: source, desc, and introduced_in. There no longer is a source, and the other two are from the first include and do not reflect the entire API. 2) As with #20100, the current "desc" properties sometimes contained in-page links, other times referenced another page, and often did not match the links in the original HTML or JSON file. I chose to standardize on external links as "desc" values are isolated snippets as opposed to all.html which can be viewed as a standalone and self contained document. 3) Eliminated preprocessing for @include entirely, including the test case for this function. 4) _toc.md was renamed to index.md. 5) index comments no longer appear in embedded TOCs (left hand side column in the generated documentation. PR-URL: #21637 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 4f3bbfa commit b9bbbbe

12 files changed

+165
-216
lines changed

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ doc-only: $(apidoc_dirs) $(apiassets) ## Builds the docs with the local or the
622622
if [ ! -d doc/api/assets ]; then \
623623
$(MAKE) tools/doc/node_modules/js-yaml/package.json; \
624624
fi;
625-
@$(MAKE) $(apidocs_html) $(apidocs_json)
625+
@$(MAKE) out/doc/api/all.html out/doc/api/all.json
626626

627627
.PHONY: doc
628628
doc: $(NODE_EXE) doc-only
@@ -672,10 +672,12 @@ out/doc/api/%.json: doc/api/%.md tools/doc/generate.js tools/doc/json.js
672672
out/doc/api/%.html: doc/api/%.md tools/doc/generate.js tools/doc/html.js
673673
$(call available-node, $(gen-html))
674674

675-
out/doc/api/all.html: $(filter-out out/doc/api/all.html, $(apidocs_html)) \
676-
tools/doc/allhtml.js
675+
out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js
677676
$(call available-node, tools/doc/allhtml.js)
678677

678+
out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.js
679+
$(call available-node, tools/doc/alljson.js)
680+
679681
.PHONY: docopen
680682
docopen: $(apidocs_html)
681683
@$(PYTHON) -mwebbrowser file://$(PWD)/out/doc/api/all.html

doc/api/_toc.md

-62
This file was deleted.

doc/api/all.md

-50
This file was deleted.

doc/api/index.md

+64-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
@include _toc.md
1+
<!--
2+
NB(chrisdickinson): if you move this file, be sure to update
3+
tools/doc/html.js to point at the new location.
4+
-->
5+
6+
<!--introduced_in=v0.10.0-->
7+
8+
* [About these Docs](documentation.html)
9+
* [Usage & Example](synopsis.html)
10+
11+
<div class="line"></div>
12+
13+
* [Assertion Testing](assert.html)
14+
* [Async Hooks](async_hooks.html)
15+
* [Buffer](buffer.html)
16+
* [C++ Addons](addons.html)
17+
* [C/C++ Addons - N-API](n-api.html)
18+
* [Child Processes](child_process.html)
19+
* [Cluster](cluster.html)
20+
* [Command Line Options](cli.html)
21+
* [Console](console.html)
22+
* [Crypto](crypto.html)
23+
* [Debugger](debugger.html)
24+
* [Deprecated APIs](deprecations.html)
25+
* [DNS](dns.html)
26+
* [Domain](domain.html)
27+
* [ECMAScript Modules](esm.html)
28+
* [Errors](errors.html)
29+
* [Events](events.html)
30+
* [File System](fs.html)
31+
* [Globals](globals.html)
32+
* [HTTP](http.html)
33+
* [HTTP/2](http2.html)
34+
* [HTTPS](https.html)
35+
* [Inspector](inspector.html)
36+
* [Internationalization](intl.html)
37+
* [Modules](modules.html)
38+
* [Net](net.html)
39+
* [OS](os.html)
40+
* [Path](path.html)
41+
* [Performance Hooks](perf_hooks.html)
42+
* [Process](process.html)
43+
* [Punycode](punycode.html)
44+
* [Query Strings](querystring.html)
45+
* [Readline](readline.html)
46+
* [REPL](repl.html)
47+
* [Stream](stream.html)
48+
* [String Decoder](string_decoder.html)
49+
* [Timers](timers.html)
50+
* [TLS/SSL](tls.html)
51+
* [Trace Events](tracing.html)
52+
* [TTY](tty.html)
53+
* [UDP/Datagram](dgram.html)
54+
* [URL](url.html)
55+
* [Utilities](util.html)
56+
* [V8](v8.html)
57+
* [VM](vm.html)
58+
* [Worker Threads](worker_threads.html)
59+
* [ZLIB](zlib.html)
60+
61+
<div class="line"></div>
62+
63+
* [GitHub Repo & Issue Tracker](https://github.com/nodejs/node)
64+
* [Mailing List](https://groups.google.com/group/nodejs)

test/doctool/test-doctool-html.js

+26-38
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ try {
1111
const assert = require('assert');
1212
const { readFile } = require('fs');
1313
const fixtures = require('../common/fixtures');
14-
const processIncludes = require('../../tools/doc/preprocess.js');
1514
const toHTML = require('../../tools/doc/html.js');
1615

1716
// Test data is a list of objects with two properties.
@@ -64,15 +63,6 @@ const testData = [
6463
'<!-- This is not a metadata comment --> ' +
6564
'<p>Describe <code>Something</code> in more detail here. </p>'
6665
},
67-
{
68-
file: fixtures.path('doc_with_includes.md'),
69-
html: '<!-- [start-include:doc_inc_1.md] -->' +
70-
'<p>Look <a href="doc_inc_2.html#doc_inc_2_foobar">here</a>!</p>' +
71-
'<!-- [end-include:doc_inc_1.md] --><!-- [start-include:doc_inc_2.md] -->' +
72-
'<h1>foobar<span><a class="mark" href="#doc_inc_2_foobar" ' +
73-
'id="doc_inc_2_foobar">#</a></span></h1>' +
74-
'<p>I exist and am being linked to.</p><!-- [end-include:doc_inc_2.md] -->'
75-
},
7666
{
7767
file: fixtures.path('sample_document.md'),
7868
html: '<ol><li>fish</li><li><p>fish</p></li><li><p>Redfish</p></li>' +
@@ -90,36 +80,34 @@ testData.forEach(({ file, html, analyticsId }) => {
9080

9181
readFile(file, 'utf8', common.mustCall((err, input) => {
9282
assert.ifError(err);
93-
processIncludes(file, input, common.mustCall((err, preprocessed) => {
94-
assert.ifError(err);
9583

96-
toHTML(
97-
{
98-
input: preprocessed,
99-
filename: 'foo',
100-
nodeVersion: process.version,
101-
analytics: analyticsId,
102-
},
103-
common.mustCall((err, output) => {
104-
assert.ifError(err);
84+
toHTML(
85+
{
86+
input: input,
87+
filename: 'foo',
88+
nodeVersion: process.version,
89+
analytics: analyticsId,
90+
},
91+
common.mustCall((err, output) => {
92+
assert.ifError(err);
10593

106-
const actual = output.replace(spaces, '');
107-
// Assert that the input stripped of all whitespace contains the
108-
// expected markup.
109-
assert(actual.includes(expected));
94+
const actual = output.replace(spaces, '');
95+
// Assert that the input stripped of all whitespace contains the
96+
// expected markup.
97+
assert(actual.includes(expected));
11098

111-
// Testing the insertion of Google Analytics script when
112-
// an analytics id is provided. Should not be present by default.
113-
const scriptDomain = 'google-analytics.com';
114-
if (includeAnalytics) {
115-
assert(actual.includes(scriptDomain),
116-
`Google Analytics script was not present in "${actual}"`);
117-
} else {
118-
assert.strictEqual(actual.includes(scriptDomain), false,
119-
'Google Analytics script was present in ' +
120-
`"${actual}"`);
121-
}
122-
}));
123-
}));
99+
// Testing the insertion of Google Analytics script when
100+
// an analytics id is provided. Should not be present by default.
101+
const scriptDomain = 'google-analytics.com';
102+
if (includeAnalytics) {
103+
assert(actual.includes(scriptDomain),
104+
`Google Analytics script was not present in "${actual}"`);
105+
} else {
106+
assert.strictEqual(actual.includes(scriptDomain), false,
107+
'Google Analytics script was present in ' +
108+
`"${actual}"`);
109+
}
110+
})
111+
);
124112
}));
125113
});

test/doctool/test-make-doc.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ const path = require('path');
1313

1414
const apiPath = path.resolve(__dirname, '..', '..', 'out', 'doc', 'api');
1515
const allDocs = fs.readdirSync(apiPath);
16-
assert.ok(allDocs.includes('_toc.html'));
16+
assert.ok(allDocs.includes('index.html'));
1717

1818
const actualDocs = allDocs.filter(
1919
(name) => {
2020
const extension = path.extname(name);
21-
return (extension === '.html' || extension === '.json') &&
22-
name !== '_toc.html';
21+
return extension === '.html' || extension === '.json';
2322
}
2423
);
2524

26-
const toc = fs.readFileSync(path.resolve(apiPath, '_toc.html'), 'utf8');
25+
const toc = fs.readFileSync(path.resolve(apiPath, 'index.html'), 'utf8');
2726
const re = /href="([^/]+\.html)"/;
2827
const globalRe = new RegExp(re, 'g');
2928
const links = toc.match(globalRe);
@@ -32,8 +31,7 @@ assert.notStrictEqual(links, null);
3231
// Filter out duplicate links, leave just filenames, add expected JSON files.
3332
const linkedHtmls = [...new Set(links)].map((link) => link.match(re)[1]);
3433
const expectedJsons = linkedHtmls
35-
.map((name) => name.replace('.html', '.json'))
36-
.concat('_toc.json');
34+
.map((name) => name.replace('.html', '.json'));
3735
const expectedDocs = linkedHtmls.concat(expectedJsons);
3836

3937
// Test that all the relative links in the TOC match to the actual documents.

test/fixtures/doc_with_includes.md

-2
This file was deleted.

tools/doc/allhtml.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const htmlFiles = fs.readdirSync(source, 'utf8')
1212
.filter((name) => name.includes('.html') && name !== 'all.html');
1313

1414
// Read the table of contents.
15-
const toc = fs.readFileSync(source + '/_toc.html', 'utf8');
15+
const toc = fs.readFileSync(source + '/index.html', 'utf8');
1616

1717
// Extract (and concatenate) the toc and apicontent from each document.
1818
let contents = '';
@@ -47,11 +47,12 @@ for (const link of toc.match(/<a.*?>/g)) {
4747
seen[href] = true;
4848
}
4949

50-
// Replace various mentions of _toc with all.
51-
let all = toc.replace(/_toc\.html/g, 'all.html')
52-
.replace('_toc.json', 'all.json')
53-
.replace('api-section-_toc', 'api-section-all')
54-
.replace('data-id="_toc"', 'data-id="all"');
50+
// Replace various mentions of index with all.
51+
let all = toc.replace(/index\.html/g, 'all.html')
52+
.replace('<a href="all.html" name="toc">', '<a href="index.html" name="toc">')
53+
.replace('index.json', 'all.json')
54+
.replace('api-section-index', 'api-section-all')
55+
.replace('data-id="index"', 'data-id="all"');
5556

5657
// Clean up the title.
5758
all = all.replace(/<title>.*?\| /, '<title>');

0 commit comments

Comments
 (0)