From a453bf2f909e0ea01b0649ce8dc42d54689f738f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 11 May 2021 19:54:23 +0100 Subject: refactor --- modules/atomfeed.source.sh | 104 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 modules/atomfeed.source.sh (limited to 'modules/atomfeed.source.sh') diff --git a/modules/atomfeed.source.sh b/modules/atomfeed.source.sh new file mode 100644 index 0000000..01608fe --- /dev/null +++ b/modules/atomfeed.source.sh @@ -0,0 +1,104 @@ +atomfeed::meta () { + local -r gmi_file_path="$1"; shift + local -r meta_file=$($SED 's|gemtext|meta|; s|.gmi$|.meta|;' <<< "$gmi_file_path") + + local is_draft=no + if grep -E -q '\.draft\.meta$' <<< "$meta_file"; then + is_draft=yes + fi + + local -r meta_dir=$(dirname "$meta_file") + test ! -d "$meta_dir" && mkdir -p "$meta_dir" + + 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 + $DOMAIN feed + $SUBTITLE + + + gemini://$DOMAIN/ +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")" + + cat <> "$atom_file.tmp" + + $meta_title + + gemini://$DOMAIN/gemfeed/$gmi_file + $meta_date + + $meta_author + $meta_email + + $meta_summary + +
+ $content +
+
+
+ATOMENTRY + done < <(gemfeed::get_posts | head -n $ATOM_MAX_ENTRIES) + + cat <> "$atom_file.tmp" +
+ATOMFOOTER + + # Delete the 3rd line of the atom feeds (global feed update timestamp) + if ! diff -u <($SED 3d "$atom_file") <($SED 3d "$atom_file.tmp"); then + echo "Feed got something new!" + mv "$atom_file.tmp" "$atom_file" + test "$ADD_GIT" == yes && git add "$atom_file" + else + echo "Nothing really new in the feed" + rm "$atom_file.tmp" + fi +} -- cgit v1.2.3