her.esy.fun/mkrss.sh

70 lines
1.7 KiB
Bash
Raw Normal View History

2019-09-25 10:11:24 +00:00
#!/usr/bin/env nix-shell
#!nix-shell -i zsh
2019-09-24 15:55:59 +00:00
rsstpl="rss.tpl"
webdir="_site"
2019-09-30 07:54:53 +00:00
postsdir="$webdir/posts"
2019-09-24 15:55:59 +00:00
rssfile="$webdir/rss.xml"
xmlize() {
local fic="$1";
hxclean $fic
}
2019-09-24 15:55:59 +00:00
formatdate() {
local d=$1
LC_TIME=en_US date --date $d +'%a, %d %b %Y %H:%M:%S %z'
}
finddate(){
local fic="$1"
cat $fic | hxselect -c '.article-date'
2019-09-24 15:55:59 +00:00
}
2019-09-25 10:11:24 +00:00
findtitle(){
local fic="$1"
cat $fic | hxselect -c 'h1'
2019-09-25 10:11:24 +00:00
}
2019-09-24 15:55:59 +00:00
getcontent(){
local fic="$1"
cat $fic | hxselect '#content'
2019-09-24 15:55:59 +00:00
}
2019-09-30 07:54:53 +00:00
findkeywords(){
local fic="$1"
cat $fic | hxselect -c '.keywords > code' | sed 's/,//g'
}
mkcategories(){
for keyword in $*; do
printf "\\n<category>%s</category>" $keyword
done
}
2019-09-24 15:55:59 +00:00
realname="Yann Esposito"
website="https://her.esy.fun"
2019-09-25 10:11:24 +00:00
autoload -U colors && colors
2019-09-24 15:55:59 +00:00
tmpdir=$(mktemp -d)
2019-09-30 07:54:53 +00:00
for fic in $postsdir/**/*.html; do
printf "%-30s" $(echo "$fic"|sed 's#^'$postsdir'/##')
xfic="$tmpdir/$fic.xml"
mkdir -p $(dirname $xfic)
xmlize $fic > $xfic
d=$(finddate $xfic)
2019-09-25 10:11:24 +00:00
echo -n " [$d]"
rssdate=$(formatdate $d)
title=$(findtitle $xfic)
2019-09-30 07:54:53 +00:00
keywords=( $(findkeywords $xfic) )
printf ": %-55s" "$title ($keywords)"
categories=$(mkcategories $keywords)
2019-09-24 15:55:59 +00:00
blogfile="$(echo $fic | perl -pe 's#.*?/posts/#/posts/#')"
2019-09-30 07:54:53 +00:00
printf "\\n<item>\\n<title>%s</title>\\n<guid>%s%s</guid>\\n<pubDate>%s</pubDate>%s\\n<description><![CDATA[\\n%s\\n]]></description>\\n</item>\\n\\n" "$title" "$website" "$blogfile" "$rssdate" "$categories" "$(getcontent "$xfic")" >> "$tmpdir/${d}-$(basename $fic).rss"
2019-09-25 10:11:24 +00:00
echo " [${fg[green]}OK${reset_color}]"
done
for fic in $(ls $tmpdir/*.rss | sort -r); do
# echo $fic
cat $fic >> $tmpdir/rss
2019-09-24 15:55:59 +00:00
done
sed "/<!-- LB -->/r $tmpdir/rss" "$rsstpl" > "$rssfile"
2019-09-25 10:11:24 +00:00
rm -rf $tmpdir
echo "RSS Generated"