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

doc: Move @VERSION@ for html docs into gatsby #283

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Expand Up @@ -52,8 +52,6 @@ htmldocs:
cd docs && node ../bin/npm-cli.js install && \
node ../bin/npm-cli.js run build:static echo>&2 && \
rm -rf node_modules .cache public/*js public/*json public/404* public/page-data public/manifest*
find docs/public -name '*.html' -exec \
node scripts/docs-build.js {} \;

docs: mandocs htmldocs

Expand Down Expand Up @@ -92,7 +90,7 @@ man/man1/npx.1: node_modules/libnpx/libnpx.1
man/man5/npm-json.5: man/man5/package.json.5
cp $< $@

man/man5/npm-global.5: man/man5/foslders.5
man/man5/npm-global.5: man/man5/folders.5
cp $< $@

man/man5/%.5: docs/content/configuring-npm/%.md scripts/docs-build.js package.json $(build-doc-tools)
Expand Down
5 changes: 4 additions & 1 deletion docs/src/templates/Page.js
Expand Up @@ -5,6 +5,7 @@ import styled, { ThemeProvider } from 'styled-components'
import {theme} from 'src/theme'
import FoundTypo from 'src/components/FoundTypo'
import Scripts from 'src/components/Scripts'
const version = require('../../../package.json').version

const Content = styled.div`
max-width: 760px;
Expand All @@ -20,7 +21,9 @@ const Page = ({data}) => {
<ThemeProvider theme={theme}>
<Layout showSidebar>
<Content className='documentation'>
<div dangerouslySetInnerHTML={{ __html: html }} />
<div dangerouslySetInnerHTML={{
__html: html.replace(/@VERSION@/g, version)
}} />
<FoundTypo />
<Scripts />
</Content>
Expand Down
23 changes: 9 additions & 14 deletions scripts/docs-build.js
Expand Up @@ -10,22 +10,17 @@ var dest = args[1] || src
fs.readFile(src, 'utf8', function (err, data) {
if (err) return console.log(err)

var fileExt = src.split('.').pop()
var result = data.replace(/@VERSION@/g, npm.version)
.replace(/---([\s\S]+)---/g, '')
.replace(/(npm-)?([a-zA-Z\\.-]*)\(1\)/g, 'npm help $2')
.replace(/(npm-)?([a-zA-Z\\.-]*)\((5|7)\)/g, 'npm help $2')
.replace(/npm(1)/g, 'npm help npm')
.replace(/\[([^\]]+)\]\(\/cli-commands\/([^)]+)\)/g, 'npm help $2')
.replace(/\[([^\]]+)\]\(\/configuring-npm\/([^)]+)\)/g, 'npm help $2')
.replace(/\[([^\]]+)\]\(\/using-npm\/([^)]+)\)/g, 'npm help $2')
.trim()

if (fileExt === 'md') {
result = marked(
result.replace(/---([\s\S]+)---/g, '')
.replace(/(npm-)?([a-zA-Z\\.-]*)\(1\)/g, 'npm help $2')
.replace(/(npm-)?([a-zA-Z\\.-]*)\((5|7)\)/g, 'npm help $2')
.replace(/(npm-)?([a-zA-Z\\.-]*)\(3\)/g, 'npm apihelp $2')
.replace(/npm(1)/g, 'npm help npm')
.replace(/npm(3)/g, 'npm apihelp npm')
.trim()
)
}

fs.writeFile(dest, result, 'utf8', function (err) {
fs.writeFile(dest, marked(result), 'utf8', function (err) {
if (err) return console.log(err)
})
})