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 ab878a8e29481d504c3bc67446d11361499cee2c
parent c71b2f32a3dd9439b1276313b1617ccd23c66c79
Author: St John Karp <contact@stjo.hn>
Date:   Sun, 29 Aug 2021 08:22:05 -0400

Don't call Markdown from inside Prolog

This has always bugged me as it's not ISO Prolog and I believe it's
causing other problems, such as with the `wait` command to wait for
child jobs to complete. I've reinstated some of the older functionality
whereby the shell script is the proper glue between utilities. This
will allow us to stick to strict ISO Prolog and get rid of some of
the workarounds for different dialects, although it does mean we
can no longer specify a different Markdown command per-site.

Diffstat:
MREADME | 13+------------
Mdialects/gnu-prolog.pl | 13-------------
Mdialects/swi-prolog.pl | 12------------
Mexample/site.pl | 2--
Mparse_entry.pl | 4+---
Msqueeze.sh | 16+++++++++++++++-
6 files changed, 17 insertions(+), 43 deletions(-)

diff --git a/README b/README @@ -40,7 +40,7 @@ config values in `site.pl` and define your template in `html.pl`. * 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 +* [Python-Markdown](https://python-markdown.github.io/). Used to convert Markdown to HTML. * [SmartyPants](https://daringfireball.net/projects/smartypants/). Used to smarten the punctuation in the HTML output. @@ -71,14 +71,3 @@ Generate a static website from Markdown sources: Generate source files from a static website: ./unsqueeze.sh /home/user/website - -## Notes - -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. diff --git a/dialects/gnu-prolog.pl b/dialects/gnu-prolog.pl @@ -10,19 +10,6 @@ gnu_prolog:- catch(current_prolog_flag(prolog_name, 'GNU Prolog'), _, fail). -% GNU-Prolog-specific predicate to run an external Markdown tool. -% The command itself should be specified in your site.pl. -markdown_to_html(MarkdownEntryCodes, HTMLEntryCodes):- - gnu_prolog, - markdown_command(CommandList), - join(CommandList, ' ', Command), - exec(Command, StreamIn, StreamOut, _), - write_codes(StreamIn, MarkdownEntryCodes), - close(StreamIn), - read_file(StreamOut, HTMLEntryCodes), - close(StreamOut). - - % GNU-Prolog-specific handling of dates. today(FormattedDateCodes):- gnu_prolog, diff --git a/dialects/swi-prolog.pl b/dialects/swi-prolog.pl @@ -7,18 +7,6 @@ swi_prolog:- catch(current_prolog_flag(dialect, swi), _, fail). -% SWI-Prolog-specific predicate to run an external Markdown tool. -% The command itself should be specified in your site.pl. -markdown_to_html(MarkdownEntryCodes, HTMLEntryCodes):- - swi_prolog, - markdown_command([Exe|Args]), - process_create(Exe, Args, [stdin(pipe(StreamIn)), stdout(pipe(StreamOut))]), - write_codes(StreamIn, MarkdownEntryCodes), - close(StreamIn), - read_file(StreamOut, HTMLEntryCodes), - close(StreamOut). - - % SWI-Prolog-specific predicates for date handling. today(FormattedDateCodes):- swi_prolog, diff --git a/example/site.pl b/example/site.pl @@ -11,5 +11,3 @@ site_url --> "https://www.example.com". user_email --> "webmaster@example.com". user_name --> "Harold Gruntfuttock". - -markdown_command(['/usr/bin/hoedown', '--footnotes']). diff --git a/parse_entry.pl b/parse_entry.pl @@ -7,7 +7,6 @@ :- include('markdown.pl'). % Include files for dialect-dependent predicates. -:- discontiguous(markdown_to_html/2). :- discontiguous(format_date/2). :- discontiguous(today/1). :- include('dialects/gnu-prolog.pl'). @@ -56,9 +55,8 @@ generate_entry(Filename):- % Parse Markdown into an HTML file and write to stdout. generate_html(Markdown):- markdown(EntryCodes, Title, Subtitle, Date, Markdown, []), - markdown_to_html(EntryCodes, HTMLEntryCodes), clean_title(Title, CleanTitle), - page(HTMLEntryCodes, Title, Subtitle, Date, CleanTitle, HTMLCodes, []), + page(EntryCodes, Title, Subtitle, Date, CleanTitle, HTMLCodes, []), write_codes(user_output, HTMLCodes), halt. diff --git a/squeeze.sh b/squeeze.sh @@ -21,7 +21,21 @@ find "$SOURCE_PATH" -type f -name "*.md" | 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')." | + # Get everything after the metadata. + if head -n 1 "$SOURCE_PATH/$file" | grep -q "^[A-Za-z]*: "; then + HEADERS="$(sed '/^$/q' "$SOURCE_PATH/$file")" + MARKDOWN="$(sed '1,/^$/d' "$SOURCE_PATH/$file")" + else + HEADERS="" + MARKDOWN="$(cat "$SOURCE_PATH/$file")" + fi + + printf '%s' "$MARKDOWN" | + # Convert Markdown to HTML. + markdown_py --extension footnotes --extension md_in_html --extension smarty --quiet --output_format xhtml | + # Recombine with the metadata and hand it to Prolog. + ([ ! -z "$HEADERS" ] && printf '%s\n\n' "$HEADERS" ; cat) | + swipl --traditional --quiet -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." | # Unwrap block-level elements that have erroneously been wrapped in <p> tags. sed "s|<p><details|<details|g" | sed "s|</summary></p>|</summary>|g" |