diff --git a/feed.rss b/feed.rss index 45eb7b0..6e903b6 100644 --- a/feed.rss +++ b/feed.rss @@ -1,18 +1,19 @@ - - - - jutty.dev: Blog - http://blog.jutty.dev/ - jutty.dev: Blog - pt-br - Sat, 11 May 2024 23:19:00 -0300 - https://www.rssboard.org/rss-specification - - Scripts em OCaml - Sat, 24 Feb 2024 03:22 -0300 - https://blog.jutty.dev/posts/html/scripts-em-ocaml.md.html - https://blog.jutty.dev/posts/html/scripts-em-ocaml.md.html - juno@jutty.dev (Juno Takano) - - + + + + jutty.dev: Blog + http://blog.jutty.dev/ + + jutty.dev: Blog + pt-br + Sun, 19 May 2024 19:13:50 -0300 + https://www.rssboard.org/rss-specification + + Scripts em OCaml + Sun, 19 May 2024 19:13:50 -0300 + https://blog.jutty.dev/posts/scripts-em-ocaml.html + https://blog.jutty.dev/posts/scripts-em-ocaml.html + juno@jutty.dev (Juno Takano) + + diff --git a/posts/html/.gitattributes b/posts/.gitattributes similarity index 100% rename from posts/html/.gitattributes rename to posts/.gitattributes diff --git a/posts/gen.ml b/posts/gen.ml index 79fc618..2c3f2bb 100755 --- a/posts/gen.ml +++ b/posts/gen.ml @@ -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 diff --git a/posts/markdown/scripts-em-ocaml.md b/posts/md/scripts-em-ocaml.md similarity index 100% rename from posts/markdown/scripts-em-ocaml.md rename to posts/md/scripts-em-ocaml.md diff --git a/posts/html/scripts-em-ocaml.md.html b/posts/scripts-em-ocaml.html similarity index 100% rename from posts/html/scripts-em-ocaml.md.html rename to posts/scripts-em-ocaml.html diff --git a/update-feed.zsh b/update-feed.zsh new file mode 100755 index 0000000..0cfd88b --- /dev/null +++ b/update-feed.zsh @@ -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///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