#!/bin/sh set -e export LC_ALL=C SECTIONS="1 2 3 4 5 6 7 8 9" if [ -z ${SORTIX_SITE_OFFICIAL+x} ]; then SORTIX_SITE_OFFICIAL="https://sortix.org/" fi if [ -z ${SORTIX_RELEASE_SITE+x} ]; then SORTIX_RELEASE_SITE="https://pub.sortix.org/sortix/release" fi if [ -z ${MANHTML_TO_SITE_ROOT+x} ]; then MANHTML_TO_SITE_ROOT=. fi if [ -z ${MANHTML_TEMPLATE+x} ]; then MANHTML_TEMPLATE="$(dirname -- "$(realpath -- "$(which -- "$0")")")" fi if [ -z ${MANHTML_RELEASES+x} ]; then MANHTML_RELEASES="current nightly" 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 [ $# -lt 1 ]; then echo "Usage: $0 mandir $#" >&2 exit 1 fi if [ ! -e "$1/ports.list" ]; then echo "$0: No ports.list in $1" >&2 exit 1 fi cd "$1" backwards() { echo "$1" | tr -cd / | sed 's,/,../,g' } tositeofficial() { BACKWARDS=$(backwards "$1") case "$SORTIX_SITE_OFFICIAL" in http*) echo "$SORTIX_SITE_OFFICIAL" ;; *) echo "$BACKWARDS$SORTIX_SITE_OFFICIAL" ;; esac } tositeroot() { echo "$(backwards "$1")$MANHTML_TO_SITE_ROOT" } frontpage() { tositeofficial "$1" | sed 's/^$/./g' } begin_html() { cat "$MANHTML_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 manhtml 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 manhtml $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 "Generating undocumented manhtml for $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 -F -- "../$manpage.html" . | grep -E '\.html$' | undocumented_see_also) | mandoc -Thtml -Oman=../man%S/%N.%S.html | selflink end_html) | finalize_html "$manpage.html" fi done echo "Generating manhtml 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