Mirror of static site repo git.pfy.ch/pfych/static
Something went wrong. Try again.
title: Better RSS and Hell summary: HELL category: 💻 publishedAt: 1641466800000 #
I think I've reached the limits of
bash. I just wrote the grossest
script to embed my posts into RSS
<description> tags. This is so
people can read my posts in their
reader without coming to my site.
Behold. Filth:
RSS_ITEMS=()
echo "Creating RSS feed..."
cd "$BLOG_LOCATION"
for file in $BLOG_LOCATION/*.md; do
NAME="$(basename "$file")"
TITLE="$(grep "^title:" "$file" | sed 's/[^ ]* //')"
EDIT_TIME="$(git log -1 --pretty="format:%ci" "$file" | cut -d" " -f2)"
PUB_DATE="$(date -d"${NAME%$FILE_PREFIX.md}" +"%a, %d %b %Y ${EDIT_TIME:-$RSS_TIME} $TIMEZONE")"
DRAFT="$(grep "^draft:" "$file" | sed 's/[^ ]* //')"
GUID="$(echo "$FILENAME $PUB_DATE" | md5sum | cut -f1 -d" ")"
FILE_CONTENT=$(cat "${PARENT_PATH}out/blog/${NAME%$FILE_PREFIX.md}.html")
FIXED_IMAGES=$(echo "$FILE_CONTENT" | sed "s/<img src=\"\./<img src=\"https:\/\/pfy\.ch\/blog/g" )
FIXED_QUOTES=$(echo "$FIXED_IMAGES" | sed "s/\“/\"/g" | sed "s/\”/\"/g" | sed "s/\’/\'/g")
FIXED_FILE="${FIXED_QUOTES#*</h1>}"
if [ ! "$DRAFT" ]; then
RSS_ITEMS+=("
<item>
<guid isPermaLink='false'>${GUID}</guid>
<title>${TITLE}</title>
<link>https://${DOMAIN_NAME}/blog/${NAME%$FILE_PREFIX.md}.html</link>
<description><![CDATA[${FIXED_FILE%<\hr />*}]]></description>
<pubDate>${PUB_DATE}</pubDate>
</item>
")
fi
done
cd "$PARENT_PATH"
RSS_STRING=$(printf '%s' "${RSS_ITEMS[@]}" | tr -d '\n')
RSS_OUTPUT="<?xml version='1.0' encoding='ISO-8859-1' ?>
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
<channel>
<title>pfy.ch</title>
<link>https://pfy.ch</link>
<description>pfych blogs</description>
<atom:link href='https://pfy.ch/rss.xml' rel='self' type='application/rss+xml' />
$RSS_STRING
</channel>
</rss>"
echo "$RSS_OUTPUT" > ./out/rss.xml
I hate it.
I will probably rewrite this script in something else now tbh. Idk what language though.
However! Now at least my site is more RSS friendly. Genuinely think more sites should use RSS.