From 044d3dfabb5ddb19e6fbb1e2f7bd0bb187d3b6e1 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Tue, 2 Jan 2024 23:29:48 -0800 Subject: [PATCH] checkpoint further development of tmp/readme2index.sh The `tmp/readme2index.sh` tool now processes all the HTML phases, except 20, 21, and 22. Added missing -N early exits to various inc/*.sh tools. Released VERSION "1.0 2024-01-02" of `inc/subst.default.sh`. Renamed `inc/subst.readme.sh` to `inc/subst.winner-index.sh`. Released VERSION "1.0 2024-01-02" of `inc/subst.winner-index.sh`. Added `inc/topnav.first.html` and `inc/topnav.last.html` to handle the 1st and last winners of a given year. Added various fixes to `tmp/readme2index.sh`. Improved debugging statements from `tmp/readme2index.sh`. TODO: Add code to process HTML phases 20, 21, and 22. TODO: Modify `inc/subst.winner-index.sh` to handle topnav links. TODO: Add inventory links in some form to `index.html`. TODO: Figure out how to best generate `inventory.html'. --- inc/gen-author.sh | 22 +- inc/md2html.cfg | 4 +- inc/subst.default.sh | 309 +++++++++++++++++- inc/subst.readme.sh | 5 - inc/subst.winner-index.sh | 317 ++++++++++++++++++ inc/topnav.first.html | 9 + inc/topnav.last.html | 9 + tmp/readme2index.sh | 663 ++++++++++++++++++++++++++++++++++++-- 8 files changed, 1298 insertions(+), 40 deletions(-) delete mode 100755 inc/subst.readme.sh create mode 100755 inc/subst.winner-index.sh create mode 100644 inc/topnav.first.html create mode 100644 inc/topnav.last.html diff --git a/inc/gen-author.sh b/inc/gen-author.sh index 97294e8d6..0c73db8c4 100755 --- a/inc/gen-author.sh +++ b/inc/gen-author.sh @@ -2,9 +2,9 @@ # # gen-author.sh - output winning author(s) related HTML # -# This tool is intended to be used as a 'before tool' during HTML phase number 20. +# This tool is intended to be used as a "before tool" during HTML phase number 20. # -# This tool is intended to be invoked by a tool such as 'readme2index.sh" +# This tool is intended to be invoked by a tool such as "readme2index.sh" # and as such, the leading options will include "-p pandoc_wrapper" and -P "optstr", # the final arg will be in yyyy/dir form, and will be called from # the topdir directory under which the yyyy/dir winner directory must be found. @@ -553,15 +553,6 @@ if [[ $V_FLAG -ge 3 ]]; then echo "$0: debug[3]: NOOP=$NOOP" 1>&2 fi -# If -N, time to exit -# -if [[ -n $DO_NOT_PROCESS ]]; then - if [[ $V_FLAG -ge 1 ]]; then - echo "$0: debug[1]: arguments parsed, -N given, exit 0" 1>&2 - fi - exit 0 -fi - # Set AUTHOR_HANDLE_SET with author handles from .winner.json # export AUTHOR_HANDLE_SET @@ -640,6 +631,15 @@ for author_handle in $AUTHOR_HANDLE_SET; do fi done +# If -N, time to exit +# +if [[ -n $DO_NOT_PROCESS ]]; then + if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: arguments parsed, -N given, exit 0" 1>&2 + fi + exit 0 +fi + # create a temporary markdown for pandoc to process # TMP_FILE=".$NAME.$$.md" diff --git a/inc/md2html.cfg b/inc/md2html.cfg index 9fb36184b..f10c3c577 100644 --- a/inc/md2html.cfg +++ b/inc/md2html.cfg @@ -283,8 +283,8 @@ mock/*/inventory.md -H topnav=up2index -o inc/subst.default.sh # Unless matched above, default process all winner README.md files -[12][0-9][0-9][0-9]/*/README.md -o inc/subst.default.sh -o inc/subst.readme.sh -b inc/gen-author.sh -mock/*/README.md -o inc/subst.default.sh -o inc/subst.readme.sh -b inc/gen-author.sh +[12][0-9][0-9][0-9]/*/README.md -o inc/subst.default.sh -o inc/subst.winner-index.sh -b inc/gen-author.sh +mock/*/README.md -o inc/subst.default.sh -o inc/subst.winner-index.sh -b inc/gen-author.sh # Exit 9 for any markdown file that we have not previously configured diff --git a/inc/subst.default.sh b/inc/subst.default.sh index d4f7b0a0e..e1c6fe81a 100755 --- a/inc/subst.default.sh +++ b/inc/subst.default.sh @@ -1,5 +1,310 @@ #!/usr/bin/env bash # -# subst.default.sh - stub for an actual subst tool -printf "%s\n" "-s subst_default_token=subst_default_value" +# subst.default.sh - print default substitutions +# +# This tool is used in conjunction with the inc/md2html.cfg configuration +# file, and the tools that use that use that configuration file +# such as "readme2index.sh". +# +# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved. +# +# Permission to use, copy, modify, and distribute this software and +# its documentation for any purpose and without fee is hereby granted, +# provided that the above copyright, this permission notice and text +# this comment, and the disclaimer below appear in all of the following: +# +# supporting documentation +# source copies +# source works derived from this source +# binaries derived from this source or from derived source +# +# LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +# EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# chongo (Landon Curt Noll, http://www.isthe.com/chongo/index.html) /\oo/\ +# +# Share and enjoy! :-) + +# firewall - must be bash with a version 4.2 or later +# +# We must declare arrays with -ag or -Ag +# +if [[ -z ${BASH_VERSINFO[0]} || ${BASH_VERSINFO[0]} -lt 4 || ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 2 ]]; then + echo "$0: ERROR: bash version must be >= 4.2: $BASH_VERSION" 1>&2 + exit 4 +fi + +# setup bash file matching +# +# Requires bash with a version 4.2 or later +# +shopt -s nullglob # enable expanded to nothing rather than remaining unexpanded +shopt -u failglob # disable error message if no matches are found +shopt -u dotglob # disable matching files starting with . +shopt -s globskipdots # enable never matching . nor .. +shopt -u nocaseglob # disable strict case matching +shopt -u extglob # enable extended globbing patterns +shopt -s globstar # enable ** to match all files and zero or more directories and subdirectories + +# set variables referenced in the usage message +# +export VERSION="1.0 2024-01-02" +NAME=$(basename "$0") +export NAME +export V_FLAG=0 +GIT_TOOL=$(type -P git) +export GIT_TOOL +if [[ -z "$GIT_TOOL" ]]; then + echo "$0: FATAL: git tool is not installed or not in PATH" 1>&2 + exit 200 +fi +"$GIT_TOOL" rev-parse --is-inside-work-tree >/dev/null 2>&1 +status="$?" +if [[ $status -eq 0 ]]; then + TOPDIR=$("$GIT_TOOL" rev-parse --show-toplevel) +fi + +# set usage message +# +export USAGE="usage: $0 [-h] [-v level] [-V] [-n] [-N] + [-d topdir] [-p tool] [-P optstr] + [-e string ..] [-E exitcode] + yyyy/dir + + -h print help message and exit + -v level set verbosity level (def level: 0) + -V print version string and exit + + -d topdir set topdir (def: $TOPDIR) + + -n go thru the actions, but do not update any files (def: do the action) + -N do not process file, just parse arguments and ignore the file (def: process the file) + + -e string output string, followed by newline, to stderr (def: do not) + -E exitcode force exit with exitcode (def: exit based on success or failure of the action) + + yyyy/dir path from topdir to winner directory: must contain the files: README.md, .path and .winner.json + +Exit codes: + 0 all OK + 1 pandoc exited non-zero + 2 -h and help string printed or -V and version string printed + 3 command line error + 4 bash version is < 4.2 + 5 yyyy/dir is not a winner directory + >= 10 < 200 ((not used)) + >= 200 internal error + +$NAME version: $VERSION" + +# setup +# +export NOOP= +export DO_NOT_PROCESS= +export DOCROOT_URL_SLASH="/" + +# parse command line +# +while getopts :hv:Vd:nNe:E: flag; do + case "$flag" in + h) echo "$USAGE" 1>&2 + exit 2 + ;; + v) V_FLAG="$OPTARG" + ;; + V) echo "$VERSION" + exit 2 + ;; + d) TOPDIR="$OPTARG" + ;; + n) NOOP="-n" + ;; + N) DO_NOT_PROCESS="-N" + ;; + e) echo "$OPTARG" 1>&2 + ;; + E) exit "$OPTARG" + ;; + \?) echo "$0: ERROR: invalid option: -$OPTARG" 1>&2 + echo 1>&2 + print_usage 1>&2 + exit 3 + ;; + :) echo "$0: ERROR: option -$OPTARG requires an argument" 1>&2 + echo 1>&2 + echo "$USAGE" 1>&2 + exit 3 + ;; + *) echo "$0: ERROR: unexpected value from getopts: $flag" 1>&2 + echo 1>&2 + echo "$USAGE" 1>&2 + exit 3 + ;; + esac +done + +# parse the command line arguments +# +if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: debug level: $V_FLAG" 1>&2 +fi +# +shift $(( OPTIND - 1 )); +# +if [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: file argument count: $#" 1>&2 +fi +if [[ $# -ne 1 ]]; then + echo "$0: ERROR: expected 1 arg, found: $#" 1>&2 + exit 3 +fi +# +export WINNER_PATH="$1" +if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: WINNER_PATH=$WINNER_PATH" 1>&2 +fi + +# verify that we have an author subdirectory +# +export AUTHOR_PATH="$TOPDIR/author" +if [[ ! -d $AUTHOR_PATH ]]; then + echo "$0: ERROR: author is not a directory under topdir: $AUTHOR_PATH" 1>&2 + exit 203 +fi +export AUTHOR_DIR="author" + +# cd to topdir +# +if [[ ! -e $TOPDIR ]]; then + echo "$0: ERROR: cannot cd to non-existent path: $TOPDIR" 1>&2 + exit 204 +fi +if [[ ! -d $TOPDIR ]]; then + echo "$0: ERROR: cannot cd to a non-directory: $TOPDIR" 1>&2 + exit 205 +fi +export CD_FAILED +if [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: about to: cd $TOPDIR" 1>&2 +fi +cd "$TOPDIR" || CD_FAILED="true" +if [[ -n $CD_FAILED ]]; then + echo "$0: ERROR: cd $TOPDIR failed" 1>&2 + exit 206 +fi +if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: now in directory: $(/bin/pwd)" 1>&2 +fi + +# verify that WINNER_PATH is a winner directory +# +# WINNER_PATH must be in yyyy/dir form +# yyyy must be a directory +# yyyy must be a writable directory +# yyyy/.year must be a non-empty file +# yyyy/dir must be a directory +# yyyy/dir/.path must be a non-empty file +# WINNER_PATH must match the contents of yyyy/dir/.path +# yyyy/dir/.winner.json must be a non-empty file +# +if [[ ! -d $WINNER_PATH ]]; then + echo "$0: ERROR: arg is not a directory: $WINNER_PATH" 1>&2 + exit 5 +fi +if [[ ! -w $WINNER_PATH ]]; then + echo "$0: ERROR: arg is not a writable directory: $WINNER_PATH" 1>&2 + exit 5 +fi +export YEAR_DIR=${WINNER_PATH%%/*} +if [[ -z $YEAR_DIR ]]; then + echo "$0: ERROR: arg not in yyyy/dir form: $WINNER_PATH" 1>&2 + exit 5 +fi +export WINNER_DIR=${WINNER_PATH#*/} +if [[ -z $WINNER_DIR ]]; then + echo "$0: ERROR: arg: $WINNER_PATH not in $YEAR_DIR/dir form: $WINNER_PATH" 1>&2 + exit 5 +fi +if [[ $WINNER_DIR = */* ]]; then + echo "$0: ERROR: dir from arg: $WINNER_PATH contains a /: $WINNER_DIR" 1>&2 + exit 5 +fi +if [[ ! -d $YEAR_DIR ]]; then + echo "$0: ERROR: yyyy from arg: $WINNER_PATH is not a directory: $YEAR_DIR" 1>&2 + exit 5 +fi +export WINNER_ID="${YEAR_DIR}_${WINNER_DIR}" +export DOT_YEAR="$YEAR_DIR/.year" +if [[ ! -s $DOT_YEAR ]]; then + echo "$0: ERROR: not a non-empty file: $DOT_YEAR" 1>&2 + exit 5 +fi +if [[ ! -d $YEAR_DIR/$WINNER_DIR ]]; then + echo "$0: ERROR: yyyy/dir from arg: $WINNER_PATH is not a directory: $YEAR_DIR/$WINNER_DIR" 1>&2 + exit 5 +fi +export DOT_PATH="$YEAR_DIR/$WINNER_DIR/.path" +if [[ ! -s $DOT_PATH ]]; then + echo "$0: ERROR: not a non-empty file: $DOT_PATH" 1>&2 + exit 5 +fi +DOT_PATH_CONTENT=$(< "$DOT_PATH") +if [[ $WINNER_PATH != "$DOT_PATH_CONTENT" ]]; then + echo "$0: ERROR: arg: $WINNER_PATH does not match $DOT_PATH contents: $DOT_PATH_CONTENT" 1>&2 + exit 5 +fi +export WINNER_JSON="$YEAR_DIR/$WINNER_DIR/.winner.json" +if [[ ! -e $WINNER_JSON ]]; then + echo "$0: ERROR: .winner.json does not exist: $WINNER_JSON" 1>&2 + exit 5 +fi +if [[ ! -f $WINNER_JSON ]]; then + echo "$0: ERROR: .winner.json is not a file: $WINNER_JSON" 1>&2 + exit 5 +fi +if [[ ! -r $WINNER_JSON ]]; then + echo "$0: ERROR: .winner.json is not a readable file: $WINNER_JSON" 1>&2 + exit 5 +fi + +# parameter debugging +# +if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: NAME=$NAME" 1>&2 + echo "$0: debug[3]: YEAR_DIR=$YEAR_DIR" 1>&2 + echo "$0: debug[3]: WINNER_DIR=$WINNER_DIR" 1>&2 + echo "$0: debug[3]: WINNER_ID=$WINNER_ID" 1>&2 + echo "$0: debug[3]: DOT_YEAR=$DOT_YEAR" 1>&2 + echo "$0: debug[3]: DOT_PATH=$DOT_PATH" 1>&2 + echo "$0: debug[3]: WINNER_JSON=$WINNER_JSON" 1>&2 + echo "$0: debug[3]: AUTHOR_PATH=$AUTHOR_PATH" 1>&2 + echo "$0: debug[3]: AUTHOR_DIR=$AUTHOR_DIR" 1>&2 + echo "$0: debug[3]: DO_NOT_PROCESS=$DO_NOT_PROCESS" 1>&2 + echo "$0: debug[3]: NOOP=$NOOP" 1>&2 +fi + +# If -N, time to exit +# +if [[ -n $DO_NOT_PROCESS ]]; then + if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: arguments parsed, -N given, exit 0" 1>&2 + fi + exit 0 +fi + +# output DOCROOT_URL_SLASH substitution +# +echo "-s DOCROOT_URL_SLASH='$DOCROOT_URL_SLASH'" + +# output HEADER_1 substitution +# +echo "-s HEADER_1='The International Obfuscated C Code Contest'" + +# All Done!!! -- Jessica Noll, Age 2 +# exit 0 diff --git a/inc/subst.readme.sh b/inc/subst.readme.sh deleted file mode 100755 index 3ae5df9e7..000000000 --- a/inc/subst.readme.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -# -# subst.readme.sh - stub for an actual subst tool -printf "%s\n" "-s subst_readme_token=subst_readme_value" -exit 0 diff --git a/inc/subst.winner-index.sh b/inc/subst.winner-index.sh new file mode 100755 index 000000000..61fa291ea --- /dev/null +++ b/inc/subst.winner-index.sh @@ -0,0 +1,317 @@ +#!/usr/bin/env bash +# +# subst.winner-index.sh - print substitutions for a winner index.html +# +# This tool is used in conjunction with the inc/md2html.cfg configuration +# file, and "readme2index.sh" to build an index.html file for a winner. +# +# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved. +# +# Permission to use, copy, modify, and distribute this software and +# its documentation for any purpose and without fee is hereby granted, +# provided that the above copyright, this permission notice and text +# this comment, and the disclaimer below appear in all of the following: +# +# supporting documentation +# source copies +# source works derived from this source +# binaries derived from this source or from derived source +# +# LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO +# EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# chongo (Landon Curt Noll, http://www.isthe.com/chongo/index.html) /\oo/\ +# +# Share and enjoy! :-) + +# firewall - must be bash with a version 4.2 or later +# +# We must declare arrays with -ag or -Ag +# +if [[ -z ${BASH_VERSINFO[0]} || ${BASH_VERSINFO[0]} -lt 4 || ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 2 ]]; then + echo "$0: ERROR: bash version must be >= 4.2: $BASH_VERSION" 1>&2 + exit 4 +fi + +# setup bash file matching +# +# Requires bash with a version 4.2 or later +# +shopt -s nullglob # enable expanded to nothing rather than remaining unexpanded +shopt -u failglob # disable error message if no matches are found +shopt -u dotglob # disable matching files starting with . +shopt -s globskipdots # enable never matching . nor .. +shopt -u nocaseglob # disable strict case matching +shopt -u extglob # enable extended globbing patterns +shopt -s globstar # enable ** to match all files and zero or more directories and subdirectories + +# set variables referenced in the usage message +# +export VERSION="1.0 2024-01-02" +NAME=$(basename "$0") +export NAME +export V_FLAG=0 +GIT_TOOL=$(type -P git) +export GIT_TOOL +if [[ -z "$GIT_TOOL" ]]; then + echo "$0: FATAL: git tool is not installed or not in PATH" 1>&2 + exit 200 +fi +"$GIT_TOOL" rev-parse --is-inside-work-tree >/dev/null 2>&1 +status="$?" +if [[ $status -eq 0 ]]; then + TOPDIR=$("$GIT_TOOL" rev-parse --show-toplevel) +fi + +# set usage message +# +export USAGE="usage: $0 [-h] [-v level] [-V] [-n] [-N] + [-d topdir] [-p tool] [-P optstr] + [-e string ..] [-E exitcode] + yyyy/dir + + -h print help message and exit + -v level set verbosity level (def level: 0) + -V print version string and exit + + -d topdir set topdir (def: $TOPDIR) + + -n go thru the actions, but do not update any files (def: do the action) + -N do not process file, just parse arguments and ignore the file (def: process the file) + + -e string output string, followed by newline, to stderr (def: do not) + -E exitcode force exit with exitcode (def: exit based on success or failure of the action) + + yyyy/dir path from topdir to winner directory: must contain the files: README.md, .path and .winner.json + +Exit codes: + 0 all OK + 1 pandoc exited non-zero + 2 -h and help string printed or -V and version string printed + 3 command line error + 4 bash version is < 4.2 + 5 yyyy/dir is not a winner directory + >= 10 < 200 ((not used)) + >= 200 internal error + +$NAME version: $VERSION" + +# setup +# +export NOOP= +export DO_NOT_PROCESS= +export DOCROOT_URL_SLASH="/" + +# parse command line +# +while getopts :hv:Vd:nNe:E: flag; do + case "$flag" in + h) echo "$USAGE" 1>&2 + exit 2 + ;; + v) V_FLAG="$OPTARG" + ;; + V) echo "$VERSION" + exit 2 + ;; + d) TOPDIR="$OPTARG" + ;; + n) NOOP="-n" + ;; + N) DO_NOT_PROCESS="-N" + ;; + e) echo "$OPTARG" 1>&2 + ;; + E) exit "$OPTARG" + ;; + \?) echo "$0: ERROR: invalid option: -$OPTARG" 1>&2 + echo 1>&2 + print_usage 1>&2 + exit 3 + ;; + :) echo "$0: ERROR: option -$OPTARG requires an argument" 1>&2 + echo 1>&2 + echo "$USAGE" 1>&2 + exit 3 + ;; + *) echo "$0: ERROR: unexpected value from getopts: $flag" 1>&2 + echo 1>&2 + echo "$USAGE" 1>&2 + exit 3 + ;; + esac +done + +# parse the command line arguments +# +if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: debug level: $V_FLAG" 1>&2 +fi +# +shift $(( OPTIND - 1 )); +# +if [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: file argument count: $#" 1>&2 +fi +if [[ $# -ne 1 ]]; then + echo "$0: ERROR: expected 1 arg, found: $#" 1>&2 + exit 3 +fi +# +export WINNER_PATH="$1" +if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: WINNER_PATH=$WINNER_PATH" 1>&2 +fi + +# verify that we have an author subdirectory +# +export AUTHOR_PATH="$TOPDIR/author" +if [[ ! -d $AUTHOR_PATH ]]; then + echo "$0: ERROR: author is not a directory under topdir: $AUTHOR_PATH" 1>&2 + exit 203 +fi +export AUTHOR_DIR="author" + +# cd to topdir +# +if [[ ! -e $TOPDIR ]]; then + echo "$0: ERROR: cannot cd to non-existent path: $TOPDIR" 1>&2 + exit 204 +fi +if [[ ! -d $TOPDIR ]]; then + echo "$0: ERROR: cannot cd to a non-directory: $TOPDIR" 1>&2 + exit 205 +fi +export CD_FAILED +if [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: about to: cd $TOPDIR" 1>&2 +fi +cd "$TOPDIR" || CD_FAILED="true" +if [[ -n $CD_FAILED ]]; then + echo "$0: ERROR: cd $TOPDIR failed" 1>&2 + exit 206 +fi +if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: now in directory: $(/bin/pwd)" 1>&2 +fi + +# verify that WINNER_PATH is a winner directory +# +# WINNER_PATH must be in yyyy/dir form +# yyyy must be a directory +# yyyy must be a writable directory +# yyyy/.year must be a non-empty file +# yyyy/dir must be a directory +# yyyy/dir/.path must be a non-empty file +# WINNER_PATH must match the contents of yyyy/dir/.path +# yyyy/dir/.winner.json must be a non-empty file +# +if [[ ! -d $WINNER_PATH ]]; then + echo "$0: ERROR: arg is not a directory: $WINNER_PATH" 1>&2 + exit 5 +fi +if [[ ! -w $WINNER_PATH ]]; then + echo "$0: ERROR: arg is not a writable directory: $WINNER_PATH" 1>&2 + exit 5 +fi +export YEAR_DIR=${WINNER_PATH%%/*} +if [[ -z $YEAR_DIR ]]; then + echo "$0: ERROR: arg not in yyyy/dir form: $WINNER_PATH" 1>&2 + exit 5 +fi +export WINNER_DIR=${WINNER_PATH#*/} +if [[ -z $WINNER_DIR ]]; then + echo "$0: ERROR: arg: $WINNER_PATH not in $YEAR_DIR/dir form: $WINNER_PATH" 1>&2 + exit 5 +fi +if [[ $WINNER_DIR = */* ]]; then + echo "$0: ERROR: dir from arg: $WINNER_PATH contains a /: $WINNER_DIR" 1>&2 + exit 5 +fi +if [[ ! -d $YEAR_DIR ]]; then + echo "$0: ERROR: yyyy from arg: $WINNER_PATH is not a directory: $YEAR_DIR" 1>&2 + exit 5 +fi +export WINNER_ID="${YEAR_DIR}_${WINNER_DIR}" +export DOT_YEAR="$YEAR_DIR/.year" +if [[ ! -s $DOT_YEAR ]]; then + echo "$0: ERROR: not a non-empty file: $DOT_YEAR" 1>&2 + exit 5 +fi +if [[ ! -d $YEAR_DIR/$WINNER_DIR ]]; then + echo "$0: ERROR: yyyy/dir from arg: $WINNER_PATH is not a directory: $YEAR_DIR/$WINNER_DIR" 1>&2 + exit 5 +fi +export DOT_PATH="$YEAR_DIR/$WINNER_DIR/.path" +if [[ ! -s $DOT_PATH ]]; then + echo "$0: ERROR: not a non-empty file: $DOT_PATH" 1>&2 + exit 5 +fi +DOT_PATH_CONTENT=$(< "$DOT_PATH") +if [[ $WINNER_PATH != "$DOT_PATH_CONTENT" ]]; then + echo "$0: ERROR: arg: $WINNER_PATH does not match $DOT_PATH contents: $DOT_PATH_CONTENT" 1>&2 + exit 5 +fi +export WINNER_JSON="$YEAR_DIR/$WINNER_DIR/.winner.json" +if [[ ! -e $WINNER_JSON ]]; then + echo "$0: ERROR: .winner.json does not exist: $WINNER_JSON" 1>&2 + exit 5 +fi +if [[ ! -f $WINNER_JSON ]]; then + echo "$0: ERROR: .winner.json is not a file: $WINNER_JSON" 1>&2 + exit 5 +fi +if [[ ! -r $WINNER_JSON ]]; then + echo "$0: ERROR: .winner.json is not a readable file: $WINNER_JSON" 1>&2 + exit 5 +fi + +# parameter debugging +# +if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: NAME=$NAME" 1>&2 + echo "$0: debug[3]: YEAR_DIR=$YEAR_DIR" 1>&2 + echo "$0: debug[3]: WINNER_DIR=$WINNER_DIR" 1>&2 + echo "$0: debug[3]: WINNER_ID=$WINNER_ID" 1>&2 + echo "$0: debug[3]: DOT_YEAR=$DOT_YEAR" 1>&2 + echo "$0: debug[3]: DOT_PATH=$DOT_PATH" 1>&2 + echo "$0: debug[3]: WINNER_JSON=$WINNER_JSON" 1>&2 + echo "$0: debug[3]: AUTHOR_PATH=$AUTHOR_PATH" 1>&2 + echo "$0: debug[3]: AUTHOR_DIR=$AUTHOR_DIR" 1>&2 + echo "$0: debug[3]: DO_NOT_PROCESS=$DO_NOT_PROCESS" 1>&2 + echo "$0: debug[3]: NOOP=$NOOP" 1>&2 +fi + +# If -N, time to exit +# +if [[ -n $DO_NOT_PROCESS ]]; then + if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: arguments parsed, -N given, exit 0" 1>&2 + fi + exit 0 +fi + +# output TITLE substitution +# +echo "-s TITIE='$YEAR_DIR/$WINNER_DIR'" + +# output DESCRIPTION substitution +# +echo "-s DESCRIPTION='$YEAR_DIR IOCCC winner $WINNER_DIR'" + +# output KEYWORDS substitution +# +echo "-s KEYWORDS='IOCCC, $YEAR_DIR, IOCCC $YEAR_DIR, IOCCC winner, $WINNER_DIR'" + +# output HEADER_2 substitution +# +echo "-s HEADER_2='$YEAR_DIR/$WINNER_DIR'" + +# All Done!!! -- Jessica Noll, Age 2 +# +exit 0 diff --git a/inc/topnav.first.html b/inc/topnav.first.html new file mode 100644 index 000000000..3704ceb3b --- /dev/null +++ b/inc/topnav.first.html @@ -0,0 +1,9 @@ + + +
+

first entry + ↑ %%UP_TEXT%% ↑ + %%RIGHT_TEXT%% → +

+ + diff --git a/inc/topnav.last.html b/inc/topnav.last.html new file mode 100644 index 000000000..441ab146d --- /dev/null +++ b/inc/topnav.last.html @@ -0,0 +1,9 @@ + + +
+ ← %%LEFT_TEXT%% + ↑ %%UP_TEXT%% ↑ +

last entry

+
+ + diff --git a/tmp/readme2index.sh b/tmp/readme2index.sh index 871a72efc..e148a476b 100755 --- a/tmp/readme2index.sh +++ b/tmp/readme2index.sh @@ -150,8 +150,8 @@ Exit codes: 5 yyyy/dir is not a winner directory 6 tool not found or not executable (before, pandoc wrapper, after, output tools) 7 HTML phase file not found or not readable - >= 10 < 100 internal error - >= 100 tool error + >= 10 < 200 internal error + >= 200 tool error $NAME version: $VERSION" @@ -159,7 +159,7 @@ $NAME version: $VERSION" # command line parsing functions # ################################## -# setup global variables +# global_variable_setup - setup global variables # # Call this once at the start of the shell script. # @@ -210,9 +210,9 @@ function global_variable_setup # unset PHASE_NAME declare -ag PHASE_NAME - PHASE_NAME=(top head body header topnav begin-row begin-leftcolumn sidenav end-leftcolumn - end-leftcolumn begin-rightcolumn before-content before-content after-content - end-row footer bottom) + PHASE_NAME=(top head body header topnav begin-row begin-leftcolumn + sidenav end-leftcolumn end-leftcolumn begin-rightcolumn before-content + after-content end-rightcolumn end-row footer bottom) unset HTML_PHASE_NAME declare -Ag HTML_PHASE_NAME for n in "${PHASE_NAME[@]}"; do @@ -224,7 +224,7 @@ function global_variable_setup export GETOPT_PHASE=0 } -# print the usage message, exit code and version information +# print_usage - print the usage message, exit code and version information # # Call this to print the usage message, by default to stdout. # However one might usually want to do: @@ -238,7 +238,7 @@ function print_usage echo "$USAGE" } -# parse command line arguments +# parse_command_line - parse command line arguments # # You MUST call this function at least once AND after calling global_variable_setup. # You may call this function again, after setting a new command line args. For example: @@ -643,7 +643,7 @@ function parse_command_line # md2html.cfg related functions # ################################# -# first file_glob match for md2html.cfg file +# match_md2html - first file_glob match for md2html.cfg file # # usage: # match_md2html md2html_path file_path @@ -717,6 +717,133 @@ function match_md2html return 1 } +################################ +# HTML phase related functions # +################################ + +# append_html_phase - append a sed modified HTML phase file to a growing temporary HTML file +# +# usage: +# append_html_phase phase_number name_of_phase starting_exit_code sed_script tmp_phase_file tmp_append +# +# phase_number - HTML phase number (see inc/md2readme.cfg) +# name_of_phase - Name of HTML phase (see inc/md2readme.cfg and the HTML_PHASE_NAME array) +# starting_exit_code - On error, exit starting at this exit code +# sed_script - file contain sed commands +# tmp_phase_file - temp file used to write sed script results +# tmp_append - growing temporary HTML file to append tmp_phase onto +# +# returns: +# 0 ==> ALL is OK +# >0 ==> fatal ERROR, exit with this code +# +function append_html_phase +{ + local PHASE_NUMBER; # HTML phase number + local NAME_OF_PHASE; # Name of HTML phase + local STARTING_EXIT_CODE; # On error, return exit code starting at this exit code + local SED_SCRIPT; # file contain sed commands + local TMP_PHASE_FILE; # temp file used to write sed script results + local TMP_APPEND; # growing temporary HTML file to append tmp_phase onto + + # parse args + # + if [[ $# -ne 6 ]]; then + echo "$0: ERROR: in append_html_phase, expected 6 args, found $#" 1>&2 + # We have to return non-zero but we don't have the args to know STARTING_EXIT_CODE. + # We might as well use 7 since that is an HTML phase exit code + return 7 + fi + PHASE_NUMBER="$1" + NAME_OF_PHASE="$2" + STARTING_EXIT_CODE="$3" + SED_SCRIPT="$4" + TMP_PHASE_FILE="$5" + TMP_APPEND="$6" + # + if [[ $V_FLAG -ge 7 ]]; then + echo "$0: debug[7]: starting: append_html_phase $PHASE_NUMBER $NAME_OF_PHASE $STARTING_EXIT_CODE" \ + "$SED_SCRIPT $TMP_PHASE_FILE $TMP_APPEND" 1>&2 + fi + + # HTML phase setup + # + PHASE_FILE="$INC/$NAME_OF_PHASE.${HTML_PHASE_NAME[$NAME_OF_PHASE]}.html" + # + # we validated all HTML phase names previously: so only a readable file check is needed + # + if [[ ! -r "$PHASE_FILE" ]]; then + echo "$0: ERROR: cannot read HTML phase $PHASE_NUMBER ($NAME_OF_PHASE) file: $PHASE_FILE" 1>&2 + return "$STARTING_EXIT_CODE"; + fi + + # output, with sed modification, HTML phase file + # + if [[ -z $NOOP ]]; then + sed -f "$SED_SCRIPT" "$PHASE_FILE" > "$TMP_PHASE_FILE" + status="$?" + if [[ $status -ne 0 ]]; then + echo "$0: ERROR: sed error on HTML phase $PHASE_NUMBER ($NAME_OF_PHASE) file: $PHASE_FILE," \ + "error code: $status" 1>&2 + return $(( STARTING_EXIT_CODE+1 )) + fi + elif [[ $V_FLAG -ge 7 ]]; then + echo "$0: debug[7]: because of -n, disabled: sed -f $SED_SCRIPT $PHASE_FILE > $TMP_PHASE_FILE" 1>&2 + fi + + + # verify that no %%symbol%%'s were missed + # + if [[ -z $NOOP ]]; then + if grep -F -q '%%' "$TMP_PHASE_FILE" 2>/dev/null; then + + # warn about the problem + # + echo "$0: WARNING: %% symbols found in HTML phase $PHASE_NUMBER ($NAME_OF_PHASE)" \ + "starts below: $TMP_PHASE_FILE" 1>&2 + grep -F '%%' "$TMP_PHASE_FILE" 1>&2 + echo "$0: WARNING: %% symbols found in HTML phase $PHASE_NUMBER ($NAME_OF_PHASE)" \ + "ends above: $TMP_PHASE_FILE" 1>&2 + + # -S means just warn + # + if [[ -n $CAP_S_FLAG ]]; then + echo "$0: WARNING: -S and %% symbols found in HTML phase $PHASE_NUMBER ($NAME_OF_PHASE)" \ + "file: $TMP_PHASE_FILE" 1>&2 + else + echo "$0: ERROR: %% symbols found in HTML phase $PHASE_NUMBER ($NAME_OF_PHASE)" \ + "file: $TMP_PHASE_FILE" 1>&2 + return $(( STARTING_EXIT_CODE+2 )) + fi + elif [[ $V_FLAG -ge 7 ]]; then + echo "$0: debug[7]: no %%'s found in: $TMP_PHASE_FILE" 1>&2 + fi + elif [[ $V_FLAG -ge 7 ]]; then + echo "$0: debug[7]: because of -n, disabled: grep -F -q '%%' $TMP_PHASE_FILE 2>/dev/null" 1>&2 + fi + + # append HTML phase file to temporary index HTML file + # + if [[ -z $NOOP ]]; then + cat "$TMP_PHASE_FILE" >> "$TMP_APPEND" + status="$?" + if [[ $status -ne 0 ]]; then + echo "$0: ERROR: cat $TMP_PHASE_FILE >> $TMP_APPEND for HTML phase $PHASE_NUMBER ($NAME_OF_PHASE)," \ + "error code: $status" 1>&2 + return $(( STARTING_EXIT_CODE+3 )) + fi + elif [[ $V_FLAG -ge 7 ]]; then + echo "$0: debug[7]: because of -n, disabled: cat $TMP_PHASE_FILE >> $TMP_APPEND" 1>&2 + fi + + # report progress if verbose + # + if [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: successfully completed HTML phase $PHASE_NUMBER ($NAME_OF_PHASE)" 1>&2 + fi + return 0 +} + ################################### # required initial variable setup # ################################### @@ -1014,8 +1141,10 @@ for n in "${!OUTPUT_TOOL[@]}"; do # SC2086 (info): Double quote to prevent globbing and word splitting. # shellcheck disable=SC2046,SC2086 OUTPUT_TOOL_OUTPUT=$("$VALUE" ${OUTPUT_TOOL_OPTSTR[$VALUE]} -- "${WINNER_PATH}") - if [[ $V_FLAG -ge 7 ]]; then - echo "$0: debug[7]: phase ${GETOPT_PHASE} output tool output: $OUTPUT_TOOL_OUTPUT" 1>&2 + if [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: phase ${GETOPT_PHASE} $VALUE output starts below" 1>&2 + echo "$OUTPUT_TOOL_OUTPUT" 1>&2 + echo "$0: debug[5]: phase ${GETOPT_PHASE} $VALUE output ends above" 1>&2 fi # process command line arguments from output tool @@ -1026,7 +1155,7 @@ for n in "${!OUTPUT_TOOL[@]}"; do # # SC2086 (info): Double quote to prevent globbing and word splitting. # shellcheck disable=SC2086 - parse_command_line $OUTPUT_TOOL_OUTPUT + eval parse_command_line $OUTPUT_TOOL_OUTPUT # parse output tool arguments # @@ -1072,7 +1201,7 @@ fi match_md2html "$MD2HTML_CFG" "$README_PATH" status="$?" if [[ $status -ne 0 ]]; then - echo "$0: ERROR: README_PATH: $README_PATH does not match any lines in: $MD2HTML_CFG" 1>&2 + echo "$0: ERROR: README_PATH: $README_PATH does not match any lines in: $MD2HTML_CFG, error code: $status" 1>&2 exit 26 fi @@ -1161,8 +1290,10 @@ for n in "${!OUTPUT_TOOL[@]}"; do # SC2086 (info): Double quote to prevent globbing and word splitting. # shellcheck disable=SC2046,SC2086 OUTPUT_TOOL_OUTPUT=$("$VALUE" ${OUTPUT_TOOL_OPTSTR[$VALUE]} -- "${WINNER_PATH}") - if [[ $V_FLAG -ge 7 ]]; then - echo "$0: debug[7]: phase ${GETOPT_PHASE} output tool output: $OUTPUT_TOOL_OUTPUT" 1>&2 + if [[ $V_FLAG -ge 5 ]]; then + echo "$0: debug[5]: phase ${GETOPT_PHASE} $VALUE output starts below" 1>&2 + echo "$OUTPUT_TOOL_OUTPUT" 1>&2 + echo "$0: debug[5]: phase ${GETOPT_PHASE} $VALUE output ends above" 1>&2 fi # process command line arguments from output tool @@ -1173,7 +1304,7 @@ for n in "${!OUTPUT_TOOL[@]}"; do # # SC2086 (info): Double quote to prevent globbing and word splitting. # shellcheck disable=SC2086 - parse_command_line $OUTPUT_TOOL_OUTPUT + eval parse_command_line $OUTPUT_TOOL_OUTPUT # parse output tool arguments # @@ -1317,12 +1448,504 @@ fi # if [[ $V_FLAG -ge 5 ]]; then for n in "${!TOKEN[@]}"; do - VALUE="${TOKEN[$n]}" - echo "$0: debug[5]: -s token replacement: sed -e s;%%$n%%;$VALUE;g" 1>&2 + echo "$0: debug[5]: -s token replacement: sed -e s;%%$n%%;${TOKEN[$n]};g" 1>&2 done fi -# XXX - write more code here - XXX # +# If -N, time to exit # -echo "$0: Notice: if $0 was complete, $README_PATH would be used to form $INDEX_PATH" 1>&2 +if [[ -n $DO_NOT_PROCESS ]]; then + if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: arguments parsed, -N given, exit 0" 1>&2 + fi + exit 0 +fi + +########################## +# HTML pre-0 phase setup # +########################## + +# create a temporary sed script +# +TMP_SED_SCRIPT=".$NAME.$$.sed" +if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: temporary sed script: $TMP_SED_SCRIPT" 1>&2 +fi +if [[ -z $NOOP ]]; then + + # form the temp file + # + trap 'rm -f $TMP_SED_SCRIPT; exit' 0 1 2 3 15 + rm -f "$TMP_SED_SCRIPT" + if [[ -e $TMP_SED_SCRIPT ]]; then + echo "$0: ERROR: cannot remove temporary sed script: $TMP_SED_SCRIPT" 1>&2 + exit 27 + fi + :> "$TMP_SED_SCRIPT" + if [[ ! -e $TMP_SED_SCRIPT ]]; then + echo "$0: ERROR: cannot create temporary sed script: $TMP_SED_SCRIPT" 1>&2 + exit 28 + fi + + # load the sed script with sed commands from any "-s token=value" + # + for n in "${!TOKEN[@]}"; do + echo "s;%%$n%%;${TOKEN[$n]};g" >> "$TMP_SED_SCRIPT" + done + if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: temporary sed script starts below: $TMP_SED_SCRIPT" 1>&2 + echo "$TMP_SED_SCRIPT" 1>&2 + echo "$0: debug[3]: temporary sed script ends above: $TMP_SED_SCRIPT" 1>&2 + fi +elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: because of -n, temporary sed script is not formed: $TMP_SED_SCRIPT" 1>&2 + echo "$0: debug[3]: the temporary sed script that would have been written starts below: $TMP_SED_SCRIPT" 1>&2 + for n in "${!TOKEN[@]}"; do + echo "s;%%$n%%;${TOKEN[$n]};g" 1>&2 + done + echo "$0: debug[3]: the temporary sed script that would have been written ends above: $TMP_SED_SCRIPT" 1>&2 +fi + +# create a temporary HTML phase file +# +# NOTE: This file, when we are finished building it, will be come the final index.html file. +# +TMP_PHASE=".$NAME.$$.html-phase.html" +if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: temporary HTML file: $TMP_PHASE" 1>&2 +fi +if [[ -z $NOOP ]]; then + + # form the temp file + # + trap 'rm -f $TMP_SED_SCRIPT $TMP_PHASE; exit' 0 1 2 3 15 + rm -f "$TMP_PHASE" + if [[ -e $TMP_PHASE ]]; then + echo "$0: ERROR: cannot remove temporary HTML file: $TMP_PHASE" 1>&2 + exit 27 + fi + :> "$TMP_PHASE" + if [[ ! -e $TMP_PHASE ]]; then + echo "$0: ERROR: cannot create temporary HTML file: $TMP_PHASE" 1>&2 + exit 28 + fi +elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: because of -n, temporary HTML file is not formed: $TMP_PHASE" 1>&2 +fi + +# create a temporary index HTML file +# +# NOTE: This file, when we are finished building it, will be come the final index.html file. +# +TMP_INDEX_HTML=".$NAME.$$.index.html" +if [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: temporary index HTML file: $TMP_INDEX_HTML" 1>&2 +fi +if [[ -z $NOOP ]]; then + + # form the temp file + # + trap 'rm -f $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML; exit' 0 1 2 3 15 + rm -f "$TMP_INDEX_HTML" + if [[ -e $TMP_INDEX_HTML ]]; then + echo "$0: ERROR: cannot remove temporary index HTML file: $TMP_INDEX_HTML" 1>&2 + exit 29 + fi + :> "$TMP_INDEX_HTML" + if [[ ! -e $TMP_INDEX_HTML ]]; then + + exit 30 + fi +elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: because of -n, temporary index HTML file is not formed: $TMP_INDEX_HTML" 1>&2 +fi + +####################################### +# HTML phase 0: inc/top.__name__.html # +####################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +export CUR_PHASE_NUM=0 +export CUR_PHASE_NAME="top" +export BASE_EXIT_CODE=40 # possible: exit 40 or exit 41 or exit 42 or exit 43 or exit 44 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +# Special output to indicate which tool was used +# +if [[ -z $NOOP ]]; then + echo "" >> "$TMP_INDEX_HTML" +fi + +######################################## +# HTML phase 1: inc/head.__name__.html # +######################################## + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=1 +CUR_PHASE_NAME="head" +BASE_EXIT_CODE=45 # possible: exit 45 or exit 46 or exit 47 or exit 48 or exit 49 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +######################################## +# HTML phase 2: inc/body.__name__.html # +######################################## + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=2 +CUR_PHASE_NAME="body" +BASE_EXIT_CODE=50 # possible: exit 50 or exit 51 or exit 52 or exit 53 or exit 54 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +########################################## +# HTML phase 3: inc/header.__name__.html # +########################################## + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=3 +CUR_PHASE_NAME="header" +BASE_EXIT_CODE=55 # possible: exit 55 or exit 56 or exit 57 or exit 58 or exit 59 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +########################################## +# HTML phase 4: inc/topnav.__name__.html # +########################################## + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=4 +CUR_PHASE_NAME="topnav" +BASE_EXIT_CODE=60 # possible: exit 60 or exit 61 or exit 62 or exit 63 or exit 64 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +############################################# +# HTML phase 5: inc/begin-row.__name__.html # +############################################# + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=5 +CUR_PHASE_NAME="begin-row" +BASE_EXIT_CODE=65 # possible: exit 65 or exit 66 or exit 67 or exit 68 or exit 69 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +#################################################### +# HTML phase 6: inc/begin-leftcolumn.__name__.html # +#################################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=6 +CUR_PHASE_NAME="begin-leftcolumn" +BASE_EXIT_CODE=70 # possible: exit 70 or exit 71 or exit 72 or exit 73 or exit 74 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +########################################### +# HTML phase 7: inc/sidenav.__name__.html # +########################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=7 +CUR_PHASE_NAME="sidenav" +BASE_EXIT_CODE=75 # possible: exit 75 or exit 76 or exit 77 or exit 78 or exit 79 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +################################################## +# HTML phase 8: inc/end-leftcolumn.__name__.html # +################################################## + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=8 +CUR_PHASE_NAME="end-leftcolumn" +BASE_EXIT_CODE=80 # possible: exit 80 or exit 81 or exit 82 or exit 83 or exit 84 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +##################################################### +# HTML phase 9: inc/begin-rightcolumn.__name__.html # +##################################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=9 +CUR_PHASE_NAME="begin-rightcolumn" +BASE_EXIT_CODE=85 # possible: exit 85 or exit 86 or exit 87 or exit 88 or exit 89 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +################################################### +# HTML phase 10: inc/before-content.__name__.html # +################################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=10 +CUR_PHASE_NAME="before-content" +BASE_EXIT_CODE=90 # possible: exit 90 or exit 91 or exit 92 or exit 93 or exit 94 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +############################## +# HTML phase 20: before tool # +############################## + +# XXX - add code for before tool here - XXX + +###################################### +# HTML phase 21: pandoc wrapper tool # +###################################### + +# XXX - add code for pandoc wrapper tool here - XXX + +############################# +# HTML phase 22: after tool # +############################# + +# XXX - add code for after tool here - XXX + +################################################## +# HTML phase 30: inc/after-content.__name__.html # +################################################## + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=30 +CUR_PHASE_NAME="after-content" +BASE_EXIT_CODE=110 # possible: exit 110 or exit 111 or exit 112 or exit 113 or exit 114 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +#################################################### +# HTML phase 31: inc/end-rightcolumn.__name__.html # +#################################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=31 +CUR_PHASE_NAME="end-rightcolumn" +BASE_EXIT_CODE=115 # possible: exit 115 or exit 116 or exit 117 or exit 118 or exit 119 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +############################################ +# HTML phase 32: inc/end-row.__name__.html # +############################################ + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=32 +CUR_PHASE_NAME="end-row" +BASE_EXIT_CODE=120 # possible: exit 120 or exit 121 or exit 122 or exit 123 or exit 124 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +########################################### +# HTML phase 33: inc/footer.__name__.html # +########################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=33 +CUR_PHASE_NAME="footer" +BASE_EXIT_CODE=125 # possible: exit 125 or exit 126 or exit 127 or exit 128 or exit 129 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +########################################### +# HTML phase 34: inc/bottom.__name__.html # +########################################### + +# NOTE: See inc/md2html.cfg for details on HTML phase numbers, HTML phase names, and HTML phase files +# +CUR_PHASE_NUM=34 +CUR_PHASE_NAME="bottom" +BASE_EXIT_CODE=130 # possible: exit 130 or exit 131 or exit 132 or exit 133 or exit 134 +# +append_html_phase "$CUR_PHASE_NUM" "$CUR_PHASE_NAME" "$BASE_EXIT_CODE" "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +status="$?" +if [[ $status -ne 0 ]]; then + echo "$0: ERROR: append_html_phase" \ + "$CUR_PHASE_NUM $CUR_PHASE_NAME $BASE_EXIT_CODE $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML," \ + "error code: $status" 1>&2 + exit "$status" +fi + +################################ +# finalize the index.html file # +################################ + +# sanity check - temporary index HTML file must be a readable file +# +if [[ -z $NOOP ]]; then + if [[ ! -e $TMP_INDEX_HTML ]]; then + echo "$0: ERROR: after HTML phase $CUR_PHASE_NUM ($CUR_PHASE_NAME)," \ + "temporary index HTML file is missing: $TMP_INDEX_HTML" 1>&2 + exit 135 + fi + if [[ ! -f $TMP_INDEX_HTML ]]; then + echo "$0: ERROR: after HTML phase $CUR_PHASE_NUM ($CUR_PHASE_NAME)," \ + "temporary index HTML file is not a file: $TMP_INDEX_HTML" 1>&2 + exit 136 + fi + if [[ ! -r $TMP_INDEX_HTML ]]; then + echo "$0: ERROR: after HTML phase $CUR_PHASE_NUM ($CUR_PHASE_NAME)," \ + "temporary index HTML file is not a readable file: $TMP_INDEX_HTML" 1>&2 + exit 137 + fi +elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: because of -n, disabled readable file check of: $TMP_PHASE_FILE 2>/dev/null" 1>&2 +fi + +# move temporary index HTML in place +# +if [[ -z $NOOP ]]; then + mv -f -- "$TMP_INDEX_HTML" "$INDEX_PATH" + status="$?" + if [[ status -ne 0 ]]; then + echo "$0: ERROR: mv -f -- $TMP_INDEX_HTML $INDEX_PATH filed, error code: $status" 1>&2 + exit 138 + fi + if [[ ! -s $INDEX_PATH ]]; then + echo "$0: ERROR: not a non-empty index HTML file: $INDEX_PATH" 1>&2 + exit 139 + fi +elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: because of -n, disabled: mv -f -- $TMP_INDEX_HTML $INDEX_PATH" 1>&2 +fi + +# file cleanup +# +if [[ -z $NOOP ]]; then + rm -f -- "$TMP_SED_SCRIPT" "$TMP_PHASE" "$TMP_INDEX_HTML" +elif [[ $V_FLAG -ge 3 ]]; then + echo "$0: debug[3]: because of -n, disabled: rm -f -- $TMP_SED_SCRIPT $TMP_PHASE $TMP_INDEX_HTML" 1>&2 +fi + +# All Done!!! -- Jessica Noll, Age 2 +# +if [[ -z $NOOP ]]; then + if [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[1]: All Done!!! -- Jessica Noll, Age 2, formed index HTML file: $INDEX_PATH" 1>&2 + fi +elif [[ $V_FLAG -ge 1 ]]; then + echo "$0: debug[3]: because of -n, skipped forming index HTML file: $INDEX_PATH" 1>&2 +fi exit 0