diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/atomfeed.source.sh | 47 | ||||
| -rw-r--r-- | lib/gemfeed.source.sh | 4 |
2 files changed, 41 insertions, 10 deletions
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" diff --git a/lib/gemfeed.source.sh b/lib/gemfeed.source.sh index 1b2ee5c..0d9f2f9 100644 --- a/lib/gemfeed.source.sh +++ b/lib/gemfeed.source.sh @@ -3,9 +3,7 @@ gemfeed::get_posts () { local -r gemfeed_dir="$CONTENT_BASE_DIR/gemtext/gemfeed" local -r gmi_pattern='^[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\.gmi$' - ls "$gemfeed_dir" | - $GREP -E "$gmi_pattern" | - sort -r + ls "$gemfeed_dir" | $GREP -E "$gmi_pattern" | sort -r } # Add the links from gemfeed/index.gmi to the main index site. |
