Extract xmlstarlet calls
This commit is contained in:
parent
fa66f118be
commit
5016ced432
2 changed files with 24 additions and 17 deletions
4
feed.rss
4
feed.rss
|
|
@ -6,11 +6,11 @@
|
|||
<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>
|
||||
<lastBuildDate>Sun, 19 May 2024 21:11:05 -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>
|
||||
<pubDate>Fri, 23 Feb 2024 21:23:00 -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>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
#!/usr/bin/env zsh
|
||||
# dependencies: zsh, xmlstarlet, xmllint, jq
|
||||
# dependencies: zsh, xmlstarlet, xmllint
|
||||
|
||||
alias xml="xmlstarlet"
|
||||
date="$(date +'%a, %d %b %Y %H:%M:%S %z')"
|
||||
|
||||
function subnode {
|
||||
local -r tag="${1}"
|
||||
local -r value="${2}"
|
||||
local path="${3:-rss/channel/new}"
|
||||
local -r file="${4:-feed2.rss}"
|
||||
|
||||
if [[ -n $value ]]; then
|
||||
/usr/bin/xmlstarlet ed -L --subnode "$path" -t elem -n "$tag" -v "$value" "$file"
|
||||
else
|
||||
/usr/bin/xmlstarlet ed -L --subnode "$path" -t elem -n "$tag" "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
function insert {
|
||||
local -r title="$1"
|
||||
local -r slug="${2}.html"
|
||||
|
|
@ -14,14 +26,14 @@ function insert {
|
|||
return 0
|
||||
fi
|
||||
|
||||
xml ed --update rss/channel/lastBuildDate --value "$date" feed.rss > feed2.rss
|
||||
xmlstarlet 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
|
||||
subnode new '' rss/channel
|
||||
subnode title "$title"
|
||||
subnode pubDate "$date"
|
||||
subnode link "$url_root/$slug"
|
||||
subnode guid "$url_root/$slug"
|
||||
subnode author "$author"
|
||||
|
||||
sed -i 's/<new>/<item>/g' feed2.rss
|
||||
sed -i 's/<\/new>/<\/item>/g' feed2.rss
|
||||
|
|
@ -30,6 +42,7 @@ function insert {
|
|||
mv -v feed2.rss feed.rss
|
||||
else
|
||||
echo 'Generated an invalid feed, not overwriting'
|
||||
rm -vf feed2.rss
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
|
@ -40,15 +53,9 @@ 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