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

+480
View File
@@ -0,0 +1,480 @@
#!/usr/bin/env bash
#
# gen_entry_json.sh - generate .entry.json for a winner
#
# XXX - This is a temporary utility that will be replaced when
# the .entry.json files are built.
#
# Copyright (c) 2023,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! :-)
# setup
#
export VERSION="1.1 2024-01-14"
NAME=$(basename "$0"); export NAME
export DOT_ENTRY_JSON_BASENAME=".entry.json"
export ENTRY_JSON_FORMAT_VERSION="1.1 2024-02-11"
export NO_COMMENT="mandatory comment: because comments were removed from the original JSON spec"
export AUTHOR_WINS_CSV="author_wins.csv"
export YEAR_PRIZE_CSV="year_prize.csv"
export MANIFEST_CSV="manifest.csv"
export PANDOC="/opt/homebrew/bin/pandoc"
#
export V_FLAG=0
export DOMAIN="ioccc-src.github.io"
export DOCPATH="/temp-test-ioccc"
export GITHUB_REPO="https://github.com/ioccc-src/temp-test-ioccc/blob/master"
export TOPDIR=".."
# usage
#
export USAGE="usage: $0 [-h] [-v level]
[-d www.domain.org] [-p /path/to/docroot] [-g github_url ] [-t topdir] [-P /path/to/pandoc]
year[/dir] [dir]
-h print help message and exit
-v level set verbosity level (def level: $V_FLAG)
-d www.domain.org change domain (def: $DOMAIN)
-p /path/to/docroot use path under domain to document root (def: $DOCPATH)
-g github_url path to the GitHub repo (def: $GITHUB_REPO)
-t topdir path to top of the local tree (def: $TOPDIR)
-P /path/to/pandoc path to the pandoc tool (def: $PANDOC)
year[/dir] path to winner directory (or just year if there is a path arg
[dir] optional winner directory (1st arg is just year)
Exit codes:
0 all OK
2 -h and help string printed or -V and version string printed
3 command line error
4 cannot find writable winner directory
5 cannot find readable author_wins.csv
6 cannot find readable year_prize.csv
7 cannot find readable manifest.csv
8 cannot find pandoc executable
9 cannot determine the award for year/dir
10 cannot determine authors of year/dir
>= 20 internal error
$NAME version: $VERSION"
# parse command line
#
while getopts :hv:d:p:g:t:P: flag; do
case "$flag" in
h) echo "$USAGE"
exit 2
;;
v) V_FLAG="$OPTARG"
;;
d) DOMAIN="$OPTARG"
;;
p) DOCPATH="$OPTARG"
;;
g) GITHUB_REPO="$OPTARG"
;;
t) TOPDIR="$OPTARG"
;;
P) PANDOC="$OPTARG"
;;
\?) echo "$0: ERROR: invalid option: -$OPTARG" 1>&2
echo 1>&2
echo "$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
#
# remove the options
#
shift $(( OPTIND - 1 ));
#
# verify arg count and parse args
#
export WINNER_PATH
export YEAR
export WINNER
case "$#" in
1) WINNER_PATH="$1"
YEAR="${WINNER_PATH%/*}"
WINNER="${WINNER_PATH#*/}"
;;
2) WINNER_PATH="$1/$2"
YEAR="$1"
WINNER="$2"
;;
*) echo "$0: ERROR: expected 1 or 2 args, found: $#" 1>&2
echo "$USAGE" 1>&2
exit 3
;;
esac
export FULL_WINNER_PATH="$TOPDIR/$WINNER_PATH"
export ENTRY_ID="${YEAR}_${WINNER}"
export URL_PATH="https://$DOMAIN$DOCPATH/$YEAR/$WINNER"
# setup temporary files
#
export ENTRY_JSON_PATH="$FULL_WINNER_PATH/$DOT_ENTRY_JSON_BASENAME"
export TMP_DOT_ENTRY_JSON="$FULL_WINNER_PATH/tmp.$$.$DOT_ENTRY_JSON_BASENAME"
trap 'rm -f $TMP_DOT_ENTRY_JSON' 0 1 2 3 15
# print running info if verbose
#
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: V_FLAG=$V_FLAG" 1>&2
echo "$0: debug[5]: NAME=$NAME" 1>&2
echo "$0: debug[5]: VERSION=$VERSION" 1>&2
echo "$0: debug[5]: ENTRY_JSON_FORMAT_VERSION=$ENTRY_JSON_FORMAT_VERSION" 1>&2
echo "$0: debug[5]: NO_COMMENT=$NO_COMMENT" 1>&2
echo "$0: debug[5]: AUTHOR_WINS_CSV=$AUTHOR_WINS_CSV" 1>&2
echo "$0: debug[5]: YEAR_PRIZE_CSV=$YEAR_PRIZE_CSV" 1>&2
echo "$0: debug[5]: MANIFEST_CSV=$MANIFEST_CSV" 1>&2
echo "$0: debug[5]: DOMAIN=$DOMAIN" 1>&2
echo "$0: debug[5]: DOCPATH=$DOCPATH" 1>&2
echo "$0: debug[5]: GITHUB_REPO=$GITHUB_REPO" 1>&2
echo "$0: debug[5]: TOPDIR=$TOPDIR" 1>&2
echo "$0: debug[5]: PANDOC=$PANDOC" 1>&2
echo "$0: debug[5]: FULL_WINNER_PATH=$FULL_WINNER_PATH" 1>&2
echo "$0: debug[5]: ENTRY_ID=$ENTRY_ID" 1>&2
echo "$0: debug[5]: YEAR=$YEAR" 1>&2
echo "$0: debug[5]: WINNER=$WINNER" 1>&2
echo "$0: debug[5]: WINNER_PATH=$WINNER_PATH" 1>&2
echo "$0: debug[5]: URL_PATH=$URL_PATH" 1>&2
echo "$0: debug[5]: DOT_ENTRY_JSON_BASENAME=$DOT_ENTRY_JSON_BASENAME" 1>&2
echo "$0: debug[5]: ENTRY_JSON_PATH=$ENTRY_JSON_PATH" 1>&2
echo "$0: debug[5]: TMP_DOT_ENTRY_JSON=$TMP_DOT_ENTRY_JSON" 1>&2
fi
# make is easier to process CSV files
#
IFS="$IFS,"
# verify winner directory is writable
#
if [[ ! -e $FULL_WINNER_PATH ]]; then
echo "$0: ERROR: FULL_WINNER_PATH does not exist: $FULL_WINNER_PATH" 1>&2
exit 4
fi
if [[ ! -d $FULL_WINNER_PATH ]]; then
echo "$0: ERROR: FULL_WINNER_PATH is not a directory: $FULL_WINNER_PATH" 1>&2
exit 4
fi
if [[ ! -w $FULL_WINNER_PATH ]]; then
echo "$0: ERROR: FULL_WINNER_PATH is not a writable directory: $FULL_WINNER_PATH" 1>&2
exit 4
fi
# verify author_wins.csv is readable
#
if [[ ! -e $AUTHOR_WINS_CSV ]]; then
echo "$0: ERROR: AUTHOR_WINS_CSV does not exist: $AUTHOR_WINS_CSV" 1>&2
exit 5
fi
if [[ ! -f $AUTHOR_WINS_CSV ]]; then
echo "$0: ERROR: AUTHOR_WINS_CSV is not a file: $AUTHOR_WINS_CSV" 1>&2
exit 5
fi
if [[ ! -r $AUTHOR_WINS_CSV ]]; then
echo "$0: ERROR: AUTHOR_WINS_CSV is not a readable file: $AUTHOR_WINS_CSV" 1>&2
exit 5
fi
# verify year_prize.csv is readable
#
if [[ ! -e $YEAR_PRIZE_CSV ]]; then
echo "$0: ERROR: YEAR_PRIZE_CSV does not exist: $YEAR_PRIZE_CSV" 1>&2
exit 6
fi
if [[ ! -f $YEAR_PRIZE_CSV ]]; then
echo "$0: ERROR: YEAR_PRIZE_CSV is not a file: $YEAR_PRIZE_CSV" 1>&2
exit 6
fi
if [[ ! -r $YEAR_PRIZE_CSV ]]; then
echo "$0: ERROR: YEAR_PRIZE_CSV is not a readable file: $YEAR_PRIZE_CSV" 1>&2
exit 6
fi
# verify manifest.csv is readable
#
if [[ ! -e $MANIFEST_CSV ]]; then
echo "$0: ERROR: MANIFEST_CSV does not exist: $MANIFEST_CSV" 1>&2
exit 7
fi
if [[ ! -f $MANIFEST_CSV ]]; then
echo "$0: ERROR: MANIFEST_CSV is not a file: $MANIFEST_CSV" 1>&2
exit 7
fi
if [[ ! -r $MANIFEST_CSV ]]; then
echo "$0: ERROR: MANIFEST_CSV is not a readable file: $MANIFEST_CSV" 1>&2
exit 7
fi
# verify we have a pandoc executable
#
if [[ ! -x $PANDOC ]]; then
echo "$0: ERROR: pandoc executable not found: $PANDOC" 1>&2
exit 8
fi
# determine award
#
AWARD=$(grep -E "^$ENTRY_ID," "$YEAR_PRIZE_CSV" | sed -e "s/^$ENTRY_ID,//")
export AWARD
if [[ -z $AWARD ]]; then
echo "$0: ERROR: cannot find award for $ENTRY_ID in $YEAR_PRIZE_CSV" 1>&2
exit 9
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: AWARD for $ENTRY_ID: $AWARD" 1>&2
fi
# determine author set
#
AUTHOR_SET=$(grep -E ",$ENTRY_ID," "$AUTHOR_WINS_CSV")
declare -a AUTHOR
while read -r author extra; do
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: $ENTRY_ID extra: $extra"
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: $ENTRY_ID author: $author"
fi
if [[ -z $author ]]; then
echo "$0: ERROR: $ENTRY_ID empty author found in $AUTHOR_WINS_CSV with extra: $extra" 1>&2
exit 10
fi
AUTHOR+=( "$author" )
done <<< "$AUTHOR_SET"
export AUTHOR_COUNT=${#AUTHOR[@]}
if [[ $AUTHOR_COUNT -le 0 ]]; then
echo "$0: ERROR: cannot find any authors for $ENTRY_ID" 1>&2
exit 10
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: author count for $ENTRY_ID: $AUTHOR_COUNT"
fi
# collect inventory
#
NUMBER_RANKED_MANIFEST_SET=$(grep -E "^$YEAR,$WINNER,[^,][^,]*,[0-9]" "$MANIFEST_CSV" | sort -t, -k4n)
declare -a FILE_PATH INVENTORY_ORDER OK_TO_EDIT DISPLAY_AS DISPLAY_VIA_GITHUB WINNER_TEXT
#
# process inventory with a numerical inventory_order
#
while IFS=, read -r year dir file_path inventory_order OK_to_edit display_as display_via_github winners_text extra; do
# firewall - year dir much match
#
if [[ $YEAR != "$year" ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order YEAR: $YEAR != $year" 1>&2
exit 30
fi
if [[ $WINNER != "$dir" ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order WINNER: $WINNER != $dir" 1>&2
exit 31
fi
if [[ $V_FLAG -ge 7 ]]; then
echo "$0: debug[7]: found: year: $year dir: $dir inventory_order: $inventory_order file_path: $file_path" 1>&2
echo "$0: debug[7]: also: display_as: $display_as display_via_github: $display_via_github" 1>&2
echo "$0: debug[7]: and: winners_text: $winners_text extra: $extra" 1>&2
fi
# firewall - nothing except extra should be empty
#
if [[ -z $file_path ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order empty file_path" 1>&2
exit 32
fi
if [[ -z $inventory_order ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order empty inventory_order" 1>&2
exit 33
fi
if [[ -z $OK_to_edit ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order empty OK_to_edit" 1>&2
exit 34
fi
if [[ -z $display_as ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order empty display_as" 1>&2
exit 37
fi
if [[ -z $display_via_github ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order empty display_via_github" 1>&2
exit 38
fi
if [[ -z $winners_text ]]; then
echo "$0: ERROR: ^$YEAR,$WINNER inventory_order: $inventory_order empty winners_text" 1>&2
exit 39
fi
# save inventory information
#
FILE_PATH+=( "$file_path" )
INVENTORY_ORDER+=( "$inventory_order" )
OK_TO_EDIT+=( "$OK_to_edit" )
DISPLAY_AS+=( "$display_as" )
DISPLAY_VIA_GITHUB+=( "$display_via_github" )
WINNER_TEXT+=( "$winners_text" )
done <<< "$NUMBER_RANKED_MANIFEST_SET"
export FILE_COUNT=${#FILE_PATH[@]}
if [[ $FILE_COUNT -le 0 ]]; then
echo "$0: ERROR: cannot find files in manifest $MANIFEST_CSV for $ENTRY_ID" 1>&2
exit 50
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: manifest file count for $ENTRY_ID: $FILE_COUNT"
fi
# write .entry.json
#
# write leading part of .entry.json
#
cat > "$TMP_DOT_ENTRY_JSON" << EOF
{
"no_comment" : "$NO_COMMENT",
"entry_JSON_format_version" : "$ENTRY_JSON_FORMAT_VERSION",
"award" : "$AWARD",
"year" : $YEAR,
"dir" : "$WINNER",
"entry_id" : "$ENTRY_ID",
"author_set" : [
EOF
#
# write author_handle part of .entry.json
#
((AUTHOR_COUNT_LESS_1=AUTHOR_COUNT-1))
for i in "${!AUTHOR[@]}"; do
# stupid JSON syntax does not allow a trailing comma
if [[ $i -lt "$AUTHOR_COUNT_LESS_1" ]]; then
cat >> "$TMP_DOT_ENTRY_JSON" << EOF
{ "author_handle" : "${AUTHOR[$i]}" },
EOF
else
cat >> "$TMP_DOT_ENTRY_JSON" << EOF
{ "author_handle" : "${AUTHOR[$i]}" }
EOF
fi
done
#
# write start of manifest of .entry.json
#
cat >> "$TMP_DOT_ENTRY_JSON" << EOF
],
"manifest" : [
EOF
((FILE_COUNT_LESS_1=FILE_COUNT-1))
#
# write each file in the manifest of .entry.json
#
for i in "${!INVENTORY_ORDER[@]}"; do
#
# write start and file_path of a given file in manifest of .entry.json
# write inventory_order of a given file in manifest of .entry.json
# write OK_to_edit of a given file in manifest of .entry.json
# write display_as of a given file in manifest of .entry.json
# write display_via_github of a given file in manifest of .entry.json
# write winners_text of a given file in manifest of .entry.json
#
cat >> "$TMP_DOT_ENTRY_JSON" << EOF
{
"file_path" : "${FILE_PATH[$i]}",
"inventory_order" : ${INVENTORY_ORDER[$i]},
"OK_to_edit" : ${OK_TO_EDIT[$i]},
"display_as" : "${DISPLAY_AS[$i]}",
"display_via_github" : ${DISPLAY_VIA_GITHUB[$i]},
"winners_text" : "${WINNER_TEXT[$i]}"
EOF
# stupid JSON syntax does not allow a trailing comma
if [[ $i -lt "$FILE_COUNT_LESS_1" ]]; then
cat >> "$TMP_DOT_ENTRY_JSON" << EOF
},
EOF
else
cat >> "$TMP_DOT_ENTRY_JSON" << EOF
}
EOF
fi
done
#
# write trailing part of .entry.json
#
cat >> "$TMP_DOT_ENTRY_JSON" << EOF
]
}
EOF
if [[ $V_FLAG -ge 7 ]]; then
echo "$0: debug[7]: start of TMP_DOT_ENTRY_JSON below: $TMP_DOT_ENTRY_JSON" 1>&2
cat "$TMP_DOT_ENTRY_JSON" 1>&2
echo "$0: debug[7]: end of TMP_DOT_ENTRY_JSON above: $TMP_DOT_ENTRY_JSON" 1>&2
fi
# update .entry.json if needed
#
if ! cmp -s "$TMP_DOT_ENTRY_JSON" "$ENTRY_JSON_PATH"; then
# replace index.html file
#
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: updating $ENTRY_JSON_PATH"
fi
if [[ $V_FLAG -ge 3 ]]; then
mv -f -v "$TMP_DOT_ENTRY_JSON" "$ENTRY_JSON_PATH"
status="$?"
else
mv -f "$TMP_DOT_ENTRY_JSON" "$ENTRY_JSON_PATH"
status="$?"
fi
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: mv -f -v $TMP_DOT_ENTRY_JSON $ENTRY_JSON_PATH failed, error: $status" 1>&2
exit 100
fi
else
# index.html is OK, remove the tmp file
#
rm -f "$TMP_DOT_ENTRY_JSON"
if [[ -e $TMP_DOT_ENTRY_JSON ]]; then
echo "$0: ERROR: TMP_DOT_ENTRY_JSON cannot be removed for cleanup: $TMP_DOT_ENTRY_JSON" 1>&2
exit 101
fi
fi
# All Done!!! -- Jessica Noll, Age 2
#
exit 0