Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-09-30 04:39:28 +0400
committerisaacs <i@izs.me>2014-09-30 04:39:28 +0400
commit8b58ad09b719295461167a34f666c5aa4d6e26f2 (patch)
treecc020774801cacd9009ccffd2ad41d4c465f9109 /scripts
parentf044e9a207c203f335953c1e4c94d74de4c8bfdf (diff)
doc: build partial html content as well as full-baked pages
The better to docs.npmjs.com for great good
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/doc-build.sh69
1 files changed, 42 insertions, 27 deletions
diff --git a/scripts/doc-build.sh b/scripts/doc-build.sh
index 3728259ac..e4fc035cf 100755
--- a/scripts/doc-build.sh
+++ b/scripts/doc-build.sh
@@ -66,44 +66,59 @@ version=$(node cli.js -v)
mkdir -p $(dirname $dest)
+html_replace_tokens () {
+ local url=$1
+ sed "s|@NAME@|$name|g" \
+ | sed "s|@DATE@|$date|g" \
+ | sed "s|@URL@|$url|g" \
+ | sed "s|@VERSION@|$version|g" \
+ | perl -pi -e 's/<h1([^>]*)>([^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>\2<\/h1> <p>\3<\/p>/g' \
+ | perl -pi -e 's/npm-npm/npm/g' \
+ | perl -pi -e 's/([^"-])(npm-)?README(?!\.html)(\(1\))?/\1<a href="..\/..\/doc\/README.html">README<\/a>/g' \
+ | perl -pi -e 's/<title><a href="[^"]+README.html">README<\/a><\/title>/<title>README<\/title>/g' \
+ | perl -pi -e 's/([^"-])([^\(> ]+)(\(1\))/\1<a href="..\/cli\/\2.html">\2\3<\/a>/g' \
+ | perl -pi -e 's/([^"-])([^\(> ]+)(\(3\))/\1<a href="..\/api\/\2.html">\2\3<\/a>/g' \
+ | perl -pi -e 's/([^"-])([^\(> ]+)(\(5\))/\1<a href="..\/files\/\2.html">\2\3<\/a>/g' \
+ | perl -pi -e 's/([^"-])([^\(> ]+)(\(7\))/\1<a href="..\/misc\/\2.html">\2\3<\/a>/g' \
+ | perl -pi -e 's/\([1357]\)<\/a><\/h1>/<\/a><\/h1>/g' \
+ | (if [ $(basename $(dirname $dest)) == "doc" ]; then
+ perl -pi -e 's/ href="\.\.\// href="/g'
+ else
+ cat
+ fi)
+}
+
+man_replace_tokens () {
+ sed "s|@VERSION@|$version|g" \
+ | perl -pi -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(1\)/npm help \2/g' \
+ | perl -pi -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(([57])\)/npm help \3 \2/g' \
+ | perl -pi -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(3\)/npm apihelp \2/g' \
+ | perl -pi -e 's/npm\(1\)/npm help npm/g' \
+ | perl -pi -e 's/npm\(3\)/npm apihelp npm/g'
+}
+
case $dest in
*.[1357])
./node_modules/.bin/marked-man --roff $src \
- | sed "s|@VERSION@|$version|g" \
- | perl -pi -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(1\)/npm help \2/g' \
- | perl -pi -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(([57])\)/npm help \3 \2/g' \
- | perl -pi -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(3\)/npm apihelp \2/g' \
- | perl -pi -e 's/npm\(1\)/npm help npm/g' \
- | perl -pi -e 's/npm\(3\)/npm apihelp npm/g' \
- > $dest
+ | man_replace_tokens > $dest
exit $?
;;
- *.html)
+
+ html/partial/*.html)
+ url=${dest/html\/partial\//}
+ cat $src | ./node_modules/.bin/marked | html_replace_tokens $url > $dest
+ ;;
+
+ html/*.html)
url=${dest/html\//}
(cat html/dochead.html && \
- cat $src | ./node_modules/.bin/marked &&
+ cat $src && \
cat html/docfoot.html)\
- | sed "s|@NAME@|$name|g" \
- | sed "s|@DATE@|$date|g" \
- | sed "s|@URL@|$url|g" \
- | sed "s|@VERSION@|$version|g" \
- | perl -pi -e 's/<h1([^>]*)>([^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>\2<\/h1> <p>\3<\/p>/g' \
- | perl -pi -e 's/npm-npm/npm/g' \
- | perl -pi -e 's/([^"-])(npm-)?README(?!\.html)(\(1\))?/\1<a href="..\/..\/doc\/README.html">README<\/a>/g' \
- | perl -pi -e 's/<title><a href="[^"]+README.html">README<\/a><\/title>/<title>README<\/title>/g' \
- | perl -pi -e 's/([^"-])([^\(> ]+)(\(1\))/\1<a href="..\/cli\/\2.html">\2\3<\/a>/g' \
- | perl -pi -e 's/([^"-])([^\(> ]+)(\(3\))/\1<a href="..\/api\/\2.html">\2\3<\/a>/g' \
- | perl -pi -e 's/([^"-])([^\(> ]+)(\(5\))/\1<a href="..\/files\/\2.html">\2\3<\/a>/g' \
- | perl -pi -e 's/([^"-])([^\(> ]+)(\(7\))/\1<a href="..\/misc\/\2.html">\2\3<\/a>/g' \
- | perl -pi -e 's/\([1357]\)<\/a><\/h1>/<\/a><\/h1>/g' \
- | (if [ $(basename $(dirname $dest)) == "doc" ]; then
- perl -pi -e 's/ href="\.\.\// href="/g'
- else
- cat
- fi) \
+ | html_replace_tokens $url \
> $dest
exit $?
;;
+
*)
echo "Invalid destination type: $dest" >&2
exit 1