improve markdown to HTML tools, build location.html, authors.html, years.html

Renamed `.winner.json` to `.entry.json` as per recent decisions made for issue #2156.

JSON element _winner_JSON_format_version_ renamed to _entry_JSON_format_version_
in `.winner.json`.

Changed _entry_JSON_format_version_ from "1.0 2024-01-14" to "1.1 2024-02-11".

JSON element _winner_id_ renamed to _entry_id_ in `.entry.json`
JSON element _winner_text renamed to _entry_text_ in `.entry.json`
JSON element _winner_id_ renamed to _entry_id_ in `author/author_handle.json` files.

Changed _author_JSON_format_version_ from "1.0 2023-06-10" to "1.1 2024-02-11".

Renamed `tmp/gen_winner_json.sh` to `tmp/gen_entry_json.sh`.

Renamed `tmp/example.dot_winner.json` to `tmp/example.dot_entry.json`.

Renamed `tmp/winner_id.txt` to `tmp/entry_id.txt`.

Renamed `tmp/winner_dir.txt` to `tmp/entry_dir.txt`.

Moved outdated `tmp/awards_check.sh` into `tmp/OLD_manifest/awards_check.sh`.
Moved outdated `tmp/awards_check.sh` into `tmp/OLD_manifest/awards_check.sh`.
Moved outdated `tmp/src/winner_name` into `tmp/OLD_manifest/winner_name`.
Moved outdated `tmp/sql` into `tmp/OLD_manifest/sql`.
Moved outdated `tmp/template-footer.html` into `tmp/OLD_manifest/template-footer.html`.
Moved outdated `tmp/template-header.html` into `tmp/OLD_manifest/template-header.html`.
Moved outdated `tmp/template-top.html` into `tmp/OLD_manifest/template-top.html`.
Moved outdated `tmp/test.html` into `tmp/OLD_manifest/test.html`.
Moved outdated `tmp/fake.gen_index.sh` into `tmp/OLD_manifest/fake.gen_index.sh`.
Moved outdated `tmp/old-ioccc.css` into `tmp/OLD_manifest/old-ioccc.css`.

Removed winner_name from `tmp/src/Makefile`.

Updated `tmp/example.dot_entry.json` to reflect the above JSON changes.

Updated `tmp/manifest.numbers` to reflect the above JSON changes.

Updated `tmp/README.md` to reflect the above JSON changes.
Sorted `tmp/README.md` by existing `tmp` filenames.

Updated all `.entry.json` files to reflect the above JSON changes.

Updated all `author/author_handle.json` files to reflect the above JSON changes.

Added new tool `bin/gen-location.sh` to form the top level file `location.html`
from `author/author_handle.json` files!

Added new tool `bin/gen-years.sh` to form the top level file `years.html`
using `.top`, `.year` and `.entry.json' files!

Added new tool `bin/gen-authors.sh` to form a new top level file
`/authors.html` from `author/author_handle.json` and related
`.entry.json' files!

The old `winners.html` file now redirects to the new `authors.html` file.

Renamed `bin/gen-author.sh` to `bin/output-index-author.sh`.
Renamed `bin/subst.winner-index.sh` to `subst.entry-index.sh`.
Renamed `bin/subst.winner-index.awk` to `subst.entry-index.awk`.
Renamed `bin/manifest.entry.json.awk` to `bin/manifest.entry.json.awk`.
Renamed `bin/gen-inventory.sh` to `bin/output-index-inventory.sh`.
Renamed `bin/sort.gitignore` to `bin/sort.gitignore.sh`.
Renamed `bin/sgi` to `bin/sgi.sh`.

The core logic of converting markdown to HTML has been
generalized into a new `bin/md2html.sh` tool.

The `bin/readme2index.sh` tool now calls the
new `bin/md2html.sh` tool to form entry's `index.html` files.

The `bin/quick-readme2index.sh` tool now calls the new `bin/md2html.sh`
tool, unless the `index.html` is newer than both `.entry.json` and
`README.md`, to form entry `index.html` files.

Increased, slightly, the speed of the `bin/quick-readme2index.sh` tool
with the entry's `index.html` file does not need to be updated.

The `bin/quick-readme2index.sh` tool will touch the `index.html` file,
even if the `bin/md2html.sh` tool determines that the `index.html` file
did not change, so that the `index.html` file will not appear
out of date with respect to `.entry.json`.

Slightly improved the look and feel of `index.html` files for entries.

The logic of `bin/all-run.sh` has been improved.  The initial
processing, from first bash version check, thru the -N test, serves
as the model for the `bin/readme2index.sh` tool and the
`bin/quick-readme2index.sh` tool.  There tools now share
a common set of command line options.

Changed the format of `inc/md2html.cfg` so that for a given "_file_glob_"
match, options follow, one per line.  The "_file_glob_" is on a line
by itself.  The option lines that follow must be intended:

```
[12][0-9][0-9][0-9]/README.md
	-H
	topnav=year
	-o
	bin/subst.default.sh
	-o
	bin/subst.year.sh
```

Added "-D ./" to top level markdown files in `inc/md2html.cfg`.

The above intending is performed with 1 or more whitespace
characters, although we use a leading tab "convention"
out of deference to Makefile formats. :-)

Once a new "_file_glob_" is found, the set of any previous
option lines is said to have ended.

The general argument processing logic now makes used of shell arrays.

Added checks in the `bin/md2html.sh` tool to disallow a "_file_glob_"
of . (dot) as this is used internally to help the shell process the
new `inc/md2html.cfg` format.

Changed `bin/all-run.sh` VERSION from "1.1.2 2024-01-20"
to "1.3 2024-02-11".

Changed `bin/output-index-author.sh` VERSION from "1.3.1 2024-01-16"
to "1.4 2024-02-11".

Changed `bin/pandoc-wrapper.sh` VERSION from "1.3.2 2024-01-19"
to "1.4 2024-02-05".

Changed `bin/quick-readme2index.sh` VERSION from "1.0 2024-01-20"
to "1.1 2024-02-11".

Changed `bin/readme2index.sh` VERSION from "1.1.1 2024-01-20"
to "1.2 2024-02-11".

Changed `bin/subst.default.sh` VERSION from "1.1.1 2024-01-16"
to "1.2 2024-02-05".

Changed `bin/subst.entry-index.sh` VERSION from "1.1.1 2024-01-16
to "1.2 2024-02-11".

Changed `bin/output-index-inventory.sh` VERSION from "1.0.1 2024-01-16"
to "1.1 2024-02-11".

Changed `bin/manifest.entry.json.awk` from "1.0 2024-01-14"
to "1.1 2024-02-11".

Changed `bin/sort.gitignore.sh` from "1.0 2024-02-01"
to "1.1 2024-02-11".

Changed substitution symbol _%%DOCROOT_URL_SLASH%%_ to _%%DOCROOT_SLASH%%_
in various "inc/*.html" files.

Moved setting of symbol _%%DOCROOT_SLASH%%_ from `bin/subst.entry-index.sh`
to `bin/subst.default.sh`.

Changed the variable _$DOCROOT_URL_SLASH_ to _$DOCROOT_SLASH_, in
bin tools that use it, to be more descriptive.

Removed `-P pandoc_opts` from `bin/*.sh` command lines.
The PANDOC_WRAPPER_OPTSTR value is only used in `bin/pandoc-wrapper.sh`.

Removed `-B optstr` and `-A optstr` from the `bin/md2html.sh` command line.

Removed `[-O tool=optstr ..]` from the `bin/md2html.sh` command line.

Removed old use of `-U top_url` from command lines.
Add `-w site_url` as sort of a "replacement" for the old `-U top_url`.

Added a new `-U URL` to `bin/gen-author.sh`, `bin/output-index-inventory.sh`,
`bin/md2html.sh`, `bin/subst.default.sh`, and `bin/subst.entry-index.sh`
to allow for the Nu HTML check can use the encoded absolute URL of
the HTML page.

Added `-t tagline` to most command lines.

Added `-T md2html.sh` to most command lines.

Added `-D docroot/` to most command lines to set DOCROOT_SLASH.
The DOCROOT_SLASH value defaults to "../../" for most in tools,
suitable for HTML files under a `YYYY/dir` directory, except for
`bin/gen-location.sh` and `gen-entries-html.sh` (as this produces a
top level HTML file) and `bin/md2html.sh` (forms files at any level)
who use "./" instead.

In the case of `bin/output-index-inventory.sh`, `bin/quick-readme2index.sh`,
`bin/readme2index.sh`, and `bin/all-run.sh`

Helped make the use of exit code in bin tools a bit more consistent.

Fixed a number of typos in the bin tools.

Added comments for lower level tools such as
`manifest.entry.json.awk`, `bin/subst.default.sh`,
`bin/subst.entry-index.sh`, and bin/`manifest.entry.json.awk` to
indicate how they are usually invoked by other tools.

Changed the comments that a new `bin/md2html.sh` tool (that was the
`bin/readme2index.sh` tool) would add to a entry's `index.html` file.
No longer will it add the tool version number to the comment.  Thus,
a change in tool version will not force all entry `index.html`
files to be modified.  Now both the tool adds two comments, one
is the _tagline_ to indicate how the markdown content was generated,
and one for the new `bin/md2html.sh` tool.  For example:

```
<!-- The original markdown content was formed by the tool: bin/quick-readme2index.sh -->
<!-- The HTML was converted from markdown by the tool: bin/md2html.sh -->
```

Improve the debugging, especially in regards to changing important
exported shell variables, in `bin/md2html.sh`.  Other bin tools
have their exported shell variables improved somewhat as well.

The `bin/README.md` now describes the general _converting markdown
to HTML_ procedure including _getopt phases_ and _HTML phases_.
Content from `inc/md2html.cfg` and `bin/readme2index.sh` that related
to this topic has been centralized into the `bin/README.md` file.

Improved formatting of the `bin/README.md` file.  Updated it as needed
according to the above.

Sorted `2011/.year`, `2018/.year`, and `2019/.year` to be in dictionary order.
Adjusted ${WINNERS} in year Makefile to use dictionary order so
that `make genpath` will produce `.year` files in dictionary order.

FYI: We tested this massive set of changes as best as we could.
     Nevertheless we might have missing something in the JSON changes,
     `.entry.json` renames, manifest updates, code comments, etc.
This commit is contained in:
Landon Curt Noll committed 2024-02-11 16:00:31 -08:00
1 parent b23ab491ca
commit aedb017223
897 files changed
+29985 -27475

No files matched your search

+303 -276
View File
@@ -2,21 +2,14 @@
#
# quick-readme2index.sh - quickly determine if readme2index.sh needs to be run
#
# If yyyy/dir/.winner.json exists and was modified newer than
# yyyy/dir/index.html or of yyyy/dir/index.html does not exist,
# then readme2index.sh will be run using the yyyy/dir option.
# If YYYY/dir/.entry.json exists and was modified newer than
# YYYY/dir/index.html or if YYYY/dir/index.html does not exist,
# then we will form YYYY/dir/index.html using the bin/md2html.sh tool.
#
# If yyyy/dir/.winner.json does not exist, then an error will thrown.
# If YYYY/dir/.entry.json does not exist, then an error will thrown.
#
# If yyyy/dir/.winner.json exists and was modified same or older than
# yyyy/dir/index.html, then nothing will happen.
#
# This tool has only has command line options also found in all-run.sh,
# which is a subset of the command line options available to readme2index.sh.
#
# If `index.html` is not a non-empty file, or of either `.winner.json`
# and/or `README.md` is newer than `index.html`, only then `readme2index.sh`
# is executed.
# If YYYY/dir/.entry.json exists and was modified the same or older than
# YYYY/dir/index.html, then nothing will happen.
#
# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved.
#
@@ -44,15 +37,7 @@
# 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
# firewall - must be bash with a version 4.2 or later
#
# We must declare arrays with -ag or -Ag
# We must declare arrays with -ag or -Ag, and we need loops to "export" modified variables.
#
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
@@ -73,14 +58,14 @@ shopt -s globstar # enable ** to match all files and zero or more directories an
# set variables referenced in the usage message
#
export VERSION="1.0 2024-01-20"
export VERSION="1.1 2024-02-11"
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
echo "$0: FATAL: git tool is not installed or not in \$PATH" 1>&2
exit 10
fi
"$GIT_TOOL" rev-parse --is-inside-work-tree >/dev/null 2>&1
@@ -88,27 +73,35 @@ status="$?"
if [[ $status -eq 0 ]]; then
TOPDIR=$("$GIT_TOOL" rev-parse --show-toplevel)
fi
export DOCROOT_SLASH="../../"
# We use the tagline of "bin/readme2index.sh" instead of:
#
# export TAGLINE="bin/$NAME"
#
# because we do not want the "markdown content was formed by" comment
# in index.html to change just because we used this "bin/quick-readme2index.sh"
# instead of the slightly-slower "bin/readme2index.sh" tool.
#
export TAGLINE="bin/readme2index.sh"
export MD2HTML_SH="bin/md2html.sh"
export PANDOC_WRAPPER="bin/pandoc-wrapper.sh"
export PANDOC_WRAPPER_OPTSTR="-f markdown -t html --fail-if-warnings=true"
export REPO_URL="https://github.com/ioccc-src/temp-test-ioccc"
export TOP_URL="https://ioccc-src.github.io/temp-test-ioccc"
export DOCROOT_URL_SLASH="/temp-test-ioccc/"
export SITE_URL="https://ioccc-src.github.io/temp-test-ioccc"
#
export NOOP=
export DO_NOT_PROCESS=
export EXIT_CODE="0"
# clear options we will add to tools
#
export V_FLAG_FOUND=
export P_FLAG_FOUND=
export CAP_P_FLAG_FOUND=
export U_FLAG_FOUND=
export CAP_U_FLAG_FOUND=
unset TOOL_OPTION
declare -ag TOOL_OPTION
# usage
#
export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-n] [-N]
[-p tool] [-P optstr] [-u repo_url] [-U top_url] [-e string ..] [-E exitcode]
tool [tool_options]
export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-D docroot/] [-n] [-N]
[-t tagline] [-T md2html.sh] [-p tool] [-u repo_url] [-w site_url]
tool [more_options]
-h print help message and exit
-v level set verbosity level (def level: 0)
@@ -116,36 +109,41 @@ export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-n] [-N]
-d topdir set topdir (def: $TOPDIR)
NOTE: The '-d topdir' is passed as leading options on tool command lines.
-D docroot/ set the document root path followed by slash (def: $DOCROOT_SLASH)
NOTE: The '-D docroot/' is passed as leading options on tool command lines.
NOTE: 'docroot' must end in a slash
-n go thru the actions, but do not update any files (def: do the action)
NOTE: -n is passed to tool
-N do not process file, just parse arguments and ignore the file (def: process the file)
NOTE: -N disables running a tool
-N do not process anything, just parse arguments (def: process something)
-t tagline string to write about the tool that formed the markdown content (def: $TAGLINE)
NOTE: 'pandoc_opts' may be enclosed within, but may NOT contain an internal single-quote or double-quote.
-T md2html.sh run 'markdown to html tool' to convert markdown into HTML (def: $MD2HTML_SH)
-p tool run 'pandoc wrapper tool' (not pandoc path) during HTML phase number 21 (def: use $PANDOC_WRAPPER)
NOTE: The '-p tool' is passed as leading options on tool command lines.
-P pandoc_opts run 'pandoc wrapper tool' with options found in 'optstr' (def: $PANDOC_WRAPPER_OPTSTR)
NOTE: The '-P pandoc_opts' is passed as leading options on tool command lines.
NOTE: The 'pandoc_opts' may not contain a single-quote or a double-quote.
-u repo_url Base level URL of target git repo (def: $REPO_URL)
NOTE: The '-u repo_url' is passed as leading options on tool command lines.
-U top_url Top level URL of web site where HTML files will be viewed (def: $TOP_URL)
NOTE: The '-U top_url' is passed as leading options on tool command lines.
-w site_url Base URL of the web site (def: $SITE_URL)
NOTE: The '-w site_url' is passed as leading options on tool command lines.
tool the tool to run over all winners
tool_options tool command line options to use before YYYY/dir
[more_options] additional tool command line options to use before the YYYY/dir argument
NOTE: Any '-t tagline', '-T md2html.sh', '-p tool', '-P pandoc_opts', '-u repo_url', '-U top_url'
are passed to the 'tool' at the beginning of the command line, and
before any optional 'more_options' and before the final YYYY/dir argument.
Exit codes:
0 all OK
1 readme2index.sh exited non-zero
1 some tool 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 readme2index.sh tool executable not found
6 topdir, topdir/YYYY, or topdir/YYYY/dir is not in proper form
7 missing non-empty readable .winner.json file
8 missing non-empty readable README.md file
5 tool and/or md2html.sh is not an executable file
6 problems found with or in the topdir directory
7 problems found with or in the topdir/YYYY directory
8 problems found with or in the topdir/YYYY/dir directory
>= 10 < 200 internal error
>= 200 ((not used))
@@ -153,49 +151,70 @@ $NAME version: $VERSION"
# parse command line
#
while getopts :hv:Vd:nNp:P:u:U: flag; do
while getopts :hv:Vd:D:nNt:T:p:u:w: flag; do
case "$flag" in
h) echo "$USAGE" 1>&2
exit 2
;;
v) V_FLAG="$OPTARG"
V_FLAG_FOUND="-v"
;;
V) echo "$VERSION"
exit 2
;;
d) TOPDIR="$OPTARG"
;;
D) # parse -D docroot/
case "$OPTARG" in
*/) ;;
*) echo "$0: ERROR: in -D docroot/, the docroot must end in /" 1>&2
echo 1>&2
print_usage 1>&2
exit 3
;;
esac
DOCROOT_SLASH="$OPTARG"
TOOL_OPTION+=("-D")
TOOL_OPTION+=("$DOCROOT_SLASH")
;;
n) NOOP="-n"
;;
N) DO_NOT_PROCESS="-N"
;;
p) PANDOC_WRAPPER="$OPTARG"
P_FLAG_FOUND="-p" ;;
P) # parse -P optstr
t) # parse -t tagline
case "$OPTARG" in
*"'"*)
echo "$0: ERROR: in -P optstr, the optstr may not contain a single-quote character: $OPTARG" 1>&2
echo "$0: ERROR: in -t tagline, the tagline may not contain a single-quote character: $OPTARG" 1>&2
echo 1>&2
print_usage 1>&2
exit 3
;;
*'"'*)
echo "$0: ERROR: in -P optstr, the optstr may not contain a double-quote character: $OPTARG" 1>&2
echo "$0: ERROR: in -t tagline, the tagline may not contain a double-quote character: $OPTARG" 1>&2
echo 1>&2
print_usage 1>&2
exit 3
;;
*) ;;
esac
PANDOC_WRAPPER_OPTSTR="$OPTARG"
CAP_P_FLAG_FOUND="-P"
TAGLINE="$OPTARG"
TOOL_OPTION+=("-t")
TOOL_OPTION+=("$TAGLINE")
;;
T) MD2HTML_SH="$OPTARG"
TOOL_OPTION+=("-T")
TOOL_OPTION+=("$MD2HTML_SH")
;;
p) PANDOC_WRAPPER="$OPTARG"
TOOL_OPTION+=("-p")
TOOL_OPTION+=("$PANDOC_WRAPPER")
;;
u) REPO_URL="$OPTARG"
U_FLAG_FOUND="-u"
TOOL_OPTION+=("-u")
TOOL_OPTION+=("$REPO_URL")
;;
U) TOP_URL="$OPTARG"
CAP_U_FLAG_FOUND="-U"
w) SITE_URL="$OPTARG"
TOOL_OPTION+=("-w")
TOOL_OPTION+=("$SITE_URL")
;;
\?) echo "$0: ERROR: invalid option: -$OPTARG" 1>&2
echo 1>&2
@@ -214,79 +233,91 @@ while getopts :hv:Vd:nNp:P:u:U: flag; do
;;
esac
done
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: debug level: $V_FLAG" 1>&2
fi
#
# remove the options
#
shift $(( OPTIND - 1 ));
#
# verify arg count and parse args
#
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: file argument count: $#" 1>&2
fi
#
# verify arg count and parse args
if [[ $# -ne 1 ]]; then
echo "$0: ERROR: expected 1 arg, found: $#" 1>&2
exit 3
fi
#
export TOOL_OPTIONS
export WINNER_PATH
case "$#" in
0) echo "$0: ERROR: expected 1 or more args, found: $#" 1>&2
echo "$USAGE" 1>&2
exit 3
;;
1) WINNER_PATH="$1"
shift
;;
*) WINNER_PATH="$1"
shift
TOOL_OPTIONS="$*"
;;
esac
# clear options we will add to the tool
#
export OPTSTR=
# add '-p tool' options to tool arguments
#
if [[ -n $P_FLAG_FOUND && -n $PANDOC_WRAPPER ]]; then
if [[ -z $OPTSTR ]]; then
OPTSTR="-p \"$PANDOC_WRAPPER\""
else
OPTSTR="$OPTSTR -p \"$PANDOC_WRAPPER\""
fi
export WINNER_PATH="$1"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: WINNER_PATH=$WINNER_PATH" 1>&2
fi
# add '-P optstr' options to tool arguments
# always add the '-v level' option, unless level is empty, to the set of options passed to the md2html.sh tool
#
if [[ -n $CAP_P_FLAG_FOUND && -n $PANDOC_WRAPPER_OPTSTR ]]; then
if [[ -z $OPTSTR ]]; then
OPTSTR="-P \"$PANDOC_WRAPPER_OPTSTR\""
else
OPTSTR="$OPTSTR -P \"$PANDOC_WRAPPER_OPTSTR\""
fi
if [[ -n $V_FLAG ]]; then
TOOL_OPTION+=("-v")
TOOL_OPTION+=("$V_FLAG")
fi
# add '-u repo_url' options to tool arguments
# always add the '-t tagline' option, unless tagline is empty, to the set of options passed to the md2html.sh tool
#
if [[ -n $U_FLAG_FOUND && -n $REPO_URL ]]; then
if [[ -z $OPTSTR ]]; then
OPTSTR="-u \"$REPO_URL\""
else
OPTSTR="$OPTSTR -u \"$REPO_URL\""
fi
if [[ -n $TAGLINE ]]; then
TOOL_OPTION+=("-t")
TOOL_OPTION+=("$TAGLINE")
fi
# add '-U top_url' options to tool arguments
# parse the WINNER_PATH arg
#
if [[ -n $CAP_U_FLAG_FOUND && -n $TOP_URL ]]; then
if [[ -z $OPTSTR ]]; then
OPTSTR="-U \"$TOP_URL\""
else
OPTSTR="$OPTSTR -U \"$TOP_URL\""
fi
# verify that WINNER_PATH is in proper form
#
# Also obtain the YEAR_DIR and WINNER_DIR from WINNER_PATH.
#
if [[ -z $WINNER_PATH ]]; then
echo "$0: ERROR: arg is an empty string" 1>&2
exit 3
fi
if [[ ! -d $WINNER_PATH ]]; then
echo "$0: ERROR: arg is not a directory: $WINNER_PATH" 1>&2
exit 3
fi
if [[ ! -w $WINNER_PATH ]]; then
echo "$0: ERROR: arg is not a writable directory: $WINNER_PATH" 1>&2
exit 3
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 3
fi
if [[ ! -d $YEAR_DIR ]]; then
echo "$0: ERROR: YYYY from arg: $WINNER_PATH is not a directory: $YEAR_DIR" 1>&2
exit 3
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 3
fi
if [[ $WINNER_DIR = */* ]]; then
echo "$0: ERROR: dir from arg: $WINNER_PATH contains a /: $WINNER_DIR" 1>&2
exit 3
fi
# verify that the md2html tool is executable
#
if [[ ! -e $MD2HTML_SH ]]; then
echo "$0: ERROR: md2html.sh does not exist: $MD2HTML_SH" 1>&2
exit 5
fi
if [[ ! -f $MD2HTML_SH ]]; then
echo "$0: ERROR: md2html.sh is not a regular file: $MD2HTML_SH" 1>&2
exit 5
fi
if [[ ! -x $MD2HTML_SH ]]; then
echo "$0: ERROR: md2html.sh is not an executable file: $MD2HTML_SH" 1>&2
exit 5
fi
# verify that we have a topdir directory
@@ -298,39 +329,17 @@ if [[ -z $TOPDIR ]]; then
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 6
fi
if [[ ! -e $TOPDIR ]]; then
echo "$0: ERROR: TOPDIR does not exist: $TOPDIR" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 6
fi
if [[ ! -d $TOPDIR ]]; then
echo "$0: ERROR: TOPDIR is not a directory: $TOPDIR" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 6
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 6
fi
export AUTHOR_DIR="author"
# verify that we have an inc subdirectory
#
export INC_PATH="$TOPDIR/inc"
if [[ ! -d $INC_PATH ]]; then
echo "$0: ERROR: inc is not a directory under topdir: $INC_PATH" 1>&2
exit 6
fi
export INC_DIR="inc"
# verify that we have an bin subdirectory
#
export BIN_PATH="$TOPDIR/bin"
if [[ ! -d $BIN_PATH ]]; then
echo "$0: ERROR: bin is not a directory under topdir: $BIN_PATH" 1>&2
exit 6
fi
export BIN_DIR="bin"
# cd to topdir
#
if [[ ! -e $TOPDIR ]]; then
@@ -354,183 +363,201 @@ 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
# perform tests on YYYY_DIR (YYYY/dir) as 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 6
fi
if [[ ! -w $WINNER_PATH ]]; then
echo "$0: ERROR: arg is not a writable directory: $WINNER_PATH" 1>&2
exit 6
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 6
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 6
fi
if [[ $WINNER_DIR = */* ]]; then
echo "$0: ERROR: dir from arg: $WINNER_PATH contains a /: $WINNER_DIR" 1>&2
exit 6
fi
if [[ ! -d $YEAR_DIR ]]; then
echo "$0: ERROR: yyyy from arg: $WINNER_PATH is not a directory: $YEAR_DIR" 1>&2
exit 6
fi
export WINNER_ID="${YEAR_DIR}_${WINNER_DIR}"
export DOT_YEAR="$YEAR_DIR/.year"
if [[ ! -e $DOT_YEAR ]]; then
echo "$0: ERROR: in $WINNER_PATH .year does not exist: $DOT_YEAR" 1>&2
exit 7
fi
if [[ ! -f $DOT_YEAR ]]; then
echo "$0: ERROR: in $WINNER_PATH .year is not a file: $DOT_YEAR" 1>&2
exit 7
fi
if [[ ! -r $DOT_YEAR ]]; then
echo "$0: ERROR: in $WINNER_PATH .year is not a readable file: $DOT_YEAR" 1>&2
exit 7
fi
if [[ ! -s $DOT_YEAR ]]; then
echo "$0: ERROR: not a non-empty file: $DOT_YEAR" 1>&2
exit 6
echo "$0: ERROR: in $WINNER_PATH .year is not a non-empty readable file: $DOT_YEAR" 1>&2
exit 7
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 6
# Now that we have moved to topdir, form and verify YYYY_DIR is a writable directory
export YYYY_DIR="$YEAR_DIR/$WINNER_DIR"
if [[ ! -e $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY/dir from arg: $WINNER_PATH does not exist: $YYYY_DIR" 1>&2
exit 7
fi
if [[ ! -d $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY/dir from arg: $WINNER_PATH is not a directory: $YYYY_DIR" 1>&2
exit 7
fi
if [[ ! -w $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY/dir from arg: $WINNER_PATH is not a writable directory: $YYYY_DIR" 1>&2
exit 7
fi
export DOT_PATH="$YYYY_DIR/.path"
if [[ ! -e $DOT_PATH ]]; then
echo "$0: ERROR: in $WINNER_PATH .path does not exist: $DOT_PATH" 1>&2
exit 8
fi
if [[ ! -f $DOT_PATH ]]; then
echo "$0: ERROR: in $WINNER_PATH .path is not a file: $DOT_PATH" 1>&2
exit 8
fi
if [[ ! -r $DOT_PATH ]]; then
echo "$0: ERROR: in $WINNER_PATH .path is not a readable file: $DOT_PATH" 1>&2
exit 8
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 6
echo "$0: ERROR: in $WINNER_PATH .path is not a non-empty readable file: $DOT_PATH" 1>&2
exit 8
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 6
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 7
fi
if [[ ! -f $WINNER_JSON ]]; then
echo "$0: ERROR: .winner.json is not a file: $WINNER_JSON" 1>&2
exit 7
fi
if [[ ! -r $WINNER_JSON ]]; then
echo "$0: ERROR: .winner.json is not a readable file: $WINNER_JSON" 1>&2
exit 7
fi
if [[ ! -s $WINNER_JSON ]]; then
echo "$0: ERROR: .winner.json is not a non-empty readable file: $WINNER_JSON" 1>&2
exit 7
fi
export README_MD="$YEAR_DIR/$WINNER_DIR/README.md"
if [[ ! -e $README_MD ]]; then
echo "$0: ERROR: README.md does not exist: $README_MD" 1>&2
echo "$0: ERROR: in $WINNER_PATH .path: $DOT_PATH contents: $DOT_PATH_CONTENT" 1>&2
exit 8
fi
if [[ ! -f $README_MD ]]; then
echo "$0: ERROR: README.md is not a file: $README_MD" 1>&2
exit 8
fi
if [[ ! -r $README_MD ]]; then
echo "$0: ERROR: README.md is not a readable file: $README_MD" 1>&2
exit 8
fi
if [[ ! -s $README_MD ]]; then
echo "$0: ERROR: README.md is not a non-empty readable file: $README_MD" 1>&2
exit 8
fi
export INDEX_HTML="$YEAR_DIR/$WINNER_DIR/index.html"
# determine our readme2index.sh tool path
# setup README_PATH and INDEX_PATH using YYYY_DIR
#
export TOOL="$BIN_DIR/readme2index.sh"
export README_PATH="$YYYY_DIR/README.md"
export INDEX_PATH="$YYYY_DIR/index.html"
if [[ ! -e $README_PATH ]]; then
echo "$0: ERROR: in $WINNER_PATH README.md does not exist: $README_PATH" 1>&2
exit 8
fi
if [[ ! -f $README_PATH ]]; then
echo "$0: ERROR: in $WINNER_PATH README.md is not a file: $README_PATH" 1>&2
exit 8
fi
if [[ ! -r $README_PATH ]]; then
echo "$0: ERROR: in $WINNER_PATH README.md is not a readable file: $README_PATH" 1>&2
exit 8
fi
if [[ ! -s $README_PATH ]]; then
echo "$0: ERROR: in $WINNER_PATH README.md is not a non-empty readable file: $README_PATH" 1>&2
exit 8
fi
# verify tool is executable
# verify that .entry.json is a non-empty readable file
#
if [[ ! -e $TOOL ]]; then
echo "$0: ERROR: TOOL does not exist: $TOOL" 1>&2
exit 5
export ENTRY_JSON="$YYYY_DIR/.entry.json"
if [[ ! -e $ENTRY_JSON ]]; then
echo "$0: ERROR: in $WINNER_PATH .entry.json does not exist: $ENTRY_JSON" 1>&2
exit 8
fi
if [[ ! -f $TOOL ]]; then
echo "$0: ERROR: TOOL is not a regular file: $TOOL" 1>&2
exit 5
if [[ ! -f $ENTRY_JSON ]]; then
echo "$0: ERROR: in $WINNER_PATH .entry.json is not a file: $ENTRY_JSON" 1>&2
exit 8
fi
if [[ ! -x $TOOL ]]; then
echo "$0: ERROR: TOOL is not an executable file: $TOOL" 1>&2
exit 5
if [[ ! -r $ENTRY_JSON ]]; then
echo "$0: ERROR: in $WINNER_PATH .entry.json is not a readable file: $ENTRY_JSON" 1>&2
exit 8
fi
if [[ ! -s $ENTRY_JSON ]]; then
echo "$0: ERROR: in $WINNER_PATH .entry.json is not a non-empty readable file: $ENTRY_JSON" 1>&2
exit 8
fi
# parameter debugging
# always add the '-U URL' for the winner index.html file
#
TOOL_OPTION+=("-U")
TOOL_OPTION+=("$SITE_URL/$YYYY_DIR/index.html")
# print running info if verbose
#
# If -v 3 or higher, print exported variables in order that they were exported.
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: VERSION=$VERSION" 1>&2
echo "$0: debug[3]: NAME=$NAME" 1>&2
echo "$0: debug[3]: V_FLAG=$V_FLAG" 1>&2
echo "$0: debug[3]: GIT_TOOL=$GIT_TOOL" 1>&2
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]: MD2HTML_SH=$MD2HTML_SH" 1>&2
echo "$0: debug[3]: PANDOC_WRAPPER=$PANDOC_WRAPPER" 1>&2
echo "$0: debug[3]: REPO_URL=$REPO_URL" 1>&2
echo "$0: debug[3]: SITE_URL=$SITE_URL" 1>&2
echo "$0: debug[3]: NOOP=$NOOP" 1>&2
echo "$0: debug[3]: DO_NOT_PROCESS=$DO_NOT_PROCESS" 1>&2
echo "$0: debug[3]: EXIT_CODE=$EXIT_CODE" 1>&2
echo "$0: debug[3]: WINNER_PATH=$WINNER_PATH" 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
for index in "${!TOOL_OPTION[@]}"; do
echo "$0: debug[3]: TOOL_OPTION[$index]=${TOOL_OPTION[$index]}" 1>&2
done
echo "$0: debug[3]: REPO_NAME=$REPO_NAME" 1>&2
echo "$0: debug[3]: YYYY_DIR=$YYYY_DIR" 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]: REPO_URL=$REPO_URL" 1>&2
echo "$0: debug[3]: REPO_NAME=$REPO_NAME" 1>&2
echo "$0: debug[3]: TOP_URL=$TOP_URL" 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]: INC_PATH=$INC_PATH" 1>&2
echo "$0: debug[3]: INC_DIR=$INC_DIR" 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]: PANDOC_WRAPPER=$PANDOC_WRAPPER" 1>&2
echo "$0: debug[3]: PANDOC_WRAPPER_OPTSTR=$PANDOC_WRAPPER_OPTSTR" 1>&2
echo "$0: debug[3]: WINNER_JSON=$WINNER_JSON" 1>&2
echo "$0: debug[3]: README_MD=$README_MD" 1>&2
echo "$0: debug[3]: INDEX_HTML=$INDEX_HTML" 1>&2
echo "$0: debug[3]: TOOL=$TOOL" 1>&2
echo "$0: debug[3]: OPTSTR=$OPTSTR" 1>&2
echo "$0: debug[3]: TOOL_OPTIONS=$TOOL_OPTIONS" 1>&2
echo "$0: debug[3]: DO_NOT_PROCESS=$DO_NOT_PROCESS" 1>&2
echo "$0: debug[3]: NOOP=$NOOP" 1>&2
echo "$0: debug[3]: README_PATH=$README_PATH" 1>&2
echo "$0: debug[3]: INDEX_PATH=$INDEX_PATH" 1>&2
echo "$0: debug[3]: ENTRY_JSON=$WINNER_JSON" 1>&2
fi
# determine if we need to run the tool
# -N stops early before any processing is performed
#
# If the non-empty index.html is newer than the .winner.json file,
#
if [[ $V_FLAG -ge 5 ]]; then
ls -lRt "$INDEX_HTML" "$WINNER_JSON" "$README_MD" 2>/dev/null
fi
if [[ -s $INDEX_HTML && $INDEX_HTML -nt $WINNER_JSON && $INDEX_HTML -nt $README_MD ]]; then
if [[ -n $DO_NOT_PROCESS ]]; then
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: does not need to be updated: $INDEX_HTML" 1>&2
echo "$0: debug[3]: arguments parsed, -N given, exiting 0" 1>&2
fi
exit 0
fi
# run the tool
# determine if we need to run the tool
#
# If the non-empty index.html is newer than the .entry.json file,
#
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: listing of important files, if they exist, starts below" 1>&2
ls -lRt -- "$INDEX_PATH" "$ENTRY_JSON" "$README_PATH" 2>/dev/null
echo "$0: debug[5]: listing of important files, if they exist, ends above" 1>&2
fi
if [[ -s $INDEX_PATH && $INDEX_PATH -nt $ENTRY_JSON && $INDEX_PATH -nt $README_PATH ]]; then
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: does not need to be updated: $INDEX_PATH" 1>&2
fi
exit 0
fi
# run the md2html.sh tool, unless -n
#
if [[ -z $NOOP ]]; then
# run the tool
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: about to run: $TOOL $OPTSTR $TOOL_OPTIONS \"$WINNER_PATH\"" 1>&2
echo "$0: debug[3]: about to run: $MD2HTML_SH ${TOOL_OPTION[*]} -- $README_PATH $INDEX_PATH" 1>&2
fi
eval "$TOOL" "$OPTSTR" "$TOOL_OPTIONS" '"'"$WINNER_PATH"'"'
"$MD2HTML_SH" "${TOOL_OPTION[@]}" -- "$README_PATH" "$INDEX_PATH"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: tool: $TOOL failed, error: $status" 1>&2
exit 1
echo "$0: Warning: md2html.sh: $MD2HTML_SH ${TOOL_OPTION[*]} -- $README_PATH $INDEX_PATH failed, error: $status" 1>&2
EXIT_CODE="1" # exit 1
echo "$0: Warning: EXIT_CODE set to: $EXIT_CODE" 1>&2
fi
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: about to: touch $INDEX_PATH" 1>&2
fi
touch "$INDEX_PATH"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: Warning: unable to touch $INDEX_PATH, error: $status" 1>&2
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: now up to date: $INDEX_PATH" 1>&2
fi
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: listing of important files starts below" 1>&2
ls -lRt -- "$INDEX_PATH" "$ENTRY_JSON" "$README_PATH" 2>/dev/null
echo "$0: debug[5]: listing of important files ends above" 1>&2
fi
# report disabled by -n
#
elif [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: because of -n, did not run: $TOOL $OPTSTR $TOOL_OPTIONS \"$WINNER_PATH\"" 1>&2
echo "$0: debug[5]: because of -n, did not run: $MD2HTML_SH ${TOOL_OPTION[*]} -- $README_PATH $INDEX_PATH" 1>&2
fi
# All Done!!! -- Jessica Noll, Age 2