summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgemtexter1
-rw-r--r--lib/atomfeed.source.sh24
-rw-r--r--lib/template.source.sh3
3 files changed, 22 insertions, 6 deletions
diff --git a/gemtexter b/gemtexter
index 8afdab7..a76e219 100755
--- a/gemtexter
+++ b/gemtexter
@@ -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 () {