Skip to content

Commit

Permalink
docs: add npm version to every local help output (#7479)
Browse files Browse the repository at this point in the history
Every page of npm help <x> display the local npm version.

This pull request helps the local reader of the documentation to know
which version of the documentation they are reading.

## References
Closes: #7110
  • Loading branch information
klm-turing committed May 7, 2024
1 parent 722c0fa commit 268303c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const replaceHelpLinks = (src) => {

const transformMan = (src, { data, unified, remarkParse, remarkMan }) => unified()
.use(remarkParse)
.use(remarkMan)
.use(remarkMan, { version: `NPM@${version}` })
.processSync(`# ${data.title}(${data.section}) - ${data.description}\n\n${src}`)
.toString()

Expand Down
10 changes: 9 additions & 1 deletion docs/lib/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
line-height: 1;
}

header.title .version {
font-size: 0.8em;
color: #666666;
}

footer#edit {
border-top: solid 1px #e1e4e8;
margin: 3em 0 4em 0;
Expand All @@ -138,7 +143,10 @@

<section id="content">
<header class="title">
<h1>{{ title }}</h1>
<h1>
<span>{{ title }}</span>
<span class="version">@{{ version }}</span>
</h1>
<span class="description">{{ description }}</span>
</header>

Expand Down
4 changes: 4 additions & 0 deletions docs/lib/transform-html.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const jsdom = require('jsdom')
const { version } = require('../../package.json')

function transformHTML (
src,
Expand Down Expand Up @@ -36,6 +37,9 @@ function transformHTML (
case 'config.github_path':
return data[key.replace(/^config\./, '')]

case 'version':
return version

default:
throw new Error(`warning: unknown token '${token}' in ${path}`)
}
Expand Down

0 comments on commit 268303c

Please sign in to comment.