commit e072f1a4f98744b18bdca9cabccd80b1a4135a12
parent bc52446eb733b9a9189f6091c235ce84b574df09
Author: pyratebeard <root@pyratebeard.net>
Date: Tue, 21 Dec 2021 11:53:57 +0000
hacky rss feed creation
Diffstat:
M | pyratelog.sh | | | 45 | ++++++++++++++++++++++++++++++++++++++++++--- |
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/pyratelog.sh b/pyratelog.sh
@@ -1,6 +1,28 @@
#!/bin/bash
-function initialise() {
+rssgen() {
+ [ -f rss.xml ] && rm -f rss.xml
+ cat >> rss.xml << EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0">
+<channel>
+ <title>pyratelog</title>
+ <link>https://log.pyratebeard.net</link>
+ <description>another tech blog by another *nix geek</description>
+</channel>
+</rss>
+EOF
+}
+
+xmlencode() {
+ _entry=${1}
+ sed "s/</\<\;/g; s/>/\>\;/g" ${_entry} > ${_entry}.rss
+}
+
+initialise() {
+ # generate rss.xml file
+ rssgen
+
# find all markdown files in 'entry' directory
find_md=$(find entry/ -type f -name "*.md" | sort)
@@ -12,10 +34,14 @@ function initialise() {
# cut the date and turn into epoch time
input_date=$(echo ${input} | cut -f1 -d '-' )
- ls -l /bin/date | grep busybox >/dev/null && \
+ if ls -l /bin/date | grep busybox >/dev/null ; then
# busybox `date` works differently
- index_date=$(date -d ${input_date} -D "%Y%m%d" +%s) || \
+ index_date=$(date -d ${input_date} -D "%Y%m%d" +%s)
+ rss_pubdate="<pubDate>$(date -d ${input_date} -D '%a, %d %b %Y 00:00:00' +%s)</pubDate>"
+ else
index_date=$(date -d ${input_date} +%s)
+ rss_pubdate="<pubDate>$(date -d ${input_date} +'%a, %d %b %Y 00:00:00')</pubDate>"
+ fi
# cut the title and replace underscores with spaces for menu
input_title=$(echo ${input} | cut -f2 -d '-' | sed 's/_/\ /g')
@@ -45,7 +71,20 @@ function initialise() {
# tidy up
rm -f index.html.bak
+
+ # create rss item
+ rss_title="<title>${index_title}</title>"
+ rss_link="<link>https://log.pyratebeard.net/entry/${input}.html</link>"
+ xmlencode entry/${input}.html
+ rss_description=$(cat entry/${input}.html.rss)
+
+ LNR=$(sed = rss.xml | sed -n '/\<description/,/\<\\channel/p' | awk '{print $1}' | head -n2 | tail -n1)
+ #LNR=$(( LNR + 1 ))
+
+ sed -i "${LNR}i \\\t\<item\>\n\t\t${rss_title}\n\t\t${rss_pubdate}\n\t\t${rss_link}\n\t\<\/item\>" rss.xml
+ item_lnr=$(grep -n "${rss_title}" rss.xml | awk -F\: '{print $1}')
done
+
}
# watch the entry directory for new files