doc,tools: get altDocs versions from CHANGELOG.md by richardlau · Pull Request #27661 · nodejs/node · GitHub
Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions test/internet/test-doctool-versions.js
21 changes: 5 additions & 16 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

const common = require('./common.js');
const fs = require('fs');
const getVersions = require('./versions.js');
const unified = require('unified');
const find = require('unist-util-find');
const visit = require('unist-util-visit');
Expand Down Expand Up @@ -62,7 +63,7 @@ const gtocHTML = unified()
const templatePath = path.join(docPath, 'template.html');
const template = fs.readFileSync(templatePath, 'utf8');

function toHTML({ input, content, filename, nodeVersion }, cb) {
async function toHTML({ input, content, filename, nodeVersion }, cb) {
filename = path.basename(filename, '.md');

const id = filename.replace(/\W+/g, '-');
Expand All @@ -80,7 +81,7 @@ function toHTML({ input, content, filename, nodeVersion }, cb) {
const docCreated = input.match(
/<!--\s*introduced_in\s*=\s*v([0-9]+)\.([0-9]+)\.[0-9]+\s*-->/);
if (docCreated) {
HTML = HTML.replace('__ALTDOCS__', altDocs(filename, docCreated));
HTML = HTML.replace('__ALTDOCS__', await altDocs(filename, docCreated));
} else {
console.error(`Failed to add alternative version links to ${filename}`);
HTML = HTML.replace('__ALTDOCS__', '');
Expand Down Expand Up @@ -390,22 +391,10 @@ function getId(text, idCounters) {
return text;
}

function altDocs(filename, docCreated) {
async function altDocs(filename, docCreated) {
const [, docCreatedMajor, docCreatedMinor] = docCreated.map(Number);
const host = 'https://nodejs.org';
const versions = [
{ num: '12.x' },
{ num: '11.x' },
{ num: '10.x', lts: true },
{ num: '9.x' },
{ num: '8.x', lts: true },
{ num: '7.x' },
{ num: '6.x' },
{ num: '5.x' },
{ num: '4.x' },
{ num: '0.12.x' },
{ num: '0.10.x' },
];
const versions = await getVersions.versions();

const getHref = (versionNum) =>
`${host}/docs/latest-v${versionNum}/api/${filename}.html`;
Expand Down
45 changes: 45 additions & 0 deletions tools/doc/versions.js