diff options
author | Bill <bill@billserver.senders.io> | 2022-12-31 21:14:51 -0500 |
---|---|---|
committer | Bill <bill@billserver.senders.io> | 2022-12-31 21:14:51 -0500 |
commit | b5b85066bc8bfa6db6eaa33e3f14c0eaafafe5af (patch) | |
tree | 892d12491371353e35702de396a12b82bb57f580 /update-feed.sh | |
parent | 44da246fa5e373c86373889b53263f52af84d525 (diff) |
RSS Blog and Generate RSS Feed!
Diffstat (limited to 'update-feed.sh')
-rwxr-xr-x | update-feed.sh | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/update-feed.sh b/update-feed.sh new file mode 100755 index 0000000..2061cd4 --- /dev/null +++ b/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" + |