From 6dac7db15c99a8409ba34ef0137e4e791c8795bf Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Wed, 27 Jun 2018 14:14:54 -0400 Subject: [PATCH] tools: build doc/api/all.html by combining generated HTML #21544 Combine the toc and api contents from the generated doc/api/*.html files. This ensures that the single page version of the documentation exactly matches the individual pages. Fixes #20100 --- Makefile | 8 +++-- tools/doc/allhtml.js | 73 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tools/doc/allhtml.js 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*