From 268303c3b40551ae558f201841d3d5977769a7c9 Mon Sep 17 00:00:00 2001 From: klm-turing Date: Tue, 7 May 2024 17:12:33 +0000 Subject: [PATCH] docs: add npm version to every local help output (#7479) Every page of npm help 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: https://github.com/npm/cli/issues/7110 --- docs/lib/index.js | 2 +- docs/lib/template.html | 10 +++++++++- docs/lib/transform-html.js | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/lib/index.js b/docs/lib/index.js index 5f8501ead27b8..b88d20cca3558 100644 --- a/docs/lib/index.js +++ b/docs/lib/index.js @@ -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() diff --git a/docs/lib/template.html b/docs/lib/template.html index be3bafd61aa05..622dc327046ee 100644 --- a/docs/lib/template.html +++ b/docs/lib/template.html @@ -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; @@ -138,7 +143,10 @@
-

{{ title }}

+

+ {{ title }} + @{{ version }} +

{{ description }}
diff --git a/docs/lib/transform-html.js b/docs/lib/transform-html.js index c587d75e994f8..dc3dd4930d05d 100644 --- a/docs/lib/transform-html.js +++ b/docs/lib/transform-html.js @@ -1,4 +1,5 @@ const jsdom = require('jsdom') +const { version } = require('../../package.json') function transformHTML ( src, @@ -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}`) }