diff options
author | isaacs <i@izs.me> | 2014-09-30 04:39:28 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-09-30 04:39:28 +0400 |
commit | 8b58ad09b719295461167a34f666c5aa4d6e26f2 (patch) | |
tree | cc020774801cacd9009ccffd2ad41d4c465f9109 | |
parent | f044e9a207c203f335953c1e4c94d74de4c8bfdf (diff) |
doc: build partial html content as well as full-baked pages
The better to docs.npmjs.com for great good
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 84 | ||||
-rwxr-xr-x | scripts/doc-build.sh | 69 |
3 files changed, 112 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore index 234afda9c..137a452bf 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ npm-debug.log /node_modules/marked /node_modules/require-inject /html/api/ +/html/partial/ /html/doc/ /man/ /doc/*/npm-index.md @@ -31,6 +31,28 @@ misc_mandocs = $(shell find doc/misc -name '*.md' \ |sed 's|doc/misc/|man/man7/|g' ) \ man/man7/npm-index.7 + +cli_partdocs = $(shell find doc/cli -name '*.md' \ + |sed 's|.md|.html|g' \ + |sed 's|doc/cli/|html/partial/doc/cli/|g' ) \ + html/partial/doc/README.html + +api_partdocs = $(shell find doc/api -name '*.md' \ + |sed 's|.md|.html|g' \ + |sed 's|doc/api/|html/partial/doc/api/|g' ) + +files_partdocs = $(shell find doc/files -name '*.md' \ + |sed 's|.md|.html|g' \ + |sed 's|doc/files/|html/partial/doc/files/|g' ) \ + html/partial/doc/files/npm-json.html \ + html/partial/doc/files/npm-global.html + +misc_partdocs = $(shell find doc/misc -name '*.md' \ + |sed 's|.md|.html|g' \ + |sed 's|doc/misc/|html/partial/doc/misc/|g' ) \ + html/partial/doc/index.html + + cli_htmldocs = $(shell find doc/cli -name '*.md' \ |sed 's|.md|.html|g' \ |sed 's|doc/cli/|html/doc/cli/|g' ) \ @@ -53,6 +75,8 @@ misc_htmldocs = $(shell find doc/misc -name '*.md' \ mandocs = $(api_mandocs) $(cli_mandocs) $(files_mandocs) $(misc_mandocs) +partdocs = $(api_partdocs) $(cli_partdocs) $(files_partdocs) $(misc_partdocs) + htmldocs = $(api_htmldocs) $(cli_htmldocs) $(files_htmldocs) $(misc_htmldocs) all: doc @@ -79,7 +103,7 @@ clean: markedclean marked-manclean doc-clean uninstall uninstall: node cli.js rm npm -g -f -doc: $(mandocs) $(htmldocs) +doc: $(mandocs) $(htmldocs) $(partdocs) markedclean: rm -rf node_modules/marked node_modules/.bin/marked .building_marked @@ -119,43 +143,73 @@ man/man5/%.5: doc/files/%.md scripts/doc-build.sh package.json @[ -d man/man5 ] || mkdir -p man/man5 scripts/doc-build.sh $< $@ +man/man7/%.7: doc/misc/%.md scripts/doc-build.sh package.json + @[ -d man/man7 ] || mkdir -p man/man7 + scripts/doc-build.sh $< $@ + + doc/misc/npm-index.md: scripts/index-build.js package.json node scripts/index-build.js > $@ -html/doc/index.html: doc/misc/npm-index.md $(html_docdeps) - @[ -d html/doc ] || mkdir -p html/doc - scripts/doc-build.sh $< $@ -man/man7/%.7: doc/misc/%.md scripts/doc-build.sh package.json - @[ -d man/man7 ] || mkdir -p man/man7 +# html/doc depends on html/partial/doc +html/doc/%.html: html/partial/doc/%.html + @[ -d html/doc ] || mkdir -p html/doc scripts/doc-build.sh $< $@ -html/doc/README.html: README.md $(html_docdeps) +html/doc/README.html: html/partial/doc/README.html @[ -d html/doc ] || mkdir -p html/doc scripts/doc-build.sh $< $@ -html/doc/cli/%.html: doc/cli/%.md $(html_docdeps) +html/doc/cli/%.html: html/partial/doc/cli/%.html @[ -d html/doc/cli ] || mkdir -p html/doc/cli scripts/doc-build.sh $< $@ -html/doc/api/%.html: doc/api/%.md $(html_docdeps) +html/doc/misc/%.html: html/partial/doc/misc/%.html + @[ -d html/doc/misc ] || mkdir -p html/doc/misc + scripts/doc-build.sh $< $@ + +html/doc/files/%.html: html/partial/doc/files/%.html + @[ -d html/doc/files ] || mkdir -p html/doc/files + scripts/doc-build.sh $< $@ + +html/doc/api/%.html: html/partial/doc/api/%.html @[ -d html/doc/api ] || mkdir -p html/doc/api scripts/doc-build.sh $< $@ -html/doc/files/npm-json.html: html/doc/files/package.json.html + +html/partial/doc/index.html: doc/misc/npm-index.md $(html_docdeps) + @[ -d html/partial/doc ] || mkdir -p html/partial/doc + scripts/doc-build.sh $< $@ + +html/partial/doc/README.html: README.md $(html_docdeps) + @[ -d html/partial/doc ] || mkdir -p html/partial/doc + scripts/doc-build.sh $< $@ + +html/partial/doc/cli/%.html: doc/cli/%.md $(html_docdeps) + @[ -d html/partial/doc/cli ] || mkdir -p html/partial/doc/cli + scripts/doc-build.sh $< $@ + +html/partial/doc/api/%.html: doc/api/%.md $(html_docdeps) + @[ -d html/partial/doc/api ] || mkdir -p html/partial/doc/api + scripts/doc-build.sh $< $@ + +html/partial/doc/files/npm-json.html: html/partial/doc/files/package.json.html cp $< $@ -html/doc/files/npm-global.html: html/doc/files/npm-folders.html +html/partial/doc/files/npm-global.html: html/partial/doc/files/npm-folders.html cp $< $@ -html/doc/files/%.html: doc/files/%.md $(html_docdeps) - @[ -d html/doc/files ] || mkdir -p html/doc/files +html/partial/doc/files/%.html: doc/files/%.md $(html_docdeps) + @[ -d html/partial/doc/files ] || mkdir -p html/partial/doc/files scripts/doc-build.sh $< $@ -html/doc/misc/%.html: doc/misc/%.md $(html_docdeps) - @[ -d html/doc/misc ] || mkdir -p html/doc/misc +html/partial/doc/misc/%.html: doc/misc/%.md $(html_docdeps) + @[ -d html/partial/doc/misc ] || mkdir -p html/partial/doc/misc scripts/doc-build.sh $< $@ + + marked: node_modules/.bin/marked node_modules/.bin/marked: 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 |