From 48e4ffe00e473629445ba52e93186dfa8f93c121 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 3 Jul 2022 09:17:56 +0300 Subject: add cache to speed up atom feed generation --- lib/atomfeed.source.sh | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'lib/atomfeed.source.sh') diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index 716ef5c..391842a 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -32,19 +32,51 @@ 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. @@ -53,6 +85,7 @@ atomfeed::generate () { 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" -- cgit v1.2.3 From 072e1eef2e56f28a4b9c0540e5bd31a8002592d1 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 28 Aug 2022 10:17:08 +0100 Subject: then there are no notes and no feeds dont process them --- lib/atomfeed.source.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/atomfeed.source.sh') diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index 391842a..c5e492f 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -82,6 +82,10 @@ atomfeed::content () { # 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" -- cgit v1.2.3 From e9044cd87daabcb83522a68732e0b96189baf854 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 19 Nov 2022 10:52:17 +0000 Subject: add DRAFT feature --- lib/atomfeed.source.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/atomfeed.source.sh') diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index c5e492f..65afa5a 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -88,6 +88,7 @@ atomfeed::generate () { 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....' -- cgit v1.2.3