Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: build doc/api/all.html by combining generated HTML #21544

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,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
$(call available-node, $(gen-json))

out/doc/api/%.html: doc/api/%.md
out/doc/api/%.html: doc/api/%.md tools/doc/generate.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
Expand Down
61 changes: 61 additions & 0 deletions tools/doc/allhtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

// Build all.html by combining the generated toc and apicontent from each
// of the generated html files.

const fs = require('fs');
const { JSDOM } = require('jsdom');

const source = `${__dirname}/../../out/doc/api`;

const html_files = fs.readdirSync(source, 'utf8')
.filter((name) => name.includes('.html') && name !== 'all.html');

const all = {};
for (const file of html_files) {
all[file] = new JSDOM(fs.readFileSync(source + '/' + file, 'utf8'))
.window.document;
}

const doc = all['_toc.html'].documentElement;
const list = Array.from(doc.querySelectorAll('#column2 ul li a'))
.map((node) => node.getAttribute('href'));

const canonical = doc.querySelector('link[rel=canonical]');
canonical.setAttribute('href',
canonical.getAttribute('href').replace('_toc', 'all'));

const versionPickerLinks = doc.querySelectorAll('ol.version-picker a');
versionPickerLinks.forEach((versionPicker) => {
versionPicker.setAttribute(
'href',
versionPicker.getAttribute('href').replace('_toc', 'all')
);
});

doc.querySelector('body').setAttribute('id', 'api-section-all');

const owner = doc.ownerDocument;
const toc = doc.querySelector('#toc');
const ul = owner.createElement('ul');
toc.appendChild(ul);
const api = doc.querySelector('#apicontent');
while (api.firstChild) api.firstChild.remove();

const title = doc.querySelector('title');
title.textContent = title.textContent.replace(/.* \| /, '');
doc.querySelector('#column1').setAttribute('data-id', 'all');
doc.querySelector('a[href="_toc.json"]').setAttribute('href', 'all.json');

for (const file of list) {
if (!all[file]) continue;

let source = all[file].querySelector('#toc ul');
while (source.firstChild) ul.appendChild(owner.adoptNode(source.firstChild));

source = all[file].querySelector('#apicontent');
while (source.firstChild) api.appendChild(owner.adoptNode(source.firstChild));
}

const output = `<!doctype html>\n${doc.outerHTML}`;
fs.writeFileSync(source + '/all.html', output, 'utf8');
1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/escodegen

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/esgenerate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/sshpk-conv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/sshpk-sign

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/sshpk-verify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/doc/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tools/doc/node_modules/abab/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions tools/doc/node_modules/abab/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tools/doc/node_modules/abab/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions tools/doc/node_modules/abab/lib/atob.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions tools/doc/node_modules/abab/lib/btoa.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading