diff options
| author | Paul Buetow <paul@buetow.org> | 2023-03-15 01:19:48 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-03-15 01:19:48 +0200 |
| commit | e2648dee7fd93ffc6d6144d46bb0073df718c870 (patch) | |
| tree | 0379884018e545f08e03c79e4d4edf1eb207903b | |
| parent | 365a195cc0362bfeb52ebc0e9cb958b0b455aac4 (diff) | |
fix cache bug
| -rwxr-xr-x | gemtexter | 1 | ||||
| -rw-r--r-- | lib/atomfeed.source.sh | 24 | ||||
| -rw-r--r-- | lib/template.source.sh | 3 |
3 files changed, 22 insertions, 6 deletions
@@ -11,7 +11,6 @@ declare -r DATE_FORMAT='--iso-8601=seconds' declare DATE=date declare SED=sed declare GREP=grep -declare BASH=bash declare XMLLINT='' which gdate &>/dev/null && DATE=gdate which gsed &>/dev/null && SED=gsed 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" +} diff --git a/lib/template.source.sh b/lib/template.source.sh index 1b0df9d..26d5acb 100644 --- a/lib/template.source.sh +++ b/lib/template.source.sh @@ -8,7 +8,7 @@ template::generate () { fi num_tpl_files=$(( num_tpl_files + 1 )) template::_generate "$tpl_path" & - done < <(find "$CONTENT_BASE_DIR/gemtext" -type f -name \*.tpl) + done < <(find "$CONTENT_BASE_DIR/gemtext" -type f -name \*.gmi.tpl) wait log INFO "Converted $num_tpl_files template files" @@ -35,6 +35,7 @@ template::_generate () { done < "$tpl" > "$dest.tmp" mv "$dest.tmp" "$dest" + cd - } template::_line () { |
