aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-09-25 22:35:10 +0200
committerPhilip Wittamore <philip@wittamore.com>2025-09-25 22:35:10 +0200
commite19f6298c7256972f9175bc2c9e1bb7c22d6249e (patch)
tree0691a8b2132f046426d0e783495e23ab2eca6c1d
parent503f8bd3eac1848cd2b472f64ab76c1bb8a41cb1 (diff)
downloadscripts-e19f6298c7256972f9175bc2c9e1bb7c22d6249e.tar.gz
scripts-e19f6298c7256972f9175bc2c9e1bb7c22d6249e.tar.bz2
scripts-e19f6298c7256972f9175bc2c9e1bb7c22d6249e.zip
update
-rwxr-xr-xphlogrss74
-rwxr-xr-xphlogthis51
2 files changed, 125 insertions, 0 deletions
diff --git a/phlogrss b/phlogrss
new file mode 100755
index 0000000..2b24856
--- /dev/null
+++ b/phlogrss
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+phloglink="gopher://spike.nagatha.fr/0/phlog"
+description="Phil&#39;s Phlog"
+rsslink=gopher://spike.nagatha.fr/phlog/rss.xml
+feedname=$HOME/src/gopher/phlog/rss.xml
+postDir=$HOME/src/gopher/phlog
+updated=$(date --iso-8601=ns)
+
+# Build RSS header & footer
+header () {
+echo "<?xml version='1.0' encoding='UTF-8' ?>
+<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>" > ~/feedtop
+echo "
+<channel>
+<title>Phil&#39;s Phlog</title>
+<link>gopher://spike.nagatha.fr</link>
+<description>A Gopher phlog from Brittany, France</description>
+<lastBuildDate>$updated</lastBuildDate>
+<atom:link href='$rsslink' rel='self' type='application/rss+xml' />
+" >> ~/feedtop
+}
+
+footer () {
+echo "
+</channel>
+
+</rss>
+" >> ~/feedbottom
+}
+
+# Function: Build Item add to feed
+
+item () {
+ echo "<item>
+ <title>$fullTitle</title>
+ <pubDate>$postdate</pubDate>
+ <link>$linkadd</link>
+ <guid>$linkadd</guid>
+ <description>$description</description>
+</item>" >> ~/feed
+}
+
+# Function: Concatenate everything
+
+combine () {
+ header
+ footer
+ cat ~/feedtop ~/feed > ~/feedtb
+ cat ~/feedtb ~/feedbottom > $feedname
+ rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
+}
+
+# Run through files and create rss.xml
+
+if [[ -f $feedname ]]; then
+ rm $feedname
+fi
+touch $feedname
+mapfile -t postArray < <(ls -t "$postDir"/*.txt)
+postNum=0
+for posts in "${postArray[@]}"; do
+ ((postNum+=1))
+ post=$posts
+ fullTitle=$(head -n1 "$post" | sed 's/title://g')
+ postdate=$(cat $post | sed -n '2p' | sed 's/date://g')
+ postname=${post##*/}
+ linkadd="$phloglink/$postname"
+ description="$(cat $post | sed -n "/^$/,/^$/p" | head --lines 3) …"
+ item "$post"
+done
+ combine
+exit
+
diff --git a/phlogthis b/phlogthis
new file mode 100755
index 0000000..cef6049
--- /dev/null
+++ b/phlogthis
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# create text, assemble html file, add to articles
+
+root=$HOME/src/gopher/phlog
+
+mkdir -p $HOME/.tmp
+pushd "$(pwd)"
+cd $HOME/.tmp || exit
+editfile="phlogtmp.txt"
+articledate="$(date -R)"
+filedate="$(date +%Y-%m-%d-%H-%I)"
+
+read -r -p "Enter title: " title
+
+filetitle=$(echo $title | sed 's/ /-/g' | sed 's/[^A-Za-z0-9._-]//g')
+article=$filedate-$filetitle.txt
+
+dest="$root/$article"
+
+micro +4:1 "$editfile"
+
+# article
+cat "$editfile" | par -jw67 >> "$article"
+
+header="title:$title\ndate:$articledate\n\n"
+sed -i "1s/^/$header/" $article
+
+mv "$article" "$dest"
+rm $editfile
+echo "Article saved as $dest"
+
+# create gophermap
+
+cd $root
+
+echo "╔═══════════════════════════════════╗" > gophermap
+echo "║ Phil's Phlog ║" >> gophermap
+echo "╚═══════════════════════════════════╝" >> gophermap
+echo "" >> gophermap
+echo "0[Rss feed] /phlog/rss.xml spike.nagatha.fr 70" >> gophermap
+echo "" >> gophermap
+
+
+files=($(ls -1r *.txt))
+for file in "${files[@]}"; do
+ echo -e "0$(head -n 1 $file | sed s/title://g)\t/phlog/$file\tspike.nagatha.fr\t70" >> gophermap
+done
+
+popd
+exit 0