From f3bd162743f7890cb5aad7bc767d593ed4749df9 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 2 Aug 2022 22:47:33 -0500 Subject: Rewrite --- shatom | 258 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 134 insertions(+), 124 deletions(-) diff --git a/shatom b/shatom index 48b99ff..3f9adac 100755 --- a/shatom +++ b/shatom @@ -1,97 +1,105 @@ #!/bin/sh -# generate a Atom feed from a directory, recursively -# using POSIX sh -# AUTHOR: Case Duckworth -# LICENSE: MIT +# SHATOM: generate a feed from a directory of files +# Copyright (C) 2020--2022 Case Duckworth +# Licensed under the Good Choices License. See COPYING for details. -usage() { - cat < $FEED_TITLE @@ -105,60 +113,62 @@ atom_header() { END } -atom_footer() { - cat < END } -atom_entry() { # atom_entry FILE - ENTRY_URL="$(entry_url "$1")" - ENTRY_TITLE="$(entry_title "$1")" - ENTRY_SUMMARY="$(entry_summary "$1")" - ENTRY_AUTHOR="$(entry_author "$1")" - ENTRY_CONTENT="$(entry_content "$1")" - ENTRY_UPDATED="$(entry_updated "$1")" - cat < -$ENTRY_URL - -$ENTRY_TITLE -$ENTRY_SUMMARY -$ENTRY_UPDATED -$ENTRY_AUTHOR - +$ITEM_URL + +$(item_title "$1") +$(item_summary "$1") +$(item_updated "$1") +$(item_author) + END } -main() { - CONFIGFILE="$PWD/$0.conf.sh" - case "$1" in - -h) - usage - exit 0 - ;; - -c) - CONFIGFILE="$2" - shift 2 - ;; - esac - - if [ -f "CONFIGFILE" ]; then - . "$CONFIGFILE" - fi - - atom_header - for DIR; do - for entry in $(recent_files "$DIR" -type f); do - if skip_entry "$entry"; then continue; fi - - atom_entry "$entry" - done - done - atom_footer +## Item-level functions +# These can all be, and in fact should be, changed in the configuration file. + +skip_item() { + return 1 +} + +item_url() { + basename="${1#$DIRECTORY}" + echo "$FEED_URL/$basename" +} + +item_title() { + basename="${1#$DIRECTORY}" + echo "$basename" +} + +item_summary() { + return 1 +} + +item_author() { + echo "$FEED_AUTHOR" +} + +item_content() { + cat "$1" +} + +item_updated() { + # requires stat(1) + stat -c %y "$1" } -if [ $DEBUG ]; then set -x; fi +### Execution section -main "$@" +test -n $DEBUG && set -x +test -n $SOURCE || main "$@" -- cgit 1.4.1-21-gabe81