move non-README.md HTML formation to bin/othermd2html.sh

The core of `bin/gen-other-html.sh` code that converts entry non-README.md
into HTML has been moved into a new tool: `bin/othermd2html.sh`.

The `bin/othermd2html.sh` tool will be useful to the `bin/cvt-submission.sh`
tool that is under development.

Added info about `bin/othermd2html.sh` to `bin/README.md`.

Changed `bin/gen-other-html.sh` VERSION from "1.4.1 2024-08-18"
to "1.5 2024-08-27".

HTML produced by `bin/gen-other-html.sh` now uses a "jump to" mid-bar
test now shows the `YYYY/dir/index.html` link text (with `YYYY/dir/` added).

Performed `make gen_other_html` to accomplish the above and to test under macOS.
Performed `make gen_top_html` to accomplish the above and to test under macOS.
This commit is contained in:
Landon Curt Noll committed 2024-08-27 16:31:56 -07:00
1 parent 7e567c0004
commit ccc360b2fb
40 files changed
+725 -155

No files matched your search

+56 -119
View File
@@ -86,7 +86,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an
# set variables referenced in the usage message
#
export VERSION="1.4.1 2024-08-18"
export VERSION="1.5 2024-08-27"
NAME=$(basename "$0")
export NAME
export V_FLAG=0
@@ -104,8 +104,6 @@ fi
export TOPDIR
export DOCROOT_SLASH="../../"
export TAGLINE="bin/$NAME"
export MD2HTML_SH="bin/md2html.sh"
export PANDOC_WRAPPER="bin/pandoc-wrapper.sh"
export REPO_TOP_URL="https://github.com/ioccc-src/temp-test-ioccc"
# GitHub puts individual files under the "blob/master" sub-directory.
export REPO_URL="$REPO_TOP_URL/blob/master"
@@ -143,12 +141,12 @@ export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-D docroot/] [-n] [-N]
-t tagline string to write about the tool that formed the markdown content (def: $TAGLINE)
NOTE: The '-t tagline' is passed as leading options on tool command lines.
-Q quick mode, do not run $MD2HTML_SH unless markdown is out of date (def: do)
-Q quick mode, do not run $OTHERMD2HTML unless markdown is out of date (def: do)
-w site_url Base URL of the website (def: $SITE_URL)
NOTE: The '-w site_url' is passed as leading options on tool command lines.
NOTE: Any '-D docroot/', '-t tagline', '-w site_url' are passed to 'md2html.sh' tool.
NOTE: Any '-D docroot/', '-t tagline', '-v level', '-w site_url' are passed to 'md2html.sh' tool.
Exit codes:
0 all OK
@@ -305,19 +303,19 @@ fi
export BIN_DIR="bin"
# verify that the bin/md2html.sh tool is executable
# verify that the bin/othermd2html.sh tool is executable
#
export MD2HTML_SH="$BIN_DIR/md2html.sh"
if [[ ! -e $MD2HTML_SH ]]; then
echo "$0: ERROR: bin/md2html.sh does not exist: $MD2HTML_SH" 1>&2
export OTHERMD2HTML="$BIN_DIR/othermd2html.sh"
if [[ ! -e $OTHERMD2HTML ]]; then
echo "$0: ERROR: bin/othermd2html.sh does not exist: $OTHERMD2HTML" 1>&2
exit 5
fi
if [[ ! -f $MD2HTML_SH ]]; then
echo "$0: ERROR: bin/md2html.sh is not a regular file: $MD2HTML_SH" 1>&2
if [[ ! -f $OTHERMD2HTML ]]; then
echo "$0: ERROR: bin/othermd2html.sh is not a regular file: $OTHERMD2HTML" 1>&2
exit 5
fi
if [[ ! -x $MD2HTML_SH ]]; then
echo "$0: ERROR: bin/md2html.sh is not an executable file: $MD2HTML_SH" 1>&2
if [[ ! -x $OTHERMD2HTML ]]; then
echo "$0: ERROR: bin/othermd2html.sh is not an executable file: $OTHERMD2HTML" 1>&2
exit 5
fi
@@ -347,6 +345,8 @@ fi
#
TOOL_OPTION+=("-t")
TOOL_OPTION+=("$TAGLINE")
TOOL_OPTION+=("-v")
TOOL_OPTION+=("$V_FLAG")
TOOL_OPTION+=("-w")
TOOL_OPTION+=("$SITE_URL")
@@ -363,7 +363,6 @@ if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: TOPDIR=$TOPDIR" 1>&2
echo "$0: debug[3]: DOCROOT_SLASH=$DOCROOT_SLASH" 1>&2
echo "$0: debug[3]: TAGLINE=$TAGLINE" 1>&2
echo "$0: debug[3]: PANDOC_WRAPPER=$PANDOC_WRAPPER" 1>&2
echo "$0: debug[3]: REPO_TOP_URL=$REPO_TOP_URL" 1>&2
echo "$0: debug[3]: REPO_URL=$REPO_URL" 1>&2
echo "$0: debug[3]: SITE_URL=$SITE_URL" 1>&2
@@ -378,7 +377,7 @@ if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: CD_FAILED=$CD_FAILED" 1>&2
echo "$0: debug[3]: BIN_PATH=$BIN_PATH" 1>&2
echo "$0: debug[3]: BIN_DIR=$BIN_DIR" 1>&2
echo "$0: debug[3]: MD2HTML_SH=$MD2HTML_SH" 1>&2
echo "$0: debug[3]: OTHERMD2HTML=$OTHERMD2HTML" 1>&2
echo "$0: debug[3]: TOP_FILE=$TOP_FILE" 1>&2
fi
@@ -396,7 +395,7 @@ fi
# create a temporary exit code
#
# It is a pain to set the EXIT_CODE deep inside a loop, so we write the EXIT_CODE into a file
# and read the file (setting EXIT_CODE again) after the loop. A hack, but good enough for our needs.
# and read the file (setting EXIT_CODE again) after the loop. A hack, but good enough for o ur needs.
#
export TMP_EXIT_CODE=".tmp.$NAME.EXIT_CODE.$$.tmp"
if [[ $V_FLAG -ge 3 ]]; then
@@ -435,18 +434,21 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ ! -e $YYYY ]]; then
echo "$0: ERROR: YYYY does not exist: $YYYY" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -d $YYYY ]]; then
echo "$0: ERROR: YYYY is not a directory: $YYYY" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -r $YYYY ]]; then
echo "$0: ERROR: YYYY is not an readable directory: $YYYY" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -457,24 +459,28 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ ! -e $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year does not exist: $YEAR_FILE" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -f $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year is not a regular file: $YEAR_FILE" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -r $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year is not an readable file: $YEAR_FILE" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -s $YEAR_FILE ]]; then
echo "$0: ERROR: YYYY/.year is not a non-empty readable file: $YEAR_FILE" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -495,12 +501,14 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ ! -d $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY_DIR is not a directory: $YYYY_DIR" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -w $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY_DIR is not a writable directory: $YYYY_DIR" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -508,6 +516,7 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ -z $YEAR_DIR ]]; then
echo "$0: ERROR: YYYY_DIR not in YYYY/dir form: $YYYY_DIR" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -515,12 +524,14 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ -z $ENTRY_DIR ]]; then
echo "$0: ERROR: YYYY_DIR not in $YEAR_DIR/dir form: $YYYY_DIR" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ $ENTRY_DIR = */* ]]; then
echo "$0: ERROR: YYYY_DIR: $YYYY_DIR dir contains a /: $ENTRY_DIR" 1>&2
EXIT_CODE="6" # exit 6
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -530,18 +541,21 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ ! -e $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY_DIR does not exist: $YYYY_DIR" 1>&2
EXIT_CODE="7" # exit 7
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -d $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY_DIR is not a directory: $YYYY_DIR" 1>&2
EXIT_CODE="7" # exit 7
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -w $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY_DIR is not an writable directory: $YYYY_DIR" 1>&2
EXIT_CODE="7" # exit 7
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -552,6 +566,7 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ ! -s $DOT_PATH ]]; then
echo "$0: ERROR: not a non-empty file: $DOT_PATH" 1>&2
EXIT_CODE="7" # exit 7
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -559,43 +574,26 @@ for YYYY in $(< "$TOP_FILE"); do
if [[ $YYYY_DIR != "$DOT_PATH_CONTENT" ]]; then
echo "$0: ERROR: arg: $YYYY_DIR does not match $DOT_PATH contents: $DOT_PATH_CONTENT" 1>&2
EXIT_CODE="7" # exit 7
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
export ENTRY_JSON="$YYYY_DIR/.entry.json"
if [[ ! -e $ENTRY_JSON ]]; then
echo "$0: ERROR: .entry.json does not exist: $ENTRY_JSON" 1>&2
EXIT_CODE="7" # exit 7
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -f $ENTRY_JSON ]]; then
echo "$0: ERROR: .entry.json is not a file: $ENTRY_JSON" 1>&2
EXIT_CODE="7" # exit 7
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
if [[ ! -r $ENTRY_JSON ]]; then
echo "$0: ERROR: .entry.json is not a readable file: $ENTRY_JSON" 1>&2
EXIT_CODE="7" # exit 7
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
# process all markdown files that are NOT README.md for this entry
# process all markdown files that are NOT README.md (nor remarks.md) for this entry
#
find "$YYYY_DIR" -type f -name '*.md' ! -name README.md | while read -r MD_FILE; do
find "$YYYY_DIR" -type f -name '*.md' ! -name README.md ! -name remarks.md | while read -r MD_FILE; do
# basename of MD_FILE
# determine HTML filename
#
MD_BASENAME=$(basename "$MD_FILE")
export MD_BASENAME
# determine the HTML file
#
export HTML_FILE=${MD_FILE//\.md/.html}
HTML_BASENAME=$(basename "$HTML_FILE")
export HTML_BASENAME
if [[ $MD_FILE =~ (.*)\.md$ ]]; then
export HTML_FILE="${BASH_REMATCH[1]}.html"
else
echo "$0: ERROR: markdown file does not end in .md: $MD_FILE" 1>&2
EXIT_CODE="7" # exit 7
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
# case: -Q (quick mode)
#
@@ -617,79 +615,22 @@ for YYYY in $(< "$TOP_FILE"); do
fi
fi
# determine the description arg
#
export DESCRIPTION="DESCRIPTION=$MD_BASENAME for $YYYY_DIR"
# determine the keywords arg
#
KEYWORDS="KEYWORDS=IOCCC, $YYYY_DIR, $MD_BASENAME"
export KEYWORDS
# determine the HEADER_2 arg
#
export HEADER_2="HEADER_2=$HTML_BASENAME for $YYYY_DIR"
# determine the number of levels in path of MD_FILE from topdir
#
export NO_SLASH=${MD_FILE///}
LEVEL_CNT=$((${#MD_FILE} - ${#NO_SLASH}))
export LEVEL_CNT
if [[ $LEVEL_CNT -lt 2 ]]; then
echo "$0: ERROR: expected at least 2 level from topdir: $TOPDIR to MD_FILE: $MD_FILE, found $LEVEL_CNT" 1>&2
echo 12 > "$TMP_EXIT_CODE" # exit 12
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
((SUB_LEVEL_CNT=LEVEL_CNT-2))
export SUB_LEVEL_CNT
# determine -D option string and path to entry index.html file
#
export D_OPTION="../../"
export INDEX_PATH="index.html"
for ((n=0; n<SUB_LEVEL_CNT; ++n)); do
D_OPTION="../$D_OPTION"
INDEX_PATH="../$INDEX_PATH"
done
# determine the UP_LINK
#
export UP_LINK="UP_LINK=$INDEX_PATH"
# determine UP_TEXT
#
export UP_TEXT="UP_TEXT=jump to index.html"
# run the MD2HTML_SH tool unless -n
# run the OTHERMD2HTML tool unless -n
#
if [[ -z $NOOP ]]; then
# possibly update the HTML file
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: about to run: $MD2HTML_SH ${TOOL_OPTION[*]}" \
"-U $SITE_URL/$HTML_FILE" \
"-s $DESCRIPTION -s $KEYWORDS -s $HEADER_2" \
"-s REPO_URL=$REPO_URL -s SITE_URL=$SITE_URL" \
"-s $UP_LINK -s $UP_TEXT -D $D_OPTION -m $MD_FILE -v $V_FLAG --" \
"$MD_FILE $HTML_FILE" 1>&2
echo "$0: debug[3]: about to run: $OTHERMD2HTML ${TOOL_OPTION[*]} -- $MD_FILE" 1>&2
fi
"$MD2HTML_SH" "${TOOL_OPTION[@]}" \
-U "$SITE_URL/$HTML_FILE" \
-s "$DESCRIPTION" -s "$KEYWORDS" -s "$HEADER_2" \
-s "REPO_URL=$REPO_URL" -s "SITE_URL=$SITE_URL" \
-s "$UP_LINK" -s "$UP_TEXT" -D "$D_OPTION" -m "$MD_FILE" -v "$V_FLAG" -- \
"$MD_FILE" "$HTML_FILE"
"$OTHERMD2HTML" "${TOOL_OPTION[@]}" -- "$MD_FILE"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: tool: $MD2HTML_SH ${TOOL_OPTION[*]}" \
"-U $SITE_URL/$HTML_FILE" \
"-s $DESCRIPTION -s $KEYWORDS -s $HEADER_2" \
"-s REPO_URL=$REPO_URL -s SITE_URL=$SITE_URL" \
"-s $UP_LINK -s $UP_TEXT -D $D_OPTION -m $MD_FILE -v $V_FLAG --" \
"$MD_FILE $HTML_FILE failed, error: $status" 1>&2
echo 1 > "$TMP_EXIT_CODE" # exit 1
echo "$0: ERROR: tool: $OTHERMD2HTML ${TOOL_OPTION[*]} -- $MD_FILE" \
"failed, error: $status" 1>&2
EXIT_CODE="1" # exit 1
echo "$EXIT_CODE" > "$TMP_EXIT_CODE"
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
continue
fi
@@ -707,20 +648,16 @@ for YYYY in $(< "$TOP_FILE"); do
# report disabled by -n
#
elif [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: because of -n, did not run: $MD2HTML_SH ${TOOL_OPTION[*]}" \
"-s $DESCRIPTION -s $KEYWORDS -s $HEADER_2" \
"-s $UP_LINK -s $UP_TEXT -D $D_OPTION -m $MD_FILE -v $V_FLAG --" \
echo "$0: debug[5]: because of -n, did not run: $OTHERMD2HTML ${TOOL_OPTION[*]} --" \
"$MD_FILE $HTML_FILE" 1>&2
fi
done
done
done
if [[ -z $NOOP ]]; then
EXIT_CODE=$(< "$TMP_EXIT_CODE")
if [[ -z $EXIT_CODE ]]; then
echo "$0: ERROR: temporary exit file has no contents: $TMP_EXIT_CODE" 1>&2
exit 13
fi
EXIT_CODE=$(< "$TMP_EXIT_CODE")
if [[ -z $EXIT_CODE ]]; then
echo "$0: ERROR: temporary exit file has no contents: $TMP_EXIT_CODE" 1>&2
exit 13
fi