summaryrefslogtreecommitdiffstats
path: root/rss.sh
diff options
context:
space:
mode:
authorTyler Davis <tyler@gluecode.net>2025-02-13 23:32:44 +0000
committerTyler Davis <tyler@gluecode.net>2025-02-13 23:32:44 +0000
commit2f182b05325c159e618ad1675c007566e9d1694e (patch)
treea26aec8799cefb5b54419cf04aaf8adcec4dd047 /rss.sh
parent0599865ee0d6910e069028ad6d65c6504d95554f (diff)
downloadjournal-2f182b05325c159e618ad1675c007566e9d1694e.tar.gz
journal-2f182b05325c159e618ad1675c007566e9d1694e.zip
rss: fix script and make it work for my design
Diffstat (limited to 'rss.sh')
-rwxr-xr-xrss.sh175
1 files changed, 48 insertions, 127 deletions
diff --git a/rss.sh b/rss.sh
index 821a093..f709a2e 100755
--- a/rss.sh
+++ b/rss.sh
@@ -1,139 +1,60 @@
#!/usr/bin/env bash
-header () {
-echo """<?xml version='1.0' encoding='UTF-8' ?>
-<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
-""" > ~/feedtop
-echo """
-<channel>
-<title>$title</title>
-<link>$link</link>
-<description>$description</description>
-<atom:link href='$rsslink' rel='self' type='application/rss+xml' />
-""" >> ~/feedtop
-echo "adding the header"
-}
+###
+TEMPSUFFIX="$(od -t x1 -An -N6 /dev/urandom | tr -d '\n ')"
+TEMPFILE="/tmp/rss.xml.${TEMPSUFFIX}"
-footer () {
-echo """
-</channel>
+# Make a tempfile for rss feed construction
+touch "${TEMPFILE}"
-</rss>
-""" >> ~/feedbottom
-echo "adding the footer"
-}
+echo "Tempfile at: ${TEMPFILE}"
+###
-item () {
-if [[ $mode == "a" ]]; then
- echo """<item>
- <title>$fullTitle</title>
- <link>$linkadd</link>
- <guid>$guid</guid>
- <description>$extract</description>
- </item>
- """ >> ~/feed
-elif [[ $mode == "m" ]]; then
+title='Glue Code'
+link="https://gluecode.net/blog"
+description='Brain Dump'
+rsslink="https://gluecode.net/blog/rss.xml"
+feedname="/var/www/blog/rss.xml"
+postDir="/var/www/blog/posts"
+
+###
+
+header="""
+<?xml version='1.0' encoding='UTF-8' ?>
+<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
+<channel>
+<title>${title}</title>
+<link>${link}</link>
+<description>${description}</description>
+<atom:link href='${rsslink}' rel='self' type='application/rss+xml' />
+"""
+
+footer="</channel> </rss>"
+
+echo $header >> $TEMPFILE
+
+postArray=( $(ls -r "$postDir"/*/*.html) )
+numPosts=$(ls "$postDir"/*/*.html | wc -l)
+echo "numposts is $numPosts"
+postNum=0
+for posts in "${postArray[@]}"; do
+ let postNum+=1
+ post=$posts
+ fullTitle=$(grep -o '>.*</h1>' $post | sed -e 's,>,,g' -e 's,</h1,,g')
+ postname=${post##*/}
+ linkadd="$link"/"$postname"
+ guidadd=$linkadd
+ LEN=$(wc -l ${post}|awk '{print $1}')
+ extract=$(cat $post | head -n $((${LEN}-1)) | tail -n $((${LEN}-3)) )
echo """<item>
<title>$fullTitle</title>
<link>$linkadd</link>
- <guid isPermaLink='false'>$guidadd</guid>
+ <guid>$linkadd</guid>
<description>$extract</description>
</item>
- """ >> ~/feed
-fi
-}
-
-combine () {
- header
- footer
- cat ~/feedtop ~/feed > ~/feedtb
- cat ~/feedtb ~/feedbottom > $feedname
- rm ~/feedtop ~/feed ~/feedtb ~/feedbottom
-}
-
-makeRSS () {
- echo "feed does not exit already, going to make from scratch"
- echo """
- CONFIGURATION
- =============
- """
- read -p "What is your website called?: (e.g Google) " title
- read -p "What is the link to the website?: (e.g http://google.com) " link
- read -p "Give a brief description of your website: (e.g A search engine) " description
- read -p "Give the URL to where the rss feed will live: (e.g http://google.com/rssfeed.xml) " rsslink
- read -p "What will be the feed file live on the disk?: (e.g /home/dog/www/rssfeed.xml has to match above) " feedname
- read -p "Where is the file path for the posts? (leave blank if you are not using auto mode): " postDir
- echo -e "title=$title\nlink=$link\ndescription='$description'\nrsslink=$rsslink\nfeedname=$feedname\npostDir=$postDir" > ~/.rss-roller.rc
- echo "please run rss-roller again with the --auto or --manual flags"
- exit
-}
-
-if [[ ! -f ~/.rss-roller.rc ]]; then
- makeRSS
-fi
-
-source ~/.rss-roller.rc
-
-if [[ ! -f $feedname ]]; then
- touch $feedname
-fi
-
-
-if [[ $1 == "--auto" ]]; then
- mode=a
- #Do the bad thing
- if [[ -f $feedname ]]; then
- rm $feedname
- fi
- touch $feedname
- postArray=( $(ls -r "$postDir"/*.html) )
- numPosts=$(ls "$postDir"/*.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"
- fullTitle=$(grep -o '>.*</h1>' $post | sed 's/\(>\|<\/h1>\)//g')
- postname=${post##*/}
- linkadd="$link"/"$postname"
- extract=$(sed -n '/<p>.*/,/*.<\/p>/{p;q;}' $post | sed -e 's/<[^>]\+>/ /g' -e 's|<p>||g' -e 's|</p>||g' -e 's|"||g')
- item $post
- done
- combine
- exit
-fi
+ """ >> $TEMPFILE
+done
+echo $footer >> $TEMPFILE
-if [[ $1 == "--manual" ]]; then
- mode=m
- echo """
- NEW POST
- =======
- """
- read -p "What is the title of the new update?: " fullTitle
- read -p "What is the link of the new update?: " linkadd
- read -p "Provide a description of the new update: " extract
- read -p "Provide a unique identifier for the update: " guidadd
- if [[ -f $feedname ]]; then
- sed -e '1,10d' $feedname > ~/rssrollertopless
- head -n -4 ~/rssrollertopless > ~/rssrollertopandbottomless
- mv ~/rssrollertopandbottomless $feedname-old
- rm ~/rssrollertopless
- rm $feedname
- else
- touch $feedname
- fi
- item
- if [[ -f $feedname-old ]]; then
- mv ~/feed ~/feedtop
- cat ~/feedtop $feedname-old > ~/feed
- rm $feedname-old ~/feedtop
- fi
- combine
- exit
-fi
+mv -v $TEMPFILE $feedname
-if [[ $# == 0 ]]; then
- echo "please use the --auto or --manual flag"
-fi