commit 257d62e923fc8764459912496e3187f201fe90d4
parent a8101666d09cbdfbbb72e2fabbf9eea50368795f
Author: St John Karp <contact@stjo.hn>
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:
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