Add script for RSS feed updates
This commit is contained in:
parent
ab9496a92b
commit
0076b63ee8
6 changed files with 76 additions and 19 deletions
35
feed.rss
35
feed.rss
|
|
@ -1,18 +1,19 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="utf8"?>
|
||||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||||
<channel>
|
<channel>
|
||||||
<title>jutty.dev: Blog</title>
|
<title>jutty.dev: Blog</title>
|
||||||
<link>http://blog.jutty.dev/</link>
|
<link>http://blog.jutty.dev/</link>
|
||||||
<description>jutty.dev: Blog</description>
|
<atom:link href="https://blog.jutty.dev/feed.rss" rel="self" type="application/rss+xml"/>
|
||||||
<language>pt-br</language>
|
<description>jutty.dev: Blog</description>
|
||||||
<lastBuildDate>Sat, 11 May 2024 23:19:00 -0300</lastBuildDate>
|
<language>pt-br</language>
|
||||||
<docs>https://www.rssboard.org/rss-specification</docs>
|
<lastBuildDate>Sun, 19 May 2024 19:13:50 -0300</lastBuildDate>
|
||||||
<item>
|
<docs>https://www.rssboard.org/rss-specification</docs>
|
||||||
<title>Scripts em OCaml</title>
|
<item>
|
||||||
<pubDate>Sat, 24 Feb 2024 03:22 -0300</pubDate>
|
<title>Scripts em OCaml</title>
|
||||||
<link>https://blog.jutty.dev/posts/html/scripts-em-ocaml.md.html</link>
|
<pubDate>Sun, 19 May 2024 19:13:50 -0300</pubDate>
|
||||||
<guid>https://blog.jutty.dev/posts/html/scripts-em-ocaml.md.html</guid>
|
<link>https://blog.jutty.dev/posts/scripts-em-ocaml.html</link>
|
||||||
<author>juno@jutty.dev (Juno Takano)</author>
|
<guid>https://blog.jutty.dev/posts/scripts-em-ocaml.html</guid>
|
||||||
</item>
|
<author>juno@jutty.dev (Juno Takano)</author>
|
||||||
</channel>
|
</item>
|
||||||
|
</channel>
|
||||||
</rss>
|
</rss>
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,14 @@
|
||||||
let args = "--css ../../assets/style.css -s --to html5 " ^
|
let args = "--css ../../assets/style.css -s --to html5 " ^
|
||||||
"--highlight-style zenburn " ^ "--lua-filter filters/title.lua "
|
"--highlight-style zenburn " ^ "--lua-filter filters/title.lua "
|
||||||
|
|
||||||
|
|
||||||
let vert md = begin
|
let vert md = begin
|
||||||
|
let filename_split = String.split_on_char '.' md in
|
||||||
Sys.command (
|
Sys.command (
|
||||||
"pandoc " ^ args ^ " markdown/" ^ md ^ " -o html/" ^ md ^ ".html "
|
"pandoc " ^ args ^ " md/" ^ md ^ " -o " ^ List.nth filename_split 0
|
||||||
)
|
)
|
||||||
end ;;
|
end ;;
|
||||||
|
|
||||||
let contents = Sys.readdir "./markdown/"
|
let contents = Sys.readdir "./md/"
|
||||||
|> Array.to_list
|
|> Array.to_list
|
||||||
|> List.map vert
|
|> List.map vert
|
||||||
|
|
|
||||||
54
update-feed.zsh
Executable file
54
update-feed.zsh
Executable 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue