commit 817f19652b199196c0fe86b01ed7e98fa27c55f4
parent a1ccb4a96e9d55b30e4672c0e43c483de57a89f1
Author: St John Karp <contact@stjo.hn>
Date: Tue, 20 Oct 2020 05:35:39 -0500
Allow generate_rss to take input piped from stdin
This is a better way of handling a list of file names because
we don't have to construct a big list of atoms on the command line,
which results in a cleaner shell script. We can just pipe the
output of the shell commands straight to Prolog.
Diffstat:
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/generate_rss.pl b/generate_rss.pl
@@ -29,6 +29,24 @@ generate_rss(Filenames):-
write_codes(user_output, RSSCodes),
halt.
+% generate_rss.
+% Alternative interface to generate_rss(+Filenames) that reads
+% the list of files from stdin. This allows the filenames to be piped
+% from the output of another command like grep.
+generate_rss:-
+ read_file(user_input, FileListCodes),
+ file_list(FileList, FileListCodes, []),
+ generate_rss(FileList).
+
+
+file_list([]) --> [].
+
+file_list([File|FileList]) -->
+ anything(FileCodes),
+ newline,
+ file_list(FileList),
+ { atom_codes(File, FileCodes) }.
+
% files_to_articles(+Filenames, -Articles).
% Read in each file as an article predicate.
diff --git a/squeeze.sh b/squeeze.sh
@@ -18,16 +18,13 @@ find "$SOURCE_PATH" -type f -name "*.md" -printf "%P\0" |
# Generate the RSS feed.
mkdir -p "$OUTPUT_PATH/feeds"
# Grep the date of each article.
-ARTICLES=$(grep --recursive --include "*.html" "id=\"article-date\"" "$OUTPUT_PATH" |
+grep --recursive --include "*.html" "id=\"article-date\"" "$OUTPUT_PATH" |
# Sort articles by date (skipping the first field).
sort +1 |
# Get the last (i.e. most recent) posts for the RSS feed.
tail -5 |
# Reformat to just the file names.
cut --fields 1 --delimiter : |
- # Glue the file names together to be passed to Prolog.
- paste --serial --delimiters ',' - |
- sed "s|,|','|g")
-# Parse the articles and generate the RSS.
-swipl --traditional --quiet -l generate_rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss(['$ARTICLES'])." \
+ # Parse the articles and generate the RSS.
+ swipl --traditional --quiet -l generate_rss.pl -g "consult('$SITE_PATH/site.pl'), generate_rss." \
> "$OUTPUT_PATH/feeds/rss.xml"