Skip to content

Commit

Permalink
doc: build partial html content as well as full-baked pages
Browse files Browse the repository at this point in the history
The better to docs.npmjs.com for great good
  • Loading branch information
isaacs committed Sep 30, 2014
1 parent f044e9a commit 8b58ad0
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 69 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) \
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
69 changes: 42 additions & 27 deletions scripts/doc-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b58ad0

Please sign in to comment.