2020-09-02 22:52:31 +00:00
#!/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 <https://www.gnu.org/licenses/>.
# fill out variables here
make_globals( ) {
2020-09-04 02:13:10 +00:00
global_title = "yatg"
global_description = "yet another tech gemlog"
2020-09-02 22:52:31 +00:00
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
2020-09-03 15:20:58 +00:00
feed_base_url = "https://nytpu.com/files/" # base url that the feed is hosted at
2020-09-02 22:52:31 +00:00
index = "index.gmi" # main page, not recommended to change
2020-09-03 02:16:07 +00:00
2020-09-02 22:52:31 +00:00
# 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 "
2020-09-05 01:16:43 +00:00
while [ [ -f $rssfile ] ] ; do rssfile = " $gemlog_feed . $RANDOM " ; done
2020-09-02 22:52:31 +00:00
{
pubdate = $( LC_ALL = C date +" $date_format_full " )
2020-09-03 02:16:07 +00:00
echo '<?xml version="1.0" encoding="UTF-8" ?>'
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">'
2020-09-02 22:52:31 +00:00
echo " <channel><title> $global_title </title><link> $global_url $index </link> "
echo " <description> $global_description </description><language>en</language> "
echo " <lastBuildDate> $pubdate </lastBuildDate> "
echo " <pubDate> $pubdate </pubDate> "
2020-09-03 15:27:53 +00:00
echo " <atom:link href=\" $feed_base_url $gemlog_feed \" rel=\"self\" type=\"application/rss+xml\" /> "
2020-09-03 02:16:07 +00:00
2020-09-02 22:52:31 +00:00
n = 0
while IFS = '' read -r i; do
( ( n >= number_of_feed_articles) ) && break
2020-09-03 02:16:07 +00:00
echo "<item><title>"
2020-09-02 22:52:31 +00:00
get_post_title " $i "
2020-09-03 15:27:53 +00:00
echo " </title><description>You need a gemini protocol client to view this post.<br>If you have one installed, click here to open the post: <a href=\" $global_url ${ i # './' } \"> $global_url ${ i # './' } </a></description><link> $global_url ${ i # './' } </link> "
2020-09-03 02:16:07 +00:00
echo " <guid> $global_url ${ i # './' } </guid> "
echo " <dc:creator> $global_author </dc:creator> "
2020-09-02 22:52:31 +00:00
echo " <pubDate> $( LC_ALL = C date -r " $i " +" $date_format_full " ) </pubDate></item> "
2020-09-03 02:16:07 +00:00
2020-09-02 22:52:31 +00:00
n = $(( n + 1 ))
done < <( ls -r ./[ [ :digit:] ] *.gmi)
2020-09-03 02:16:07 +00:00
2020-09-02 22:52:31 +00:00
echo '</channel></rss>'
} 3>& 1 >" $rssfile "
mv " $rssfile " " $gemlog_feed "
chmod 644 " $gemlog_feed "
}
# change this to what you want
build_entries( ) {
echo "Building entries"
{
2020-09-03 15:31:40 +00:00
sed 's/$/\r/g' << 'EOF'
2020-09-03 22:49:01 +00:00
` ` ` yet another tech gemlog ( yatg) by nytpu
2020-09-03 05:06:37 +00:00
,───────────────.
( _\ _________ \ __
2020-09-03 02:16:07 +00:00
│ /__| ___| __\ │ __ ______ _/ /_____ _
│ ` . \ / ,' │ / / / / __ ` / __/ __ ` /
│ ` .\ /,' │ / /_/ / /_/ / /_/ /_/ /
│ ` .' │ \_ _, /\_ _,_/\_ _/\_ _, /
│ YET ANOTHER │ /____/ /____/
_│ TECH GEMLOG │ by nytpu
( _/_______________/
` ` `
2020-09-02 22:52:31 +00:00
2020-09-03 02:16:07 +00:00
EOF
2020-09-02 22:52:31 +00:00
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"
2020-09-02 23:46:20 +00:00
printf "=> / go home\r\n"
2020-09-02 23:44:43 +00:00
printf "\r\n"
2020-09-02 23:47:12 +00:00
printf "this gemlog has an rss feed at:\r\n"
2020-09-05 01:16:43 +00:00
printf " => $feed_base_url $gemlog_feed [https] $feed_base_url $gemlog_feed \r\n "
printf "=> /gemlog/feed.rss or here to access it through gemini\r\n"
2020-09-02 23:32:59 +00:00
printf "\r\n"
2020-09-02 23:50:39 +00:00
printf "=> /gemlog/old/ click here to view an archive of my old gemlog"
2020-09-02 22:52:31 +00:00
} 3>& 1 >" $index "
}
2020-09-03 02:16:07 +00:00
toot( ) {
filename = $( ls -r ./[ [ :digit:] ] *.gmi | head -n 1 | xargs basename)
title = $( get_post_title " $filename " )
read -r -p "do you want to toot the newest post? [y/N] " response
if [ [ " $response " = ~ ^( [ yY] [ eE] [ sS] | [ yY] ) $ ] ]
then
printf " new blog post: ${ title } \n\ngemini://nytpu.com/gemlog/ ${ filename } " | toot post
fi
}
2020-09-02 22:52:31 +00:00
make_globals
make_rss
build_entries
2020-09-03 02:16:07 +00:00
toot
2020-09-02 22:52:31 +00:00