#!/usr/bin/env bash
# Copyright 2020 nytpu
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
# fill out variables here
make_globals() {
global_title="yatb"
global_description="yet another tech blog"
global_url="gemini://nytpu.com/gemlog/" # link to base url of blog
global_author="nytpu"
global_license="CC by"
gemlog_feed="feed.rss" # filename of the rss feed
number_of_feed_articles="50" # number of posts in rss feed
feed_base_url="https://nytpu.com/blog/" # base url that the feed is hosted at
index="index.gmi" # main page, not recommended to change
# don't change these
date_format_full="%a, %d %b %Y %H:%M:%S %z"
date_format_timestamp="%Y%m%d%H%M.%S"
}
get_post_title() {
cat "$1" | perl -lne 's/#{1,3}\s+(.*)/\1/ or next; print; exit'
}
# from bashblog (https://tildegit.org/team/bashblog)
# bashblog is licensed under the gnu gplv3
make_rss() {
echo "Making RSS"
rssfile="$gemlog_feed.$RANDOM"
while [[ -f $rssfile ]]; do rssfile="feed.rss.$RANDOM"; done
{
pubdate=$(LC_ALL=C date +"$date_format_full")
echo ''
echo ''
echo "$global_title$global_url$index"
echo "$global_descriptionen"
echo "$pubdate"
echo "$pubdate"
echo ""
n=0
while IFS='' read -r i; do
((n >= number_of_feed_articles)) && break
echo ""
get_post_title "$i"
echo "$global_url${i#'./'}"
echo "$global_url${i#'./'}"
echo "$global_author"
echo "$(LC_ALL=C date -r "$i" +"$date_format_full")"
n=$(( n + 1 ))
done < <(ls -r ./[[:digit:]]*.gmi)
echo ''
} 3>&1 >"$rssfile"
mv "$rssfile" "$gemlog_feed"
chmod 644 "$gemlog_feed"
}
# change this to what you want
build_entries() {
echo "Building entries"
{
printf "# yatg (yet another tech gemlog)"
printf "## by nytpu"
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')
printf "=> $global_url$post $pubdate — $title\r\n"
done < <(ls -r [[:digit:]]*.gmi)
printf "\r\n\r\n"
printf "=> / go home\r\n"
printf "\r\n"
printf "this gemlog has an rss feed at:\r\n"
printf "=> https://www.nytpu.com/files/feed.rss [https] https://www.nytpu.com/files/feed.rss\r\n"
printf "\r\n"
printf "=> /gemlog/old/ click here to view an archive of my old gemlog"
} 3>&1 >"$index"
}
make_globals
make_rss
build_entries