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 6b21fede3a2b3fc43782c91f9ef90c6d0cfd0a91
parent ba0061ce782c9ac4e7754f9ddf66a9d739beb29d
Author: St John Karp <contact@stjo.hn>
Date:   Fri, 12 Jul 2019 20:17:04 -0500

Fixes after doing a bigger site

Added code and fixes to handle more complex scenarios after testing
this with a much bigger data source.

Diffstat:
Mhtml.pl | 15++++++++++++++-
Mmarkdown.pl | 18+++++++++++++++---
Mrss.pl | 27+++++++++++++++++++++------
Mtastic.sh | 70+++++++++++++++++++++++++++++++++++++---------------------------------
4 files changed, 87 insertions(+), 43 deletions(-)

diff --git a/html.pl b/html.pl @@ -61,13 +61,26 @@ article(Entry, Title, Subtitle, Date) --> article_close, { [First|_] = Entry, char_code('<', First) }. +% An article without a title, subtitle, or metadata. article_header(null, null, null) --> []. +% An article without a subtitle or metadata. +article_header(Title, null, null) --> + article_title(Title). + +% An article without a subtitle. article_header(Title, null, Date) --> article_title(Title), whitespace, article_meta(Date). +% An article without metadata. +article_header(Title, Subtitle, null) --> + article_title(Title), + whitespace, + article_subtitle(Subtitle). + +% An article with all header components. article_header(Title, Subtitle, Date) --> article_title(Title), whitespace, @@ -107,7 +120,7 @@ title(null) --> title(Title) --> "<title>", - Title, + anything(Title), "</title>". title(_) --> diff --git a/markdown.pl b/markdown.pl @@ -1,5 +1,14 @@ % Markdown definition +markdown(Entry, Title, Subtitle, Date) --> + metadata("Title", Title), + "\n", + metadata("Subtitle", Subtitle), + "\n", + metadata("Date", Date), + "\n\n", + anything(Entry). + markdown(Entry, Title, null, Date) --> metadata("Title", Title), "\n", @@ -7,12 +16,15 @@ markdown(Entry, Title, null, Date) --> "\n\n", anything(Entry). -markdown(Entry, Title, Subtitle, Date) --> +markdown(Entry, Title, Subtitle, null) --> metadata("Title", Title), "\n", metadata("Subtitle", Subtitle), - "\n", - metadata("Date", Date), + "\n\n", + anything(Entry). + +markdown(Entry, Title, null, null) --> + metadata("Title", Title), "\n\n", anything(Entry). diff --git a/rss.pl b/rss.pl @@ -17,12 +17,7 @@ files_to_articles([Filename|Filenames], [article(Date, Title, Link, Description) read_file(Stream, Markdown), close(Stream), % Grab the link. - atom_codes(Filename, FilenameCodes), - site_url(URL, []), - append(_, "/source", StartPath), - append(StartPath, Path, FilenameCodes), - append(PathWithoutFile, "index.md", Path), - append(URL, PathWithoutFile, Link), + get_link(Filename, Link), % Extract the title, entry, etc. from the Markdown. markdown(Entry, Title, _, Date, Markdown, []), % XML escape the description. @@ -31,6 +26,26 @@ files_to_articles([Filename|Filenames], [article(Date, Title, Link, Description) replace(">", "&gt;", EntryLT, Description), files_to_articles(Filenames, Articles). +get_link(Filename, Link):- + atom_codes(Filename, FilenameCodes), + % Just assert that this is an index file before we go further. + % Backtracking after this point will take us down a rabbit hole. + append(_, "index.md", FilenameCodes), + site_url(URL, []), + append(_, "/source", StartPath), + append(StartPath, Path, FilenameCodes), + append(PathWithoutFile, "index.md", Path), + append(URL, PathWithoutFile, Link). + +get_link(Filename, Link):- + atom_codes(Filename, FilenameCodes), + site_url(URL, []), + append(_, "/source", StartPath), + append(StartPath, Path, FilenameCodes), + append(PathWithoutExtension, ".md", Path), + append(PathWithoutExtension, "/", PathWithSlash), + append(URL, PathWithSlash, Link). + rss(BuildDate, Articles) --> rss_open, "\n", diff --git a/tastic.sh b/tastic.sh @@ -9,58 +9,62 @@ if [ "$1" == "ungenerate" ] then # Create the directory structure. rm -rf $SITE_PATH/$SOURCE_DIR/* - find $SITE_PATH/$OUTPUT_DIR -type d | \ - sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | \ + find $SITE_PATH/$OUTPUT_DIR -type d | + sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | xargs -0 -d '\n' mkdir -p -- # Parse and create all the markdown files. - for file in `find $SITE_PATH/$OUTPUT_DIR -type f -name "*.html"`; do - NEW_PATH=`echo $file | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | sed 's|.html$|.md|'` - cat $file | \ - swipl --traditional -q -l entries.pl -g "parse_entry." | \ - # Unsmarten the punctuation. - sed "s|&nbsp;| |g" | \ - sed "s|&#8216;|'|g" | \ - sed "s|&#8217;|'|g" | \ - sed "s|&#8220;|\"|g" | \ - sed "s|&#8221;|\"|g" \ - > $NEW_PATH - done + find $SITE_PATH/$OUTPUT_DIR -type f -name "*.html" -print0 | + while IFS= read -r -d '' file; do + NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | sed 's|.html$|.md|'` + cat "$file" | + swipl --traditional -q -l entries.pl -g "consult('$SITE_PATH/site.pl'), parse_entry." | + # Unsmarten the punctuation. + sed "s|&nbsp;| |g" | + sed "s|&#8216;|'|g" | + sed "s|&#8217;|'|g" | + sed "s|&#8220;|\"|g" | + sed "s|&#8221;|\"|g" \ + > "$NEW_PATH" + done # Copy anything else directly. - for file in `find $SITE_PATH/$OUTPUT_DIR -type f -not -name "*.html"`; do - NEW_PATH=`echo $file | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|"` - cp $file $NEW_PATH - done + find $SITE_PATH/$OUTPUT_DIR -type f -not -name "*.html" -print0 | + while IFS= read -r -d '' file; do + NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|"` + cp "$file" "$NEW_PATH" + done elif [ "$1" == "generate" ] then # Create the directory structure. rm -rf $SITE_PATH/$OUTPUT_DIR/* - find $SITE_PATH/$SOURCE_DIR -type d | \ - sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | \ + find $SITE_PATH/$SOURCE_DIR -type d | + sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | xargs -0 -d '\n' mkdir -p -- # Parse and create all the HTML files. - for file in `find $SITE_PATH/$SOURCE_DIR -type f -name "*.md"`; do - NEW_PATH=`echo $file | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | sed 's|.md$|.html|'` - cat $file | \ - swipl --traditional -q -l entries.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." | \ - tidy -quiet --indent auto --indent-with-tabs yes --wrap 0 -xml --tidy-mark no | \ - ~/.local/bin/smartypants \ - > $NEW_PATH - done + find $SITE_PATH/$SOURCE_DIR -type f -name "*.md" -print0 | + while IFS= read -r -d '' file; do + NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | sed 's|.md$|.html|'` + cat "$file" | + swipl --traditional -q -l entries.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." | + tidy -quiet --indent auto --indent-with-tabs yes --wrap 0 -xml --tidy-mark no | + ~/.local/bin/smartypants \ + > "$NEW_PATH" + done # Copy anything else directly. - for file in `find $SITE_PATH/$SOURCE_DIR -type f -not -name "*.md"`; do - NEW_PATH=`echo $file | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|"` - cp $file $NEW_PATH - done + find $SITE_PATH/$SOURCE_DIR -type f -not -name "*.md" -print0 | + while IFS= read -r -d '' file; do + NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|"` + cp "$file" "$NEW_PATH" + done # Generate the RSS feed. mkdir -p $SITE_PATH/$OUTPUT_DIR/feeds ARTICLES=`grep -Rl --include=\*.md "^Date: " $SITE_PATH/$SOURCE_DIR | paste -sd ',' - | sed "s|,|','|g"` BUILD_DATE=`date +"%Y-%m-%d %T"` - swipl --traditional -q -l rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])." | \ + swipl --traditional -q -l rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])." | tidy -quiet --indent auto --indent-with-tabs yes --wrap 0 -xml --tidy-mark no \ > $SITE_PATH/$OUTPUT_DIR/feeds/rss.xml else