updated to add separators between years and months

This commit is contained in:
nytpu 2020-10-14 09:40:13 -06:00
parent bc710a3edd
commit c1fbbdbd1d
Signed by: nytpu
GPG Key ID: ECCDC07B337B8F5B
2 changed files with 61 additions and 28 deletions

View File

@ -3,9 +3,13 @@
Utility for writing and managing gemini logs (gemlogs) and atom feeds without Utility for writing and managing gemini logs (gemlogs) and atom feeds without
needing a cgi script. 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: Dependencies:
other than `toot` you really should have all these installed if you're on linux. 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` * `perl`
* `date` * `date`
* `tr` * `tr`

View File

@ -16,26 +16,37 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# 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() { make_globals() {
global_title="yet another tech gemlog" global_title="my gemlog"
global_description="yatg" global_description="a gemlog about gemlogs"
global_url="gemini://nytpu.com/gemlog/" # link to base url of gemlog global_url="gemini://example.com/gemlog/" # link to base url of gemlog
global_author="nytpu" global_author="example"
global_author_email="alex@nytpu.com" global_author_email="you@example.com"
global_author_url="gemini://nytpu.com/" # homepage of author global_author_url="gemini://example.com/" # homepage of author
global_license="CC BY-SA 4.0" global_license="CC BY 4.0"
gemlog_feed="atom.xml" # filename of the atom feed gemlog_feed="atom.xml" # filename of the atom feed
number_of_feed_articles="50" # maximum number of posts added to 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 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 # 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="+%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() { get_post_title() {
@ -69,7 +80,7 @@ make_atom() {
EOF EOF
n=0 n=0
while IFS='' read -r i; do while IFS='' read -r i; do
((n >= number_of_feed_articles)) && break ((n >= $number_of_feed_articles)) && break
printf "\n <entry>\n <title>" printf "\n <entry>\n <title>"
get_post_title "$i" | tr -d '\n' get_post_title "$i" | tr -d '\n'
printf "</title>\n <id>$global_url${i#'./'}</id>\n" printf "</title>\n <id>$global_url${i#'./'}</id>\n"
@ -97,23 +108,42 @@ build_entries() {
{ {
# header of the page (above the posts list) # header of the page (above the posts list)
cat << 'EOF' cat << 'EOF'
```yet another tech gemlog (yatg) by nytpu ```wow, alt text! wouldn't you love to help people with screenreaders too?
,───────────────. ┌──────────────────┐
(_\ _________ \ __ │ │
│ /__|___|__\ │ __ ______ _/ /_____ _ │ YOUR │
`. \ / ,' │ / / / / __ `/ __/ __ `/ │ │
`.\ /,' │ / /_/ / /_/ / /_/ /_/ / │ ART │
`.'\__, /\__,_/\__/\__, / │ │
│ YET ANOTHER │ /____/ /____/ │ HERE │
_│ TECH GEMLOG │ by nytpu │ │
(_/_______________/ └──────────────────┘
``` ```
it's my gemlog all right!
EOF EOF
curyear=""
curmonth=""
while IFS='' read -r i; do while IFS='' read -r i; do
post=$(basename $i) post=$(basename $i)
title=$(get_post_title "$i") title=$(get_post_title "$i")
pubdate=$(echo $i | perl -ne '/^(\d{4}-\d{2}-\d{2}).*/; print $1') 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" printf "=> $global_url$post $pubdate$title\n"
done < <(ls -r [[:digit:]]*.gmi) done < <(ls -r [[:digit:]]*.gmi)
@ -121,15 +151,14 @@ EOF
cat << EOF cat << EOF
──────────────────
=> / go home => / 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 => $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 EOF
} 3>&1 >"$indexfile" } 3>&1 >"$indexfile"
@ -145,7 +174,7 @@ toot() {
then then
echo "tooting..." echo "tooting..."
# change this if you want the toot to have different content # 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 fi
} }