From 706e67ede63b3ff45707e6299c06b50e94e5ecf4 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 12 Mar 2023 18:04:36 +0200 Subject: make meta cache redundant --- lib/atomfeed.source.sh | 123 ++++++++++++++++++++----------------------------- 1 file changed, 51 insertions(+), 72 deletions(-) (limited to 'lib/atomfeed.source.sh') diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index 785246d..6be22a2 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -1,37 +1,3 @@ -# Retrieve meta data of a given blog post. Generate new meta info if not yet exists. -atomfeed::meta () { - local -r gmi_file_path="$1"; shift - local -r meta_file=$($SED 's|gemtext|meta|; s|.gmi$|.meta|;' <<< "$gmi_file_path") - - log VERBOSE "Generating meta info for post $gmi_file_path" - - local -r meta_dir=$(dirname "$meta_file") - if [[ ! -d "$meta_dir" ]]; then - mkdir -p "$meta_dir" - fi - - if [ ! -f "$meta_file" ]; then - # Extract first heading as post title. - local title=$($SED -n '/^# / { s/# //; p; q; }' "$gmi_file_path" | tr '"' "'") - # Extract first paragraph from Gemtext - local summary=$($SED -n '/^[A-Z]/ { p; q; }' "$gmi_file_path" | tr '"' "'") - # Extract the date from the file name. - local filename_date=$(basename "$gmi_file_path" | cut -d- -f1,2,3) - local date=$($DATE --iso-8601=seconds --date "$filename_date $($DATE +%H:%M:%S)") - - cat < "$atom_file.tmp" - $now + $($DATE $DATE_FORMAT) $DOMAIN feed $SUBTITLE @@ -111,37 +73,7 @@ atomfeed::generate () { ATOMHEADER while read -r gmi_file; do - # Load cached meta information about the post. - source <(atomfeed::meta "$gemfeed_dir/$gmi_file") - - # Get HTML content for the feed - local content="$(atomfeed::content "$gemfeed_dir/$gmi_file")" - - assert::not_empty meta_title "$meta_title" - assert::not_empty meta_date "$meta_date" - assert::not_empty meta_author "$meta_author" - assert::not_empty meta_email "$meta_email" - assert::not_empty meta_summary "$meta_summary" - assert::not_empty content "$content" - - cat <> "$atom_file.tmp" - - $meta_title - - gemini://$DOMAIN/gemfeed/$gmi_file - $meta_date - - $meta_author - $meta_email - - $meta_summary - -
- $content -
-
-
-ATOMENTRY + atomfeed::_entry "$gemfeed_dir" "$gmi_file" "$atom_file.tmp" done < <(gemfeed::get_posts | head -n $ATOM_MAX_ENTRIES) cat <> "$atom_file.tmp" @@ -159,6 +91,53 @@ ATOMFOOTER fi } +atomfeed::_entry () { + local -r gemfeed_dir="$1" + local -r gmi_file="$2" + local -r tmp_atom_file="$3" + + log INFO "Generating Atom feed entry for $gmi_file" + + # Get HTML content for the feed + local content="$(atomfeed::content "$gemfeed_dir/$gmi_file")" + assert::not_empty content "$content" + + # Extract first heading as post title. + local title=$($SED -n '/^# / { s/# //; p; q; }' "$gemfeed_dir/$gmi_file" | tr '"' "'") + assert::not_empty title "$title" + + # Extract first paragraph from Gemtext as the summary. + local summary=$($SED -n '/^[A-Z]/ { p; q; }' "$gemfeed_dir/$gmi_file" | tr '"' "'") + assert::not_empty summary "$summary" + + # Extract the date from the file name. + local publishing_date=$($SED -n '/^> Published at / { s/.*Published at //; s/;.*//; p; }' "$gemfeed_dir/$gmi_file") + if [ -z "$publishing_date" ]; then + publishing_date=$($DATE $DATE_FORMAT -r "$gemfeed_dir/$gmi_file") + log WARN "No publishing date specified for $gmi_file, assuming $publishing_date" + fi + assert::not_empty publishing_date "$publishing_date" + + cat <> "$tmp_atom_file" + + $title + + gemini://$DOMAIN/gemfeed/$gmi_file + $publishing_date + + $AUTHOR + $EMAIL + + $summary + +
+ $content +
+
+
+ATOMENTRY +} + atomfeed::_xmllint () { local -r atom_feed="$1" -- cgit v1.2.3