squeeze

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

commit 19d89625662b87aef58679542bfb93a705901acd
parent 48a5b93dbbd0bea52a536b264796c2657fb7d3dc
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Tue, 16 Jun 2020 19:55:01 -0500

Refactor shell scripts for POSIX compatibility

Refactored the bash scripts so they're now general POSIX-compatible
shell scripts.

Diffstat:
Mreadme.md | 7+++----
Msqueeze.sh | 12++++--------
Munsqueeze.sh | 6++----
3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/readme.md b/readme.md @@ -6,13 +6,13 @@ A static site generator that can put the toothpaste back in the tube. A few months ago I lost the source files I used to generate my static website. Fortunately there was no irreparable data loss because I still had the generated site up on my server. The problem was now I needed to write a script that would extract all the articles into source files again, and then I'd have to reconfigure the site generator. Then I went, "Oh. This is a Prolog problem." (But then I love Prolog so every problem is a Prolog problem. I don't care. Fight me.) A Prolog program is basically a set of rules and the logic that's guided by those rules can be run in either direction. I figured if I could write a Prolog program that described my HTML template then I could use the same code both to un-generate and re-generate the website. -So the skinny is I wound up writing my own static website generator in Prolog. Well, the main components are in Prolog. I also wrote a bash script to make use of a bunch of common \*nix utilities (find, sed, grep, etc.) and to pipe output to some third-party programs where I needed them (Markdown and SmartyPants). Weirdest bit was that I just couldn't find anything decent to generate RSS feeds. I considered dropping the RSS all together, but I've spent enough time haranguing people for not supporting interoperable standards that I didn't want to be a hypocrite. I wound up writing my own RSS generator too, also in Prolog. +So the skinny is I wound up writing my own static website generator in Prolog. Well, the main components are in Prolog. I also wrote a shell script to make use of a bunch of common \*nix utilities (find, sed, grep, etc.) and to pipe output to some third-party programs where I needed them (Markdown and SmartyPants). Weirdest bit was that I just couldn't find anything decent to generate RSS feeds. I considered dropping the RSS all together, but I've spent enough time haranguing people for not supporting interoperable standards that I didn't want to be a hypocrite. I wound up writing my own RSS generator too, also in Prolog. It's pretty closely tailored to my specific needs, but it works, and IMHO it works better than my old site generator which injected a bunch of nonsense into my HTML. To make this work for your site, all you need to do is define the template of your website in "html.pl". ## Dependencies -* Bash. Used to run the script that automates everything else. +* A POSIX shell. Used to run the script that automates everything else. * A Prolog interpreter. Tested with [SWI-Prolog](https://www.swi-prolog.org/) and [GNU Prolog](http://www.ohloh.net/p/gprolog), but the syntax aims to be vanilla ISO Prolog and should work with any implementation. * [Markdown](https://daringfireball.net/projects/markdown/). Used to convert Markdown to HTML. * [SmartyPants](https://daringfireball.net/projects/smartypants/). Used to smarten the punctuation in the HTML output. @@ -55,4 +55,4 @@ Generate source files from a static website: The Markdown converter is called from inside Prolog, so the path to your Markdown (and any arguments) is specified in site.pl. This allows you to have different Markdown converters or arguments on a per-site basis. -Because ISO Prolog doesn't support making calls to external programs, I've implemented a compatibility layer that allows you to define the `markdown_to_html` predicate for whatever dialect of Prolog you happen to use. Included are compatibility predicates for SWI-Prolog and GNU Prolog.- \ No newline at end of file +Because ISO Prolog doesn't support making calls to external programs, I've implemented a compatibility layer that allows you to define the `markdown_to_html` predicate for whatever dialect of Prolog you happen to use. Included are compatibility predicates for SWI-Prolog and GNU Prolog. diff --git a/squeeze.sh b/squeeze.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh SITE_PATH=$1 @@ -15,9 +15,7 @@ find "$OUTPUT_PATH" -type f -name "*.html" | OLD_PATH=$(echo "$file" | sed "s|^$OUTPUT_PATH|$SOURCE_PATH|" | sed 's|.html$|.md|') - if [ ! -f "$OLD_PATH" ]; then - rm "$file" - fi + [ ! -f "$OLD_PATH" ] && rm "$file" done # Parse and create all the HTML files. @@ -27,14 +25,12 @@ find "$SOURCE_PATH" -type f -name "*.md" | sed "s|^$SOURCE_PATH|$OUTPUT_PATH|" | sed 's|.md$|.html|') # Only process files whose destination doesn't exist, or which has been recently changed. - if [ ! -f "$NEW_PATH" ] || [[ $(find "$file" -mtime -7) ]]; then - echo "$file" - + [ ! -f "$NEW_PATH" ] || find "$file" -mtime -7 | grep -q . && + echo "$file" && swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry('$file')." | # Smarten punctuation. smartypants \ > "$NEW_PATH" - fi done # Generate the RSS feed. diff --git a/unsqueeze.sh b/unsqueeze.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh SITE_PATH=$1 @@ -16,9 +16,7 @@ find "$SOURCE_PATH" -type f -name "*.md" | OLD_PATH=$(echo "$file" | sed "s|^$SOURCE_PATH|$OUTPUT_PATH|" | sed 's|.md$|.html|') - if [ ! -f "$OLD_PATH" ]; then - rm "$file" - fi + [ ! -f "$OLD_PATH" ] && rm "$file" done # Parse and create all the markdown files.