#!/bin/bash

#output the date for logging purposes
date --iso=second 

# pgadey's feeds
# import all feeds from opml to sfeed
cat "/home/pgadey/public_html/pgadey/feeds/feeds.opml" | sfeed_opml_import > "/home/pgadey/.sfeed/sfeedrc"
sfeed_update 

# generate the full feeds list
sfeed_html /home/pgadey/.sfeed/feeds/* > "/home/pgadey/.sfeed/feeds.html"

# create a mini-fied version as static html
echo "Minifying!"
cat >/home/pgadey/.sfeed/feeds-mini.html <<EOF
<!DOCTYPE html>

<html>
<head>
<title>~pgadey's mini-sfeed</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<pre>
EOF

echo -e "Generated at: $(date --iso=second)">> /home/pgadey/.sfeed/feeds-mini.html

# find the feeds which have been recently updated (shown in bold <b>)
# you can hackily include / exclude stuff by modifying the grep here.
# for example ~gome suggested limiting the number of lines, 
# an added "head -n10 " would do the trick for ten lines

cat /home/pgadey/.sfeed/feeds.html | grep '<b>' | grep 'https' >> /home/pgadey/.sfeed/feeds-mini.html

cat >>/home/pgadey/.sfeed/feeds-mini.html <<EOF
<a href="sfeed.html">Full feed list</a>
</pre>
</body>
</html>
EOF

echo -e "Done minifying: $(wc -c /home/pgadey/.sfeed/feeds-mini.html)."

# copy over the pages to ctrl-c.club and pgadey.ca
cp -v "/home/pgadey/.sfeed/feeds.html" "/home/pgadey/public_html/pgadey/feeds/sfeed.html"
cp -v "/home/pgadey/.sfeed/feeds-mini.html" "/home/pgadey/public_html/pgadey/feeds/sfeed-mini.html"
scp -v /home/pgadey/.sfeed/feeds.html ctrl-c.club:/home/pgadey/public_html/sfeed.html
scp -v /home/pgadey/.sfeed/feeds-mini.html ctrl-c.club:/home/pgadey/public_html/sfeed-mini.html
