summaryrefslogtreecommitdiff
path: root/lib/atomfeed.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-03-15 01:19:48 +0200
committerPaul Buetow <paul@buetow.org>2023-03-15 01:19:48 +0200
commite2648dee7fd93ffc6d6144d46bb0073df718c870 (patch)
tree0379884018e545f08e03c79e4d4edf1eb207903b /lib/atomfeed.source.sh
parent365a195cc0362bfeb52ebc0e9cb958b0b455aac4 (diff)
fix cache bug
Diffstat (limited to 'lib/atomfeed.source.sh')
-rw-r--r--lib/atomfeed.source.sh24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh
index 253af53..918c0f3 100644
--- a/lib/atomfeed.source.sh
+++ b/lib/atomfeed.source.sh
@@ -5,7 +5,7 @@ atomfeed::_from_cache () {
if [ ! -f "${cache_file_path}.info" ]; then
# No cache there.
return 1
- elif ! diff "${cache_file_path}.info" <(ls -l "$gmi_file_path"); then
+ elif ! diff "${cache_file_path}.info" <(ls -l "$gmi_file_path") >/dev/null; then
# Need to refresh the cache.
return 1
fi
@@ -113,10 +113,11 @@ atomfeed::_entry () {
# Extract the date from the file name.
local date=$($SED -n '/^> Published at / { s/.*Published at //; s/;.*//; p; }' "$gemfeed_dir/$gmi_file")
if [ -z "$date" ]; then
- # Extract the date from the file name.
- local filename_date=$(cut -d- -f1,2,3 <<< "$gmi_file")
- date=$($DATE $DATE_FORMAT --date "$filename_date $($DATE +%H:%M:%S)")
+ # Extract the date from the file.
+ date=$($DATE $DATE_FORMAT --reference "$gemfeed_dir/$gmi_file")
log WARN "No publishing date specified for $gmi_file, assuming $date"
+ atomfeed::_insert_date "$date" "$gemfeed_dir/$gmi_file"
+
fi
assert::not_empty publishing_date "$date"
@@ -152,3 +153,18 @@ atomfeed::_xmllint () {
log WARN 'Skipping XMLLinting Atom feed as "xmllint" command is no installed!'
fi
}
+
+atomfeed::_insert_date () {
+ local -r date="$1"; shift
+ local -r gmi_file_path="$1"; shift
+
+ # Insert below first header
+ {
+ $SED '/^#/q' "$gmi_file_path"
+ echo
+ echo "> Published at $date"
+ $SED -n '/^#/,$p' "$gmi_file_path" | $SED 1d
+ } > "$gmi_file_path.insert.tmp"
+
+ mv "$gmi_file_path.insert.tmp" "$gmi_file_path"
+}