her.esy.fun/engine/mk-index-entry.sh

36 lines
1 KiB
Bash
Raw Permalink Normal View History

2021-05-25 14:27:58 +00:00
#!/usr/bin/env zsh
cd "$(git rev-parse --show-toplevel)" || exit 1
2021-08-21 15:19:30 +00:00
source ./engine/envvars.sh
2021-05-25 14:27:58 +00:00
xfic="$1"
dst="$2"
# Directory
indexdir=".cache/rss"
# HTML Accessors (similar to CSS accessors)
dateaccessor='.yyydate'
# title and keyword shouldn't be changed
titleaccessor='title'
2021-08-21 15:19:30 +00:00
keywordsaccessor='meta[name=keywords]::attr(content)'
2021-05-25 14:27:58 +00:00
finddate(){ < $1 hxselect -c $dateaccessor | sed 's/\[//g;s/\]//g;s/ .*$//' }
findtitle(){ < $1 hxselect -c $titleaccessor }
2021-08-21 15:19:30 +00:00
findkeywords(){ < $1 hxselect -c $keywordsaccessor | sed 's/,/ /g' }
2021-05-25 14:27:58 +00:00
autoload -U colors && colors
blogfile="$(echo "$xfic"|sed 's#.xml$#.html#;s#^'$indexdir'/#posts/#')"
printf "%-30s" $blogfile
d=$(finddate $xfic)
echo -n " [$d]"
title=$(findtitle $xfic)
keywords=( $(findkeywords $xfic) )
printf ": %-55s" "$title ($keywords)"
{ printf "\\n<li>"
printf "\\n<span class=\"pubDate\">%s</span>" "$d"
2022-02-19 09:36:55 +00:00
printf "\\n<span class=\"post-title\"><a href=\"%s\">%s</a></span>" "${blogfile}" "$title"
2021-05-25 14:27:58 +00:00
printf "\\n</li>\\n\\n"
2021-05-25 20:31:19 +00:00
} > ${dst}
2021-05-25 14:27:58 +00:00
echo " [${fg[green]}OK${reset_color}]"