Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
doc: Build index and readme html properly
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 11, 2013
1 parent e600886 commit fb35715
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
30 changes: 22 additions & 8 deletions Makefile
Expand Up @@ -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' ) \
Expand All @@ -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' \
Expand All @@ -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)

Expand Down Expand Up @@ -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 $< $@

Expand All @@ -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 $< $@

Expand Down
11 changes: 8 additions & 3 deletions scripts/doc-build.sh
Expand Up @@ -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 $?
;;
*)
Expand Down
10 changes: 5 additions & 5 deletions scripts/index-build.js
Expand Up @@ -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))]
Expand All @@ -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]
}))
Expand All @@ -36,22 +34,24 @@ 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")
writeLines(files, 7, "Misc")
}

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)
}


function writeLine (sd) {
var sxn = sd[0]
var sxn = sd[0] || 1
, doc = sd[1]
, d = path.basename(doc, ".md")

Expand Down

0 comments on commit fb35715

Please sign in to comment.