add RSS feed for blog
This commit is contained in:
parent
8673ca1601
commit
2fa212a36f
|
@ -1,17 +1,30 @@
|
|||
#!/bin/sh
|
||||
|
||||
blog_domain='https://blog.kageru.moe/'
|
||||
|
||||
output() {
|
||||
echo "$1" >> index.html
|
||||
}
|
||||
|
||||
output_rss() {
|
||||
echo "$1" >> rss.xml
|
||||
}
|
||||
|
||||
add_header() {
|
||||
output '<h1>Blog index</h1>'
|
||||
output '<table id="linklist">'
|
||||
output '<h1>Blog index</h1><table id="linklist">'
|
||||
output_rss '<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>kageru’s blog</title>'
|
||||
output_rss " <link>$blog_domain</link>
|
||||
<description>kageru’s blog</description>"
|
||||
}
|
||||
|
||||
add_footer() {
|
||||
html_entry "legacy" "before 2020" "Older posts"
|
||||
output '</table>'
|
||||
output_rss '</channel>
|
||||
</rss>'
|
||||
}
|
||||
|
||||
html_entry() {
|
||||
|
@ -23,6 +36,14 @@ html_entry() {
|
|||
output "<td class=\"second\">$time</td></tr>"
|
||||
}
|
||||
|
||||
rss_entry() {
|
||||
output_rss " <item>
|
||||
<title>$1</title>
|
||||
<link>$blog_domain$2</link>
|
||||
<description>$1</description>
|
||||
</item>"
|
||||
}
|
||||
|
||||
create_entry() {
|
||||
path="$9"
|
||||
outpath="content/$(basename "$path" .md).html"
|
||||
|
@ -32,6 +53,7 @@ create_entry() {
|
|||
title="$(rg 'h1' "$outpath" | head -n1 | rg -o '(?<=>).*(?=<)' --pcre2)"
|
||||
created=$(git log --follow --format=%as "$path" | tail -1)
|
||||
html_entry "$outpath" "created on $created" "$title"
|
||||
rss_entry "$title" "$outpath"
|
||||
}
|
||||
|
||||
has_updates() {
|
||||
|
@ -48,6 +70,7 @@ cd /home/nginx/html/blog
|
|||
if has_updates; then
|
||||
git pull &> /dev/null
|
||||
rm -f index.html
|
||||
rm -f rss.xml
|
||||
add_header
|
||||
ls -ltu src/*.md | tail -n+1 | while read f; do create_entry $f; done
|
||||
add_footer
|
||||
|
|
Loading…
Reference in New Issue
Block a user