diff --git a/Makefile b/Makefile index 38bb8406748000..f407066cf512ad 100644 --- a/Makefile +++ b/Makefile @@ -650,12 +650,16 @@ gen-json = tools/doc/generate.js --format=json $< > $@ gen-html = tools/doc/generate.js --node-version=$(FULLVERSION) --format=html \ --analytics=$(DOCS_ANALYTICS) $< > $@ -out/doc/api/%.json: doc/api/%.md +out/doc/api/%.json: doc/api/%.md tools/doc/generate.js tools/doc/json.js $(call available-node, $(gen-json)) -out/doc/api/%.html: doc/api/%.md +out/doc/api/%.html: doc/api/%.md tools/doc/generate.js tools/doc/html.js $(call available-node, $(gen-html)) +out/doc/api/all.html: $(filter-out out/doc/api/all.html, $(apidocs_html)) \ + tools/doc/allhtml.js + $(call available-node, tools/doc/allhtml.js) + .PHONY: docopen docopen: $(apidocs_html) @$(PYTHON) -mwebbrowser file://$(PWD)/out/doc/api/all.html diff --git a/tools/doc/allhtml.js b/tools/doc/allhtml.js new file mode 100644 index 00000000000000..fad530f1c44245 --- /dev/null +++ b/tools/doc/allhtml.js @@ -0,0 +1,73 @@ +'use strict'; + +// Build all.html by combining the generated toc and apicontent from each +// of the generated html files. + +const fs = require('fs'); + +const source = `${__dirname}/../../out/doc/api`; + +// Get a list of generated API documents. +const htmlFiles = fs.readdirSync(source, 'utf8') + .filter((name) => name.includes('.html') && name !== 'all.html'); + +// Read the table of contents. +const toc = fs.readFileSync(source + '/_toc.html', 'utf8'); + +// Extract (and concatenate) the toc and apicontent from each document. +let contents = ''; +let apicontent = ''; + +// Identify files that should be skipped. As files are processed, they +// are added to this list to prevent dupes. +const seen = { + 'all.html': true, + 'index.html': true +}; + +for (const link of toc.match(//g)) { + const href = /href="(.*?)"/.exec(link)[1]; + if (!htmlFiles.includes(href) || seen[href]) continue; + const data = fs.readFileSync(source + '/' + href, 'utf8'); + + // Split the doc. + const match = /(<\/ul>\s*)?<\/div>\s*
/.exec(data); + + contents += data.slice(0, match.index) + .replace(/[\s\S]*?