#!/bin/sh # TODO: libmanpage.sh and manpages.sh duplicate a lot of logic set -e export LC_ALL=C SECTIONS="1 2 3 4 5 6 7 8 9" RELEASES="current nightly" if [ -z ${URL+x} ]; then URL=https://sortix.org/man/ fi if [ -z ${NIGHTLY_RELEASE_SITE+x} ]; then NIGHTLY_RELEASE_SITE=https://pub.sortix.org/sortix/release fi if [ -z ${SITE+x} ]; then SITE=../ fi if [ -z ${SUBDIR+x} ]; then SUBDIR=man fi if [ -z ${OFFICIAL+x} ]; then OFFICIAL="$SITE" fi if [ -z ${TEMPLATE+x} ]; then TEMPLATE="$SITE" fi if [ -z ${RELEASE+x} ]; then RELEASE="current" fi if [ -z ${RELEASE_STRING+x} ]; then if [ "$RELEASE" = current ]; then RELEASE_STRING="Sortix" else RELEASE_STRING="Sortix $RELEASE" fi fi if [ ! -e "ports.list" ]; then echo "$0: No ports.list in the current directory" >&2 exit 1 fi backwards() { echo "$1" | tr -cd / | sed 's,/,../,g' } tositeofficial() { BACKWARDS=$(backwards "$1") case "$OFFICIAL" in http*) echo "$OFFICIAL" ;; *) echo "$BACKWARDS$OFFICIAL" ;; esac } tositeroot() { echo "$(backwards "$1")$SITE" } frontpage() { tositeofficial "$1" | sed 's/^$/./g' } begin_html() { cat "$TEMPLATE/header.html" | sed "s|@title@|$1|g" } header() { cat << EOF
" } ep() { echo "
" } link() { cat << EOF $2$3$prettyport contains no manual pages.
" fi end_html) | finalize_html $port.html done for section in $SECTIONS; do echo "generating index for section $section" mkdir -p "man$section" (begin_html "Section $section - $(section_name $section)" && header "Section $section - $(section_name $section)" && see_stable "man$section/" ls man$section | sort | grep -E "\.$section$" | while read manpage; do manpage=$(basename -- "$manpage") name=$(echo "$manpage" | sed "s/\.$section$//") link "$manpage.html" "$name($section)" done if ! ls man$section | grep -Eq "\.$section$"; then echo "Section $section contains no manual pages.
" fi end_html) | finalize_html man$section/index.html done for section in $SECTIONS; do find man$section -type f | sort | grep -E "\.$section$" | while read manpage; do filename=$(basename -- "$manpage") name=$(expr "x$filename" : 'x\(.*\)\.[^.]*') echo generating $manpage (begin_html "$name($section)" see_stable "$manpage.html" true mandoc -Thtml -Ofragment,man=../man%S/%N.%S.html "$manpage" | selflink end_html) | finalize_html "$manpage.html" done done (find . -name '*.html' | while read FILE; do grep -Eoh 'href=\"../man[[:digit:]]/[^/]+\.html\"' "$FILE" || true done) | sort -u | grep -Eo 'man[[:digit:]]/[^/]+\.html' | sed 's/\.html$//' | while read manpage; do if ! [ -e "$manpage" ]; then echo undocumented: $manpage filename=$(basename -- "$manpage") name=$(expr "x$filename" : 'x\(.*\)\.[^.]*') NAME=$(echo "$filename" | tr '[:lower:]' '[:upper:]') section=$(expr "x$manpage" : 'x.*\.\([^.]*\)') (begin_html "$name($section)" see_stable "$manpage.html" true (cat man7/undocumented.7 | grep -Ev '^\.Xr man 1$' | sed -e "s/UNDOCUMENTED/$NAME/g" -e "s/undocumented/$name/g" && grep -rl --include='*.html' -- "../$manpage.html" . | undocumented_see_also) | mandoc -Thtml -Oman=../man%S/%N.%S.html | selflink end_html) | finalize_html "$manpage.html" fi done echo "generating index for all" (begin_html "All manual pages for Sortix" header "All manual pages for Sortix" see_stable "all.html" for section in $SECTIONS; do section "Section $section" "$section" bp ls man$section | sort | grep -E "\.$section$" | while read manpage; do name=$(echo "$manpage" | sed "s/\.$section$//") link "man$section/$manpage.html" "$name($section)" done ep done end_html) | finalize_html all.html