summaryrefslogtreecommitdiff
path: root/feed.sh
diff options
context:
space:
mode:
Diffstat (limited to 'feed.sh')
-rwxr-xr-xfeed.sh111
1 files changed, 111 insertions, 0 deletions
diff --git a/feed.sh b/feed.sh
new file mode 100755
index 0000000..44df5fb
--- /dev/null
+++ b/feed.sh
@@ -0,0 +1,111 @@
+#!/bin/bash
+
+# taken from https://github.com/maxhebditch/rss-roller/
+# modified by Mohit Agarwal
+
+
+# Configuration
+title="Unorthodox Monologues"
+link="https://mohit.uk/blogs/unmono"
+description="Abby's Blog"
+rsslink="$link/feed.xml"
+feedname="./feed.xml"
+postDir="./unmono/"
+
+
+echo "./feed.sh------------------------------------------------"
+echo " Feed builder RSS/ATOM"
+echo " Written by Mohit Agarwal"
+echo " INTERNAL USE ONLY"
+echo "---------------------------------------------------------"
+
+echo ""
+echo "TITLE" $title
+echo "LINK " $link
+echo "RSS L" $rsslink
+echo "RSS F" $feedname
+echo "DESCR" $description
+echo "POSTD" $postDir
+
+
+header () {
+echo """<?xml version='1.0' encoding='UTF-8' ?>
+<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
+<!-- Made using rss-roller https://github.com/maxhebditch/rss-roller -->
+""" > ~/feedtop
+echo """
+<channel>
+<title>$title</title>
+<link>$link</link>
+<description>$description</description>
+<atom:link href='$rsslink' rel='self' type='application/rss+xml' />
+""" >> ~/feedtop
+}
+
+footer () {
+echo """
+</channel>
+</rss>
+""" >> ~/feedbottom
+}
+
+item () {
+ echo """<item>
+ <title>$fullTitle</title>
+ <link>$linkadd</link>
+ <guid>$guid</guid>
+ <content>
+ $fullText
+ </content>
+
+ <description>
+ $fullText
+ </description>
+ </item>
+ """ >> ~/feed
+ echo """<item>
+ <title>$fullTitle</title>
+ <link>$linkadd</link>
+ <guid isPermaLink='false'>$guidadd</guid>
+ </item>
+ """ >> ~/feed
+}
+
+combine () {
+ header
+ footer
+ cat ~/feedtop ~/feed > ~/feedtb
+ cat ~/feedtb ~/feedbottom > $feedname
+ rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
+}
+
+
+
+if [[ ! -f $feedname ]]; then
+ touch $feedname
+fi
+
+echo ""
+echo "BUILDING FEED"
+#Do the bad thing
+if [[ -f $feedname ]]; then
+ rm $feedname
+fi
+touch $feedname
+postArray=( $(ls -r "$postDir"/*.html | grep -v index.html) )
+numPosts=$(ls -r "$postDir"/*.html | grep -v index.html | wc -l)
+echo "numPosts is $numPosts"
+postNum=0
+guidadd=$linkadd
+for posts in "${postArray[@]}"; do
+ let postNum+=1
+ post=$posts
+ echo " adding post $postNum/$numPosts : $post"
+ fullTitle=$(grep -o '>.*</h1>' $post | sed 's/\(>\|<\/h1>\)//g')
+ postname=${post##*/}
+ linkadd="$link"/"$postname"
+ fullText=$(pandoc ../${post/%html/md} -t html)
+ item $post
+done
+combine
+exit