Add script for RSS feed updates

This commit is contained in:
jultty 2024-05-19 19:14:39 -03:00
commit 0076b63ee8
6 changed files with 76 additions and 19 deletions

View file

@ -1,18 +1,19 @@
<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>jutty.dev: Blog</title>
<link>http://blog.jutty.dev/</link>
<description>jutty.dev: Blog</description>
<language>pt-br</language>
<lastBuildDate>Sat, 11 May 2024 23:19:00 -0300</lastBuildDate>
<docs>https://www.rssboard.org/rss-specification</docs>
<item>
<title>Scripts em OCaml</title>
<pubDate>Sat, 24 Feb 2024 03:22 -0300</pubDate>
<link>https://blog.jutty.dev/posts/html/scripts-em-ocaml.md.html</link>
<guid>https://blog.jutty.dev/posts/html/scripts-em-ocaml.md.html</guid>
<author>juno@jutty.dev (Juno Takano)</author>
</item>
</channel>
<?xml version="1.0" encoding="utf8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>jutty.dev: Blog</title>
<link>http://blog.jutty.dev/</link>
<atom:link href="https://blog.jutty.dev/feed.rss" rel="self" type="application/rss+xml"/>
<description>jutty.dev: Blog</description>
<language>pt-br</language>
<lastBuildDate>Sun, 19 May 2024 19:13:50 -0300</lastBuildDate>
<docs>https://www.rssboard.org/rss-specification</docs>
<item>
<title>Scripts em OCaml</title>
<pubDate>Sun, 19 May 2024 19:13:50 -0300</pubDate>
<link>https://blog.jutty.dev/posts/scripts-em-ocaml.html</link>
<guid>https://blog.jutty.dev/posts/scripts-em-ocaml.html</guid>
<author>juno@jutty.dev (Juno Takano)</author>
</item>
</channel>
</rss>

View file

@ -3,12 +3,14 @@
let args = "--css ../../assets/style.css -s --to html5 " ^
"--highlight-style zenburn " ^ "--lua-filter filters/title.lua "
let vert md = begin
let filename_split = String.split_on_char '.' md in
Sys.command (
"pandoc " ^ args ^ " markdown/" ^ md ^ " -o html/" ^ md ^ ".html "
"pandoc " ^ args ^ " md/" ^ md ^ " -o " ^ List.nth filename_split 0
)
end ;;
let contents = Sys.readdir "./markdown/"
let contents = Sys.readdir "./md/"
|> Array.to_list
|> List.map vert

54
update-feed.zsh Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env zsh
# dependencies: zsh, xmlstarlet, xmllint, jq
alias xml="xmlstarlet"
date="$(date +'%a, %d %b %Y %H:%M:%S %z')"
function insert {
local -r title="$1"
local -r slug="${2}.html"
local -r url_root='https://blog.jutty.dev/posts'
local -r author='juno@jutty.dev (Juno Takano)'
if grep -q "$url_root/$slug" feed.rss; then
return 0
fi
xml ed --update rss/channel/lastBuildDate --value "$date" feed.rss > feed2.rss
xml ed -L --subnode rss/channel -t elem -n new feed2.rss
xml ed -L --subnode rss/channel/new -t elem -n title -v "$title" feed2.rss
xml ed -L --subnode rss/channel/new -t elem -n pubDate -v "$date" feed2.rss
xml ed -L --subnode rss/channel/new -t elem -n link -v "$url_root/$slug" feed2.rss
xml ed -L --subnode rss/channel/new -t elem -n guid -v "$url_root/$slug" feed2.rss
xml ed -L --subnode rss/channel/new -t elem -n author -v "$author" feed2.rss
sed -i 's/<new>/<item>/g' feed2.rss
sed -i 's/<\/new>/<\/item>/g' feed2.rss
if xmllint --noout feed2.rss; then
mv -v feed2.rss feed.rss
else
echo 'Generated an invalid feed, not overwriting'
return 1
fi
}
index="$(cat assets/js/data.js | grep 'title\|slug' | sed 's/,/\n/g' | grep '.')"
total=$(echo $index | wc -l)
current=2
while [[ $current -le $total ]]; do
echo processing $current
lines=$(echo $index | tail -$((current)) | head -2)
title=$(echo $lines | grep title: | cut -d: -f 2 | xargs)
slug=$(echo $lines | grep slug: | cut -d: -f 2 | xargs)
echo title: $title
echo slug: $slug
insert "$title" "$slug"
((current+=2))
done
echo -e "\nfeed.rss:"
cat feed.rss | xq -x