forked from HPR/hpr-tools
		
	Various updates
Show_Submission/copy_shownotes: Changed the location of the function library
Show_Submission/do_brave: Updates to the way local stand-alone HTML is generated for
    review purposes.
Show_Submission/do_index: Changed the location of the function library
Show_Submission/do_pandoc: Changed the location of the function library; now uses
    'author_title.pl' to generate YAML for Pandoc
Show_Submission/do_parse: Trivial change
Show_Submission/do_pictures: Changed the location of the function library; better
    handling of the show specification
Show_Submission/do_report: Changed the location of the function library
Show_Submission/do_update_reservations: Changed the location of the function library
Show_Submission/fix_relative_links: Added features 'say' and 'state'
Show_Submission/parse_JSON: New checks: notes too short, trailing spaces on title,
    summary and tags (needing JSON changes). Check for Markdown in the
    assets (see 'do_pandoc_assets'). New 'trim' function.
			
			
This commit is contained in:
		| @@ -19,10 +19,17 @@ | ||||
| #               2022-12-22: We now write state changes to the file .status in | ||||
| #               the show directory, so we need to do that here too. Also | ||||
| #               changed to using the function library for cleanup_temp. | ||||
| #               2024-10-17: Changed the logic around 'hpr????_full.html' by | ||||
| #               using a TT² template to enclose the usual HTML fragment in | ||||
| #               enough HTML to make it standalone. We have to get values from | ||||
| #               'shownotes.json' and paass them into 'tpage' to do this, and | ||||
| #               the end result is not the same as the one generated by | ||||
| #               'do_pandoc'. The result looks better than using the HTML | ||||
| #               fragment. | ||||
| #       AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com | ||||
| #      VERSION: 0.0.5 | ||||
| #      VERSION: 0.0.6 | ||||
| #      CREATED: 2016-03-20 15:22:29 | ||||
| #     REVISION: 2022-12-22 17:28:12 | ||||
| #     REVISION: 2024-10-17 19:33:42 | ||||
| # | ||||
| #=============================================================================== | ||||
|  | ||||
| @@ -47,18 +54,29 @@ if [[ $# -ne 1 ]]; then | ||||
|     exit 1 | ||||
| fi | ||||
|  | ||||
| epno="${1}" | ||||
|  | ||||
| # | ||||
| # Directories and files | ||||
| # | ||||
| BASENAME="$HOME/HPR/Show_Submission" | ||||
| SHOWDIR="$BASENAME/shownotes/hpr${1}" | ||||
| RAWNOTES="$SHOWDIR/hpr${1}.out" | ||||
| HTML="$SHOWDIR/hpr${1}.html" | ||||
| FULLHTML="$SHOWDIR/hpr${1}_full.html" | ||||
| SHOWDIR="$BASENAME/shownotes/hpr${epno}" | ||||
| RAWNOTES="$SHOWDIR/hpr${epno}.out" | ||||
| HTML="$SHOWDIR/hpr${epno}.html" | ||||
| FULLHTML="$SHOWDIR/hpr${epno}_full.html" | ||||
| SHOWNOTES="$SHOWDIR/shownotes.json" | ||||
| STATUSFILE="$SHOWDIR/.status" | ||||
| FORMATFILE="$SHOWDIR/.format" | ||||
| FORMAT="$(cat "$FORMATFILE")" | ||||
|  | ||||
| HTMLFILE="$FULLHTML" | ||||
|  | ||||
| # | ||||
| # Check we have this template | ||||
| # | ||||
| FULLTPL="$BASENAME/make_fullnotes.tpl" | ||||
| [[ -e $FULLTPL ]] || { echo "Unable to find template $FULLTPL"; exit 1; } | ||||
|  | ||||
| # | ||||
| # Check we have this browser | ||||
| # | ||||
| @@ -66,28 +84,57 @@ BRAVE=$(command -v brave-browser) | ||||
| [[ -v BRAVE ]] || { echo "Problem finding the Brave browser"; exit 1; } | ||||
|  | ||||
| # | ||||
| # We prefer to view the 'full' html which we do by default. If not found | ||||
| # (because the host sent in HTML themselves) we look for hpr????.html, which | ||||
| # is a link to the notes from the form (hpr????.out), and view that. If the | ||||
| # link didn't get created (not sure why) we copy the "raw" notes to | ||||
| # a temporary file with an '.html' extension (TODO: we could just make a link | ||||
| # here). Otherwise we found nothing viewable. | ||||
| # Taking a different approach with the 'full' html. If the format is known to | ||||
| # be 'html5' there will not be one the first time we run this script. We will | ||||
| # make 'hpr????_full.html' by enclosing the HTML "fragment" in 'hpr????.html' | ||||
| # in a TT² template with HTML header and footer. | ||||
| # | ||||
| if [[ ! -e $FULLHTML ]]; then | ||||
|     if [[ -e $HTML ]]; then | ||||
|         echo "No full HTML found, viewing $HTML instead" | ||||
|         HTMLFILE="$HTML" | ||||
|     elif [[ -e $RAWNOTES ]]; then | ||||
|         echo "No files with ''.HTML' suffix, viewing raw notes" | ||||
| if [[ $FORMAT = 'html5' ]]; then | ||||
|     # | ||||
|     # Extract the fields we want from the JSON and make them Bash variables | ||||
|     # | ||||
|     declare _author _title _summary # Declare them for shellcheck | ||||
|     jqprog='@sh "_author=\(.host.Host_Name) ' | ||||
|     jqprog+='_title=\(.episode.Title) ' | ||||
|     jqprog+='_summary=\(.episode.Summary)"' | ||||
|     eval "$(jq -r "$jqprog" "$SHOWNOTES")" | ||||
|  | ||||
|         TMP1=$(mktemp '/tmp/notes_XXXXXX.html') || { echo "$SCRIPT: creation of temporary file failed!"; exit 1; } | ||||
|         trap 'cleanup_temp $TMP1' SIGHUP SIGINT SIGPIPE SIGTERM EXIT | ||||
|     # | ||||
|     # Feed the variables to the template to make the full HTML | ||||
|     # | ||||
|     tpage --define author="$_author" \ | ||||
|         --define title="$_title" \ | ||||
|         --define summary="$_summary" \ | ||||
|         --define body="$HTML" \ | ||||
|         "$FULLTPL" > "$FULLHTML" | ||||
| else | ||||
|     # | ||||
|     # See above for how we make the 'full' notes if the host sent in HTML | ||||
|     # notes. Here we have received notes that use one of the excepted markup | ||||
|     # formats or are plain text (≡ Pandoc Markdown). | ||||
|     # | ||||
|     # If the 'full' HTML is not found (for unknown reasons) we look for | ||||
|     # hpr????.html, which is a link to the notes from the form (hpr????.out), | ||||
|     # and view that. If the link didn't get created (not sure why) we copy the | ||||
|     # "raw" notes to a temporary file with an '.html' extension (TODO: we | ||||
|     # could just make a link here). Otherwise we found nothing viewable. | ||||
|     # | ||||
|     if [[ ! -e $FULLHTML ]]; then | ||||
|         if [[ -e $HTML ]]; then | ||||
|             echo "No full HTML found, viewing $HTML instead" | ||||
|             HTMLFILE="$HTML" | ||||
|         elif [[ -e $RAWNOTES ]]; then | ||||
|             echo "No files with ''.HTML' suffix, viewing raw notes" | ||||
|  | ||||
|         cp "$RAWNOTES" "$TMP1" | ||||
|         HTMLFILE="$TMP1" | ||||
|     else | ||||
|         echo "Nothing to view, giving up" | ||||
|         exit | ||||
|             TMP1=$(mktemp '/tmp/notes_XXXXXX.html') || { echo "$SCRIPT: creation of temporary file failed!"; exit 1; } | ||||
|             trap 'cleanup_temp $TMP1' SIGHUP SIGINT SIGPIPE SIGTERM EXIT | ||||
|  | ||||
|             cp "$RAWNOTES" "$TMP1" | ||||
|             HTMLFILE="$TMP1" | ||||
|         else | ||||
|             echo "Nothing to view, giving up" | ||||
|             exit | ||||
|         fi | ||||
|     fi | ||||
| fi | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user