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>2013-07-12 01:33:58 +0400
committerisaacs <i@izs.me>2013-07-12 01:33:58 +0400
commitfb3571543839cae0fcd2ffd53e8a9136da87fd3e (patch)
treea7b0908bd473bd4448f9881b3690e0bd42a62452
parente600886532351c18852a9fe5a1386fffb773ba8d (diff)
doc: Build index and readme html properly
-rw-r--r--Makefile30
-rwxr-xr-xscripts/doc-build.sh11
-rwxr-xr-xscripts/index-build.js10
3 files changed, 35 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 094e391e1..046b7063a 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,12 @@ SHELL = bash
markdowns = $(shell find doc -name '*.md' | grep -v 'index') README.md
+html_docdeps = html/dochead.html \
+ html/docfoot.html \
+ html/docfoot-script.html \
+ scripts/doc-build.sh \
+ package.json
+
cli_mandocs = $(shell find doc/cli -name '*.md' \
|sed 's|.md|.1|g' \
|sed 's|doc/cli/|man/man1/|g' ) \
@@ -19,8 +25,8 @@ files_mandocs = $(shell find doc/files -name '*.md' \
misc_mandocs = $(shell find doc/misc -name '*.md' \
|sed 's|.md|.7|g' \
- |sed 's|doc/misc/|man/man7/|g' )
-
+ |sed 's|doc/misc/|man/man7/|g' ) \
+ man/man7/index.7
cli_htmldocs = $(shell find doc/cli -name '*.md' \
|sed 's|.md|.html|g' \
@@ -39,7 +45,8 @@ files_htmldocs = $(shell find doc/files -name '*.md' \
misc_htmldocs = $(shell find doc/misc -name '*.md' \
|sed 's|.md|.html|g' \
- |sed 's|doc/misc/|html/doc/misc/|g' )
+ |sed 's|doc/misc/|html/doc/misc/|g' ) \
+ html/doc/index.html
mandocs = $(api_mandocs) $(cli_mandocs) $(files_mandocs) $(misc_mandocs)
@@ -103,19 +110,26 @@ man/man5/%.5: doc/files/%.md scripts/doc-build.sh package.json
@[ -d man/man5 ] || mkdir -p man/man5
scripts/doc-build.sh $< $@
+doc/misc/index.md: scripts/index-build.js package.json
+ node scripts/index-build.js > $@
+
+html/doc/index.html: doc/misc/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
scripts/doc-build.sh $< $@
-html/doc/README.html: README.md html/dochead.html html/docfoot.html scripts/doc-build.sh package.json
+html/doc/README.html: README.md $(html_docdeps)
@[ -d html/doc ] || mkdir -p html/doc
scripts/doc-build.sh $< $@
-html/doc/cli/%.html: doc/cli/%.md html/dochead.html html/docfoot.html scripts/doc-build.sh package.json
+html/doc/cli/%.html: doc/cli/%.md $(html_docdeps)
@[ -d html/doc/cli ] || mkdir -p html/doc/cli
scripts/doc-build.sh $< $@
-html/doc/api/%.html: doc/api/%.md html/dochead.html html/docfoot.html scripts/doc-build.sh package.json
+html/doc/api/%.html: doc/api/%.md $(html_docdeps)
@[ -d html/doc/api ] || mkdir -p html/doc/api
scripts/doc-build.sh $< $@
@@ -124,11 +138,11 @@ html/doc/files/npm-json.html: html/doc/files/package.json.html
html/doc/files/npm-global.html: html/doc/files/npm-folders.html
cp $< $@
-html/doc/files/%.html: doc/files/%.md html/dochead.html html/docfoot.html scripts/doc-build.sh package.json
+html/doc/files/%.html: doc/files/%.md $(html_docdeps)
@[ -d html/doc/files ] || mkdir -p html/doc/files
scripts/doc-build.sh $< $@
-html/doc/misc/%.html: doc/misc/%.md html/dochead.html html/docfoot.html scripts/doc-build.sh package.json
+html/doc/misc/%.html: doc/misc/%.md $(html_docdeps)
@[ -d html/doc/misc ] || mkdir -p html/doc/misc
scripts/doc-build.sh $< $@
diff --git a/scripts/doc-build.sh b/scripts/doc-build.sh
index de4c9d22b..4ca97322e 100755
--- a/scripts/doc-build.sh
+++ b/scripts/doc-build.sh
@@ -61,15 +61,20 @@ case $dest in
| sed "s|@VERSION@|$version|g" \
| perl -pi -e 's/<h1>([^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>\1<\/h1> <p>\2<\/p>/g' \
| perl -pi -e 's/npm-npm/npm/g' \
- | perl -pi -e 's/([^"-])(npm-)?README(\(1\))?/\1<a href="..\/doc\/README.html">README<\/a>/g' \
+ | perl -pi -e 's/([^"-])(npm-)?README(\(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' \
- > $dest
- cat html/docfoot-script.html >> $dest
+ | (if [ $(basename $(dirname $dest)) == "doc" ]; then
+ perl -pi -e 's/ href="\.\.\// href="/g'
+ else
+ cat
+ fi) \
+ > $dest \
+ && cat html/docfoot-script.html >> $dest
exit $?
;;
*)
diff --git a/scripts/index-build.js b/scripts/index-build.js
index 56827fcc7..8031fe727 100755
--- a/scripts/index-build.js
+++ b/scripts/index-build.js
@@ -11,7 +11,7 @@ glob(root + "/{README.md,doc/*/*.md}", function (er, files) {
output(files.map(function (f) {
var b = path.basename(f)
if (b === "README.md")
- return [1, b]
+ return [0, b]
if (b === "index.md")
return null
var s = conversion[path.basename(path.dirname(f))]
@@ -22,8 +22,6 @@ glob(root + "/{README.md,doc/*/*.md}", function (er, files) {
return (a[0] === b[0])
? ( path.basename(a[1]) === "npm.md" ? -1
: path.basename(b[1]) === "npm.md" ? 1
- : path.basename(a[1]) === "README.md" ? -1
- : path.basename(b[1]) === "README.md" ? 1
: a[1] > b[1] ? 1 : -1 )
: a[0] - b[0]
}))
@@ -36,6 +34,7 @@ function output (files) {
"npm-index(7) -- Index of all npm documentation\n" +
"==============================================\n")
+ writeLines(files, 0)
writeLines(files, 1, "Command Line Documentation")
writeLines(files, 3, "API Documentation")
writeLines(files, 5, "Files")
@@ -43,7 +42,8 @@ function output (files) {
}
function writeLines (files, sxn, heading) {
- console.log("# %s\n", heading)
+ if (heading)
+ console.log("# %s\n", heading)
files.filter(function (f) {
return f[0] === sxn
}).forEach(writeLine)
@@ -51,7 +51,7 @@ function writeLines (files, sxn, heading) {
function writeLine (sd) {
- var sxn = sd[0]
+ var sxn = sd[0] || 1
, doc = sd[1]
, d = path.basename(doc, ".md")