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 026ad4022ab61c5cf78990ff5bc711b9dff23e42
parent 2233e4d2b213d294892048e4e13637c15c7ac5ad
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Mon, 30 Mar 2020 15:01:07 -0500

Sort articles in the shell

Sort articles in the shell before we pass them to the RSS generator.
This saves Prolog from having to parse every article just to get
the date.

Diffstat:
Mgenerate_rss.pl | 4+---
Msqueeze.sh | 3++-
2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/generate_rss.pl b/generate_rss.pl @@ -17,10 +17,8 @@ generate_rss(BuildDate, Filenames):- files_to_articles(Filenames, Articles), % Sort articles by date. sort(Articles, SortedArticles), - % Grab the most recent 5. - take_last(5, SortedArticles, TakenArticles), % Convert to RSS and write to stdout. - rss(BuildDate, TakenArticles, RSSCodes, []), + rss(BuildDate, SortedArticles, RSSCodes, []), atom_codes(RSS, RSSCodes), write(RSS), halt. diff --git a/squeeze.sh b/squeeze.sh @@ -34,7 +34,8 @@ find "$SITE_PATH"/"$SOURCE_DIR" -type f -not -name "*.md" -print0 | # 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"` +# Grep the date of each article, sort them by date, then get a list of file names and take the most recent five. +ARTICLES=`grep -R --include=\*.md "^Date: " "$SITE_PATH"/"$SOURCE_DIR" | sed -rn 's/^([^:]+):(.+)$/\2\t\1/p' | sort | cut -f2 | tail -5 | paste -sd ',' - | sed "s|,|','|g"` BUILD_DATE=`date +"%Y-%m-%d %T"` swipl --traditional -q -l generate_rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(\"$BUILD_DATE\", ['$ARTICLES'])." \ > "$SITE_PATH"/"$OUTPUT_DIR"/feeds/rss.xml \ No newline at end of file