From 90621c2c82ff6c965496685f0ad165ccd9b69fc7 Mon Sep 17 00:00:00 2001 From: nytpu Date: Wed, 14 Oct 2020 09:40:13 -0600 Subject: [PATCH] updated to add separators between years and months --- README.md | 6 +++- gemlog.sh | 83 +++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 0b67ffa..9ebd418 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,13 @@ Utility for writing and managing gemini logs (gemlogs) and atom feeds without needing a cgi script. +After 0.2.0, I'm no longer having my personal configuration on master, but as +I'm replacing it with placeholder data, it may have a conflict for this one +upgrade. Sorry for the inconvenience. + Dependencies: other than `toot` you really should have all these installed if you're on linux. -* bash and all its goodies (duh) +* `bash` and all its goodies (duh) * `perl` * `date` * `tr` diff --git a/gemlog.sh b/gemlog.sh index e3cf6a0..5f0c10c 100755 --- a/gemlog.sh +++ b/gemlog.sh @@ -16,26 +16,37 @@ # along with this program. If not, see . -# to customize, modify variables here and modify build_entries() +# change configuration variables here to suit you +### be sure to also change the header and footer in build_entries! ### make_globals() { - global_title="yet another tech gemlog" - global_description="yatg" - global_url="gemini://nytpu.com/gemlog/" # link to base url of gemlog - global_author="nytpu" - global_author_email="alex@nytpu.com" - global_author_url="gemini://nytpu.com/" # homepage of author - global_license="CC BY-SA 4.0" + global_title="my gemlog" + global_description="a gemlog about gemlogs" + global_url="gemini://example.com/gemlog/" # link to base url of gemlog + global_author="example" + global_author_email="you@example.com" + global_author_url="gemini://example.com/" # homepage of author + global_license="CC BY 4.0" gemlog_feed="atom.xml" # filename of the atom feed number_of_feed_articles="50" # maximum number of posts added to atom feed - feed_base_url="https://nytpu.com/files/" # base url that the feed is hosted at + feed_base_url="gemini://example.com/gemlog/" # base url that the feed is hosted at + feed_web_url="https://example.com/files/" # base url that the feed is hosted at on the web index="index.gmi" # main page of gemlog, not recommended to change + use_year_divider=true # separate posts from different years with a heading? + + # these 2 are exclusive, and use_month_divider_nl takes priority if both are set + use_month_divider_nl=true # separate posts from different months with a newline? + use_month_divider_hd=false # separate posts from different months with a heading? + + + gemlog_sh_link="https://tildegit.org/nytpu/gemlog.sh" # link to the utility, you should change this if you've made substantial non-configuration changes + # don't change these - gemlog_sh_link="https://tildegit.org/nytpu/gemlog.sh" # link to the utility, you should change this if you modified it substantially date_format_8601="+%Y-%m-%dT%H:%M:%S%:z" # *formal* ISO-8601 format including time zone - date_format_8601_timeless="+%Y-%m-%dT12:00:00%:z" # *formal* ISO-8601 format including time zone + date_format_8601_timeless="+%Y-%m-%dT12:00:00%:z" # *formal* ISO-8601 format with fixed preset time + monthnames=( "invalid" "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec" ) } get_post_title() { @@ -69,7 +80,7 @@ make_atom() { EOF n=0 while IFS='' read -r i; do - ((n >= number_of_feed_articles)) && break + ((n >= $number_of_feed_articles)) && break printf "\n \n " get_post_title "$i" | tr -d '\n' printf "\n $global_url${i#'./'}\n" @@ -97,23 +108,42 @@ build_entries() { { # header of the page (above the posts list) cat << 'EOF' -```yet another tech gemlog (yatg) by nytpu - ,───────────────. - (_\ _________ \ __ - │ /__|___|__\ │ __ ______ _/ /_____ _ - │ `. \ / ,' │ / / / / __ `/ __/ __ `/ - │ `.\ /,' │ / /_/ / /_/ / /_/ /_/ / - │ `.' │ \__, /\__,_/\__/\__, / - │ YET ANOTHER │ /____/ /____/ - _│ TECH GEMLOG │ by nytpu - (_/_______________/ +```wow, alt text! wouldn't you love to help people with screenreaders too? +┌──────────────────┐ +│ │ +│ YOUR │ +│ │ +│ ART │ +│ │ +│ HERE │ +│ │ +└──────────────────┘ ``` +it's my gemlog all right! EOF + curyear="" + curmonth="" while IFS='' read -r i; do post=$(basename $i) title=$(get_post_title "$i") pubdate=$(echo $i | perl -ne '/^(\d{4}-\d{2}-\d{2}).*/; print $1') + + newcuryear=$(echo $i | perl -ne '/^(\d{4})-\d{2}-\d{2}.*/; print $1') + newcurmonth=$(echo $i | perl -ne '/^\d{4}-(\d{2})-\d{2}.*/; print $1') + if [ "$newcuryear" != "$curyear" ] && $use_year_divider; then + printf "\n\n## $newcuryear\n" + curyear="$newcuryear" + fi + if [ "$newcurmonth" != "$curmonth" ]; then + if $use_month_divider_nl; then + printf "\n" + elif $use_month_divider_hd; then + printf "\n### ${monthnames[${newcurmonth#0}]}\n\n" + fi + curmonth="$newcurmonth" + fi + printf "=> $global_url$post $pubdate — $title\n" done < <(ls -r [[:digit:]]*.gmi) @@ -121,15 +151,14 @@ EOF cat << EOF -⁂ +────────────────── => / go home -=> /gemlog/old/ click here to view an archive of my old gemlog => $feed_base_url$gemlog_feed this gemlog has an atom feed at: $feed_base_url$gemlog_feed -=> gemini://nytpu.com/gemlog/$gemlog_feed or through gemini at: gemini://nytpu.com/gemlog/$gemlog_feed +=> $feed_web_url$gemlog_feed or through the web at: $feed_web_url$gemlog_feed -=> https://tildegit.org/nytpu/gemlog.sh generated with gemlog.sh +=> $gemlog_sh_link generated with gemlog.sh EOF } 3>&1 >"$indexfile" @@ -145,7 +174,7 @@ toot() { then echo "tooting..." # change this if you want the toot to have different content - printf "new gemlog post: ${title}\n\ngemini://nytpu.com/gemlog/${filename}" | toot post + printf "new gemlog post: ${title}\n\n${global_url}${filename}\n" | toot post fi }