diff options
| author | Mohit Agarwal <mohit.agarwal@sky.com> | 2025-03-14 18:37:19 +0000 |
|---|---|---|
| committer | Mohit Agarwal <mohit.agarwal@sky.com> | 2025-03-14 18:37:19 +0000 |
| commit | 41ea1757508169957d0ff91ccd94ffea5cc676be (patch) | |
| tree | 40b94e8dcd96020504a7ca6ec169f33bac8b2b68 /feed.sh | |
Diffstat (limited to 'feed.sh')
| -rwxr-xr-x | feed.sh | 111 |
1 files changed, 111 insertions, 0 deletions
@@ -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 |
