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 407f91ea668e0e3cf4a2ba7b405423a8029d796a
parent 954051b24bce6729e41bbeda53e59b9637b768d4
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Sun, 17 May 2020 11:32:48 -0500

Support GNU Prolog

Added support for GNU Prolog. Tested everything with both SWI-Prolog
and GNU Prolog, added support to the bash scripts for both
calls, and updated the Prolog source for compatibility with both.
The source was always ISO, but GNU Prolog had some weird behavior
that meant the code wouldn't run as-is. Hopefully this will make
the source code more portable between Prolog implementations.

This remains slightly messy upon unsqueezing as there's no way to
suppress GNU Prolog's compiling output. On squeezing it's easy
enough just to cut all the lines before the doctype or xml elements.
If you really want to use GNU Prolog (or another Prolog that doesn't
let you switch off compiler output), it's up to you to remove the
extra messages when you decompile. Hopefully this won't be often,
so I'm not going to bust my hump to fix it.

Diffstat:
Mgenerate_rss.pl | 3+--
Mhelpers.pl | 13+++++++++++++
Mmarkdown.pl | 49++++++++++++++++++++++++++-----------------------
Mparse_entry.pl | 6++----
Mreadme.md | 2+-
Msqueeze.sh | 11++++++++++-
Munsqueeze.sh | 4++--
7 files changed, 55 insertions(+), 33 deletions(-)

diff --git a/generate_rss.pl b/generate_rss.pl @@ -19,8 +19,7 @@ generate_rss(BuildDate, Filenames):- sort(Articles, SortedArticles), % Convert to RSS and write to stdout. rss(BuildDate, SortedArticles, RSSCodes, []), - atom_codes(RSS, RSSCodes), - write(RSS), + write_codes(RSSCodes), halt. diff --git a/helpers.pl b/helpers.pl @@ -51,6 +51,19 @@ append_lists([First|List1], List2, [First|Result]):- append_lists(List1, List2, Result). +% write_codes(+CodesList). +% Loop through a list of character codes, convert each one to a +% character, and write them to the current output stream one at +% a time. This is better than converting the whole list to an atom +% with atom_codes/2, which can trigger a segfault if the atom is too long. +write_codes([]). + +write_codes([X|Rest]):- + char_code(Char, X), + write(Char), + write_codes(Rest). + + anything([]) --> []. anything([X|Rest]) --> [X], anything(Rest). diff --git a/markdown.pl b/markdown.pl @@ -6,37 +6,40 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% markdown(Entry, Title, Subtitle, Date) --> - metadata("Title", Title), - "\n", - metadata("Subtitle", Subtitle), - "\n", - metadata("Date", Date), - "\n\n", + "Title: ", + anything(Title), + newline, + "Subtitle: ", + anything(Subtitle), + newline, + "Date: ", + anything(Date), + newline, newline, anything(Entry). markdown(Entry, Title, null, Date) --> - metadata("Title", Title), - "\n", - metadata("Date", Date), - "\n\n", + "Title: ", + anything(Title), + newline, + "Date: ", + anything(Date), + newline, newline, anything(Entry). markdown(Entry, Title, Subtitle, null) --> - metadata("Title", Title), - "\n", - metadata("Subtitle", Subtitle), - "\n\n", + "Title: ", + anything(Title), + newline, + "Subtitle: ", + anything(Subtitle), + newline, newline, anything(Entry). markdown(Entry, Title, null, null) --> - metadata("Title", Title), - "\n\n", + "Title: ", + anything(Title), + newline, newline, anything(Entry). markdown(Entry, null, null, null) --> - anything(Entry). - -metadata(Key, Value) --> - Key, - ": ", - anything(Value).- \ No newline at end of file + anything(Entry).+ \ No newline at end of file diff --git a/parse_entry.pl b/parse_entry.pl @@ -27,8 +27,7 @@ parse_entry(Filename):- parse_html(HTML):- page(EntryCodes, Title, Subtitle, Date, HTML, []), markdown(EntryCodes, Title, Subtitle, Date, MarkdownCodes, []), - atom_codes(Markdown, MarkdownCodes), - write(Markdown), + write_codes(MarkdownCodes), halt. @@ -52,6 +51,5 @@ generate_entry(Filename):- generate_html(Markdown):- markdown(EntryCodes, Title, Subtitle, Date, Markdown, []), page(EntryCodes, Title, Subtitle, Date, HTMLCodes, []), - atom_codes(HTML, HTMLCodes), - write(HTML), + write_codes(HTMLCodes), halt. \ No newline at end of file diff --git a/readme.md b/readme.md @@ -13,7 +13,7 @@ It's pretty closely tailored to my specific needs, but it works, and IMHO it wor ## Dependencies * Bash. Used to run the script that automates everything else. -* A Prolog interpreter. Tested with [SWI-Prolog](https://www.swi-prolog.org/), but the syntax aims to be vanilla ISO Prolog and should work with any implementation. +* 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. diff --git a/squeeze.sh b/squeeze.sh @@ -35,7 +35,11 @@ find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" | markdown | # Recombine with the metadata and hand it to Prolog. (sed "/^$/q" "$file" && cat) | + #gprolog --consult-file parse_entry.pl --consult-file "$SITE_PATH/site.pl" --entry-goal "generate_entry" | swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." | + # Some Prolog variants will output banners and "compiling" output no matter how nicely you ask them not to. + # Strip everything before the doctype declaration. + awk "/<!DOCTYPE/{i++}i" | # Smarten punctuation. smartypants \ > "$NEW_PATH" @@ -59,5 +63,9 @@ ARTICLES=$(grep --recursive --include=\*.md "^Date: " "$SITE_PATH/$SOURCE_DIR" | sed "s|,|','|g") BUILD_DATE=$(date +"%Y-%m-%d %T") # Parse the articles and generate the RSS. -swipl --traditional --quiet -l generate_rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])." \ +#gprolog --consult-file generate_rss.pl --consult-file "$SITE_PATH/site.pl" --entry-goal "generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])" | +swipl --traditional --quiet -l generate_rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])." | + # Strip everything before the XML declaration. + awk "/<?xml/{i++}i" \ > "$SITE_PATH/$OUTPUT_DIR/feeds/rss.xml" + + \ No newline at end of file diff --git a/unsqueeze.sh b/unsqueeze.sh @@ -27,8 +27,8 @@ find "$SITE_PATH/$OUTPUT_DIR" -type f -name "*.html" | NEW_PATH=$(echo "$file" | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | sed 's|.html$|.md|') - cat "$file" | - swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), parse_entry." | + #gprolog --consult-file parse_entry.pl --consult-file "$SITE_PATH/site.pl" --entry-goal "parse_entry('$file')" | + swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), parse_entry('$file')." | # Unsmarten the punctuation. sed "s|&nbsp;| |g" | sed "s|&#8216;|'|g" |