2021-05-07 16:02:58 +00:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
|
|
|
cd "$(git rev-parse --show-toplevel)" || exit 1
|
|
|
|
# Directory
|
|
|
|
webdir="_site"
|
|
|
|
postsdir="$webdir/posts"
|
|
|
|
indexdir=".cache/rss"
|
|
|
|
|
|
|
|
# file to handle
|
|
|
|
fic="$1"
|
2021-05-08 08:07:10 +00:00
|
|
|
dst="$2"
|
2021-05-07 16:02:58 +00:00
|
|
|
|
|
|
|
# RSS Metas
|
|
|
|
websiteurl="https://her.esy.fun"
|
|
|
|
|
|
|
|
# HTML Accessors (similar to CSS accessors)
|
|
|
|
dateaccessor='.yyydate'
|
|
|
|
contentaccessor='#content'
|
|
|
|
# title and keyword shouldn't be changed
|
|
|
|
titleaccessor='title'
|
|
|
|
keywordsaccessor='meta[name=keywords]::attr(content)'
|
|
|
|
|
|
|
|
formatdate() {
|
|
|
|
# format the date for RSS
|
|
|
|
local d="$1"
|
|
|
|
# echo "DEBUG DATE: $d" >&2
|
|
|
|
LC_TIME=en_US date --date $d +'%a, %d %b %Y %H:%M:%S %z'
|
|
|
|
}
|
|
|
|
|
|
|
|
finddate(){ < $1 hxselect -c $dateaccessor | sed 's/\[//g;s/\]//g;s/ .*$//' }
|
|
|
|
findtitle(){ < $1 hxselect -c $titleaccessor }
|
|
|
|
getcontent(){
|
|
|
|
< $1 hxselect $contentaccessor | \
|
|
|
|
perl -pe 'use URI; $base="'$2'"; s# (href|src)="((?!https?://)[^"]*)"#" ".$1."=\"".URI->new_abs($2,$base)->as_string."\""#eig' }
|
|
|
|
findkeywords(){ < $1 hxselect -c $keywordsaccessor | sed 's/,/ /g' }
|
|
|
|
|
|
|
|
mkcategories(){
|
|
|
|
for keyword in $*; do
|
|
|
|
printf "\\n<category>%s</category>" $keyword
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
autoload -U colors && colors
|
|
|
|
|
2021-05-08 11:33:14 +00:00
|
|
|
xfic="$fic"
|
2021-05-07 16:02:58 +00:00
|
|
|
postfile="$(echo "$fic"|sed 's#^'$postsdir'/##')"
|
2021-05-08 11:33:14 +00:00
|
|
|
blogfile="$(echo "$fic"|sed 's#.xml$#.html#;s#^'$indexdir'/#posts/#')"
|
2021-05-07 16:02:58 +00:00
|
|
|
printf "%-30s" $postfile
|
|
|
|
d=$(finddate $xfic)
|
|
|
|
echo -n " [$d]"
|
|
|
|
rssdate=$(formatdate $d)
|
|
|
|
title=$(findtitle $xfic)
|
|
|
|
keywords=( $(findkeywords $xfic) )
|
|
|
|
printf ": %-55s" "$title ($keywords)"
|
|
|
|
categories=$(mkcategories $keywords)
|
|
|
|
absoluteurl="${websiteurl}/${blogfile}"
|
|
|
|
mkdir -p $(dirname $dst)
|
|
|
|
{ printf "\\n<item>"
|
|
|
|
printf "\\n<title>%s</title>" "$title"
|
|
|
|
printf "\\n<guid>%s</guid>" "$absoluteurl"
|
|
|
|
printf "\\n<pubDate>%s</pubDate>%s" "$rssdate"
|
|
|
|
printf "%s" "$categories"
|
|
|
|
printf "\\n<description><![CDATA[\\n%s\\n]]></description>" "$(getcontent "$xfic" "$absoluteurl")"
|
|
|
|
printf "\\n</item>\\n\\n"
|
2021-05-08 08:07:10 +00:00
|
|
|
} > "$dst"
|
2021-05-07 16:02:58 +00:00
|
|
|
echo " [${fg[green]}OK${reset_color}]"
|