squeeze

A static site generator that can put the toothpaste back in the tube.
git clone https://git.stjo.hn/squeeze
Log | Files | Refs | README | LICENSE

commit e4d2b12103a771278c0c32af30fd5221c83ac29e
parent 569e7a74aea5ad26058790714a8e5f22ff29a8d8
Author: St John Karp <contact@stjo.hn>
Date:   Sat, 21 Aug 2021 12:58:08 -0400

Collapse generate_html.sh, generate_html_list.sh, generate_markdown.sh

Collapsed the two HTML shell scripts into one, as the list version
with a single-element list can function the same as the single-argument
version. Combined the HTML and Markdown scripts back into squeeze.sh
and unsqueeze.sh, which is where they originated. I only split the code
into separate shell scripts so they could be run in parallel with xargs,
but that use case no longer applies now that we're using strictly POSIX
functionality.

Diffstat:
Dgenerate_html.sh | 22----------------------
Dgenerate_html_list.sh | 22----------------------
Dgenerate_markdown.sh | 15---------------
Msqueeze.sh | 21+++++++++++++++++++--
Munsqueeze.sh | 13+++++++++++--
5 files changed, 30 insertions(+), 63 deletions(-)

diff --git a/generate_html.sh b/generate_html.sh @@ -1,22 +0,0 @@ -#!/usr/bin/env sh - -# Convert a Markdown file to HTML using a site's template. - -# Usage: generate_html.sh SITE_PATH MARKDOWN_FILE -# -# MARKDOWN_FILE is expected to be found at SITE_PATH/source/MARKDOWN_FILE. -# The resulting HTML will be saved to SITE_PATH/output/HTML_FILE, where -# HTML_FILE is the same filename as MARKDOWN_FILE but with a .html extension. - -echo "$2" - -swipl --traditional --quiet -l parse_entry.pl -g "consult('$1/site.pl'), generate_entry('$1/source/$2')." | - # Unwrap block-level elements that have erroneously been wrapped in <p> tags. - sed "s|<p><details|<details|g" | - sed "s|</summary></p>|</summary>|g" | - sed "s|<p></details></p>|</details>|g" | - sed "s|<p><figure|<figure|g" | - sed "s|</figure></p>|</figure>|g" | - # Smarten punctuation. - smartypants \ - > "$1/output/${2%%.md}.html" diff --git a/generate_html_list.sh b/generate_html_list.sh @@ -1,22 +0,0 @@ -#!/usr/bin/env sh - -# Loop through a list of Markdown files and generate the corresponding HTML, -# launching a background job for each process. - -# Usage: generate_html_list SITE_PATH MARKDOWN_FILE... - -# The site path will be the first argument. -# Save its value and shift it down so we can take the rest together. -SITE_PATH="$1" -shift - -# Get all the remaining arguments. These will be the file names. -# Remove the start of the path. -ARGS="$(echo "$@" | sed "s|$SITE_PATH/source/||g")" - -for arg in $ARGS; do - ./generate_html.sh "$SITE_PATH" $arg & -done - -# Wait until all jobs have completed. -wait diff --git a/generate_markdown.sh b/generate_markdown.sh @@ -1,15 +0,0 @@ -#!/usr/bin/env sh - -SITE_PATH="$1" -shift - -ARGS="$(echo "$@" | sed "s|$SITE_PATH/output/||g")" - -for arg in $ARGS; do - echo "$arg" - - swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), parse_entry('$SITE_PATH/output/$arg')." \ - > "$SITE_PATH/source/${arg%%.html}.md" & -done - -wait diff --git a/squeeze.sh b/squeeze.sh @@ -16,8 +16,25 @@ rsync --archive --delete --verbose \ "$SOURCE_PATH/" "$OUTPUT_PATH/" # Parse and create all the HTML files. -find "$SOURCE_PATH" -type f -name "*.md" \ - -exec ./generate_html_list.sh "$SITE_PATH" {} + +find "$SOURCE_PATH" -type f -name "*.md" | + sed "s|$SITE_PATH/source/||g" | + while IFS= read -r file; do + echo "$file" + + swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry('$SITE_PATH/source/$file')." | + # Unwrap block-level elements that have erroneously been wrapped in <p> tags. + sed "s|<p><details|<details|g" | + sed "s|</summary></p>|</summary>|g" | + sed "s|<p></details></p>|</details>|g" | + sed "s|<p><figure|<figure|g" | + sed "s|</figure></p>|</figure>|g" | + # Smarten punctuation. + smartypants \ + > "$SITE_PATH/output/${file%%.md}.html" & + done + +# Wait until all jobs have completed. +wait # Generate the RSS feed. mkdir -p "$OUTPUT_PATH/feeds" diff --git a/unsqueeze.sh b/unsqueeze.sh @@ -17,8 +17,17 @@ rsync --archive --delete --verbose \ "$OUTPUT_PATH/" "$SOURCE_PATH/" # Parse and create all the Markdown files. -find "$OUTPUT_PATH" -type f -name "*.html" \ - -exec ./generate_markdown.sh "$SITE_PATH" {} + +find "$OUTPUT_PATH" -type f -name "*.html" | + sed "s|$SITE_PATH/output/||g" | + while IFS= read -r file; do + echo "$file" + + swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), parse_entry('$SITE_PATH/output/$file')." \ + > "$SITE_PATH/source/${file%%.html}.md" & + done + +# Wait until all jobs have completed. +wait # Unsmarten the punctuation. MARKDOWN_FILES="$(find "$SOURCE_PATH" -type f -name "*.md")"