summaryrefslogtreecommitdiff
path: root/old/update-feed.sh
diff options
context:
space:
mode:
authorSteph Enders <steph@senders.io>2024-02-29 09:31:15 -0500
committerSteph Enders <steph@senders.io>2024-02-29 09:31:15 -0500
commit2b39175011422a0d8f96d7f598f46e2a781dd28f (patch)
treedd896a1e35e2ec194bfce829afd61f553652464a /old/update-feed.sh
parent350a5058cf383733a7e75f753abdcd1cb7aae2c5 (diff)
Initial rework commit: Build Script POC and CSS done
I've created the main CSS layout and a proof of concept for the build script: this will actually build any "done" _post/ file and generate it as a workable HTML file. However, no index file generate, rss, or gemini is implemented
Diffstat (limited to 'old/update-feed.sh')
-rwxr-xr-xold/update-feed.sh79
1 files changed, 79 insertions, 0 deletions
diff --git a/old/update-feed.sh b/old/update-feed.sh
new file mode 100755
index 0000000..5b0785b
--- /dev/null
+++ b/old/update-feed.sh
@@ -0,0 +1,79 @@
+#!/usr/bin/env bash
+set -ex
+
+# static info
+## tokens
+TKN_BUILDDATE='#BUILDDATE'
+TKN_PUBDATE='#PUBDATE'
+TKN_TITLE='#TITLE'
+TKN_LINK='#LINK'
+TKN_PERMALINK='#PERMALINK'
+
+URL_PREFIX="https://www.senders.io"
+TKN_URL_STRIP="./www" # remove www file prefix for URL/LINK
+TKN_INDEX_STRIP="index.html" # remove index.html for LINK
+
+FILE_RSS_HEADER=./templates/rss/rss-header.xml
+FILE_RSS_FOOTER=./templates/rss/rss-footer.xml
+FILE_RSS_ITEM_HEADER=./templates/rss/rss-item-header.xml
+FILE_RSS_ITEM_FOOTER=./templates/rss/rss-item-footer.xml
+FILE_ITEM_OUTPUT=./rss/items.xml
+FILE_RSS_OUTPUT=./www/blog/feed.rss
+
+
+# dynamic info
+FILE_TMP_FEED=$(mktemp --suffix=.xml)
+FILE_TMP_ITEM=$(mktemp --suffix=.xml)
+BUILDDATE=$(date -R)
+
+# user input
+
+if [ $# -ne 3 ]; then
+ echo "./update-feed.sh PUBDATE TITLE FILE_PATH
+ Examples:
+ ./update-feed.sh 2022-12-31 \"Generating RSS feeds with bash\" ./www/blog/2022-12-31/index.html"
+ exit 1
+fi
+
+PUBDATE=$(date -d "$1" -R)
+TITLE=$2
+FILE_PATH=$3
+PERMALINK=$(echo "${FILE_PATH}" | sed -e "s,${TKN_URL_STRIP},${URL_PREFIX},g")
+LINK=$(echo "${PERMALINK}" | sed -e "s,${TKN_INDEX_STRIP},,g")
+
+# Generate TMP FEED File Header
+
+cat -s $FILE_RSS_HEADER > $FILE_TMP_FEED
+sed -i -E "s/${TKN_BUILDDATE}/${BUILDDATE}/g" $FILE_TMP_FEED
+sed -i -E "s/${TKN_PUBDATE}/${PUBDATE}/g" $FILE_TMP_FEED
+
+# Generate TMP Item File
+
+cat -s $FILE_RSS_ITEM_HEADER > $FILE_TMP_ITEM
+sed -i -E "s~${TKN_TITLE}~${TITLE}~g" $FILE_TMP_ITEM
+sed -i -E "s/${TKN_PUBDATE}/${PUBDATE}/g" $FILE_TMP_ITEM
+sed -i -E "s,${TKN_PERMALINK},${PERMALINK},g" $FILE_TMP_ITEM
+sed -i -E "s,${TKN_LINK},${LINK},g" $FILE_TMP_ITEM
+sed -n "/<article>/,/<\/article>/p" $FILE_PATH >> $FILE_TMP_ITEM
+cat -s $FILE_RSS_ITEM_FOOTER >> $FILE_TMP_ITEM
+
+# Prepend Item to items list and overwrite items file w/ prepended item
+## In order to "prepend" the item (so it's on top of the others)
+## We need to concat the tmp item file with the existing list, then
+## we can push the contents over the existing file
+## We use cat -s to squeeze the blank lines
+cat -s $FILE_ITEM_OUTPUT >> $FILE_TMP_ITEM
+cat -s $FILE_TMP_ITEM > $FILE_ITEM_OUTPUT
+
+# Push items to TMP FEED
+cat -s $FILE_ITEM_OUTPUT >> $FILE_TMP_FEED
+
+# Push RSS footer to TMP FEED
+cat -s $FILE_RSS_FOOTER >> $FILE_TMP_FEED
+echo $FILE_TMP_FEED
+
+# Publish feed
+cat -s $FILE_TMP_FEED > $FILE_RSS_OUTPUT
+
+echo "Finished generating feed"
+