Skip to content
Open
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
6 changes: 6 additions & 0 deletions bin/commands/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export default new Command('generate')
.addOption(new Option('-c, --changelog <url>', 'Changelog URL or path'))
.addOption(new Option('--git-ref', 'Git ref URL'))
.addOption(new Option('--index <url>', 'index.md URL or path'))
.addOption(
new Option(
'--index-redirect-url <url>',
'URL to redirect index.html to (legacy-html generator)'
)
)
.addOption(new Option('--minify', 'Minify?'))
.addOption(new Option('--type-map <url>', 'Type map URL or path'))

Expand Down
1 change: 1 addition & 0 deletions src/generators/legacy-html/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default createLazyGenerator({
ref: 'main',
pageURL: '{baseURL}/latest-{version}/api{path}.html',
editURL: `${GITHUB_EDIT_URL}/doc/api{path}.md`,
indexRedirectURL: '',
},

hasParallelProcessor: true,
Expand Down
3 changes: 2 additions & 1 deletion src/generators/legacy-html/template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!doctype html>
<html lang="en">
<head>
__REDIRECT__
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" href="https://nodejs.org/favicon.ico" />
Expand All @@ -25,7 +26,7 @@
<div id="content" class="clearfix">
<div role="navigation" id="column2" class="interior">
<div id="intro" class="interior">
<a href="/" title="Go back to the home page"> Node.js </a>
<a href="__HOME_LINK__" title="Go back to the home page"> Node.js </a>
</div>
<hr class="line" />
__GTOC__
Expand Down
25 changes: 24 additions & 1 deletion src/generators/legacy-html/utils/replaceTemplateValues.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,38 @@ export const replaceTemplateValues = (
config,
{ skipGitHub = false, skipGtocPicker = false } = {}
) => {
const redirectMeta =
api === 'index' && config.indexRedirectURL
? `<script>
(function() {
let p = window.location.pathname;
let targetUrl = ${JSON.stringify(config.indexRedirectURL)};

const isAbsolute = targetUrl.startsWith('http://') || targetUrl.startsWith('https://') || targetUrl.startsWith('/');

if (!isAbsolute && !p.endsWith('/') && !p.split('/').pop().includes('.') && !p.endsWith('/index')) {
targetUrl = p + '/' + targetUrl;
}
Comment thread
cursor[bot] marked this conversation as resolved.

window.location.replace(targetUrl);
})();
</script>`
: '';

return apiTemplate
.replace('__REDIRECT__', redirectMeta)
.replace('__HOME_LINK__', config.indexRedirectURL || '/')
.replace('__ID__', api)
.replace(/__FILENAME__/g, api)
.replace('__SECTION__', section)
.replace(/__VERSION__/g, `v${config.version.version}`)
.replace(/__TOC__/g, tableOfContents.wrapToC(toc))
.replace(/__GTOC__/g, nav)
.replace('__CONTENT__', content)
.replace(/__TOC_PICKER__/g, buildToC(toc))
.replace(
/__TOC_PICKER__/g,
config.indexRedirectURL && api === 'index' ? '' : buildToC(toc)
)
.replace(/__GTOC_PICKER__/g, skipGtocPicker ? '' : buildNavigation(nav))
.replace('__ALTDOCS__', buildVersions(path, added, config.changelog))
.replace(
Expand Down
5 changes: 5 additions & 0 deletions src/utils/configuration/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export const createConfigFromCLIOptions = options => ({
target: options.target,
threads: options.threads,
chunkSize: options.chunkSize,
...(options.indexRedirectUrl && {
'legacy-html': {
indexRedirectURL: options.indexRedirectUrl,
},
}),
});

/**
Expand Down