summaryrefslogtreecommitdiff
path: root/lib/atomfeed.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-11-23 20:45:21 +0200
committerPaul Buetow <paul@buetow.org>2022-11-23 20:45:21 +0200
commit5bbae36a59881e34fe111c0ee9f44f3907158301 (patch)
tree85d2b8da1f33c327f57def0ba31a178872050a3d /lib/atomfeed.source.sh
parent6682bd7c4c45283acdb161765dac58ec034899bd (diff)
parent4c4f379ea616eeec320ec27776c739fadf70d2da (diff)
merge
Diffstat (limited to 'lib/atomfeed.source.sh')
-rw-r--r--lib/atomfeed.source.sh52
1 files changed, 45 insertions, 7 deletions
diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh
index 716ef5c..65afa5a 100644
--- a/lib/atomfeed.source.sh
+++ b/lib/atomfeed.source.sh
@@ -32,27 +32,65 @@ META
cat "$meta_file"
}
-# Retrieve the core content as XHTML of the blog post.
-atomfeed::content () {
+atomfeed::_from_cache () {
local -r gmi_file_path="$1"; shift
- log VERBOSE "Retrieving feed content from $gmi_file_path"
+ local -r cache_file_path="$1"; shift
+
+ if [ ! -f "${cache_file_path}.info" ]; then
+ # No cache there.
+ return 1
+ elif ! diff "${cache_file_path}.info" <(ls -l "$gmi_file_path"); then
+ # Need to refresh the cache.
+ return 1
+ fi
+
+ log VERBOSE "Retrieving feed content for $gmi_file_path from $cache_file_path"
+ cat "$cache_file_path"
+}
+
+atomfeed::_make_cache () {
+ local -r gmi_file_path="$1"; shift
+ local -r cache_file_path="$1"; shift
+
+ log VERBOSE "Making feed content cache from $gmi_file_path"
+
+ local -r cache_file_dir="$(dirname "$cache_file_path")"
+ if [ ! -d "$cache_file_dir" ]; then
+ mkdir -p "$cache_file_dir"
+ fi
# sed: Remove all before the first header
# sed: Make HTML links absolute, Atom relative URLs feature seems a mess
# across different Atom clients.
html::fromgmi < <($SED '/Go back to the main site/d' "$gmi_file_path") |
- $SED "
- s|href=\"\./|href=\"https://$DOMAIN/gemfeed/|g;
- s|src=\"\./|src=\"https://$DOMAIN/gemfeed/|g;
- "
+ $SED "s|href=\"\./|href=\"https://$DOMAIN/gemfeed/|g;
+ s|src=\"\./|src=\"https://$DOMAIN/gemfeed/|g;" |
+ tee "$cache_file_path"
+
+ ls -l "$gmi_file_path" > "${cache_file_path}.info"
+}
+
+# Retrieve the core content as XHTML of the blog post.
+atomfeed::content () {
+ local -r gmi_file_path="$1"; shift
+ local -r cache_file_path="${gmi_file_path/gemtext/cache}.atomcache"
+
+ atomfeed::_from_cache "$gmi_file_path" "$cache_file_path" ||
+ atomfeed::_make_cache "$gmi_file_path" "$cache_file_path"
}
# Generate an atom.xml feed file.
atomfeed::generate () {
local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed"
+ if [ ! -d "$gemfeed_dir" ]; then
+ return
+ fi
+
local -r atom_file="$gemfeed_dir/atom.xml"
local -r now=$($DATE --iso-8601=seconds)
+
log INFO "Generating Atom feed to $atom_file"
+ log INFO 'This may takes a while with an empty cache....'
assert::not_empty now "$now"