Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
1c9652e1a9 | |||
440e4fa753 | |||
3e7021845c | |||
ab3b9a2f19 | |||
afe2299557 | |||
a172ac644f | |||
ce337cf373 | |||
af773b4de2 | |||
f504cd34ff | |||
2b5195fb94 | |||
5e711b5f6b | |||
262e8d5aaf | |||
e0ed767c63 | |||
cddfffbbe8 | |||
810c51faa3 | |||
30eff46640 | |||
19007947b8 | |||
ddf569e46f | |||
3d3f5ee506 | |||
b1ab90fdb0 | |||
a2438208b0 | |||
7d780a551e | |||
ef7d80a19c | |||
dd968c0f42 | |||
4aae6cd240 |
108
blog-refresh.sh
108
blog-refresh.sh
|
@ -1,65 +1,95 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
blog_domain='https://blog.kageru.moe/'
|
blog_domain='https://lucy.moe/'
|
||||||
|
|
||||||
output() {
|
output() {
|
||||||
echo "$1" >> index.html
|
echo "$1" >> dist/posts-table.html
|
||||||
}
|
}
|
||||||
|
|
||||||
output_rss() {
|
output_rss() {
|
||||||
echo "$1" >> rss.xml
|
echo "$1" >> dist/rss.xml
|
||||||
}
|
}
|
||||||
|
|
||||||
add_header() {
|
add_header() {
|
||||||
output '<h1>Blog index</h1><table id="linklist">'
|
output '<table>
|
||||||
|
<colgroup>
|
||||||
|
<col style="width: 70%" />
|
||||||
|
<col style="width: 30%" />
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<tr class="header">
|
||||||
|
<th style="text-align: left">title</th>
|
||||||
|
<th style="text-align: right">date</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>'
|
||||||
output_rss '<?xml version="1.0" encoding="UTF-8" ?>
|
output_rss '<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
|
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
|
||||||
<author><name>kageru</name></author>
|
<author><name>Lucy</name></author>
|
||||||
<title>kageru’s blog</title>'
|
<title type="text">Lucys blog</title>'
|
||||||
output_rss " <link href=\"$blog_domain\" rel=\"self\" type=\"application/atom+xml\"/>
|
output_rss " <updated>$(date --iso-8601=seconds)</updated>
|
||||||
<description>kageru’s blog</description>"
|
<id>https://lucy.moe/rss.xml</id>
|
||||||
|
<link href=\"https://lucy.moe/rss.xml\" rel=\"self\" type=\"application/atom+xml\"/>"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_footer() {
|
add_footer() {
|
||||||
html_entry "legacy" "before 2020" "Older posts"
|
html_entry "https://asagi.moe" "before July 2020" "Old site"
|
||||||
output '</table>'
|
output '</tbody>
|
||||||
|
</table>'
|
||||||
output_rss '</feed>'
|
output_rss '</feed>'
|
||||||
}
|
}
|
||||||
|
|
||||||
html_entry() {
|
html_entry() {
|
||||||
output '<tr>'
|
output '<tr>'
|
||||||
path="$1"
|
webpath="$1"
|
||||||
time="$2"
|
time="$2"
|
||||||
title="$3"
|
title="$3"
|
||||||
output "<td class=\"first\"><a href=\"$path\">$title</a></td>"
|
output "<td><a href=\"$webpath\">$title</a></td>"
|
||||||
output "<td class=\"second\">$time</td></tr>"
|
output "<td style=\"text-align: right\">$time</td></tr>"
|
||||||
}
|
}
|
||||||
|
|
||||||
rss_entry() {
|
rss_entry() {
|
||||||
# The content is the output minus the first line
|
# this is made to represent what heise.de has done with
|
||||||
# (which would otherwise be a redundant title in most rss readers)
|
# their rss/atom feeds and doesn't need any escaping
|
||||||
# and with escaped html.
|
|
||||||
# The sed expression is stolen from https://stackoverflow.com/questions/12873682/12873723#12873723
|
|
||||||
output_rss " <entry>
|
output_rss " <entry>
|
||||||
<title>$1</title>
|
<title type=\"text\">$1</title>
|
||||||
<link>$blog_domain$2</link>
|
<published>$(date --iso-8601=seconds -d $4)</published>
|
||||||
|
<updated>$(date --iso-8601=seconds -r $3)</updated>
|
||||||
|
<id>$blog_domain$2</id>
|
||||||
<link href=\"$blog_domain$2\" type=\"text/html\" title=\"$1\"/>
|
<link href=\"$blog_domain$2\" type=\"text/html\" title=\"$1\"/>
|
||||||
<content type=\"html\" xml:base=\"$blog_domain$2\">
|
<summary type=\"html\">
|
||||||
$(tail -n+2 "$2" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g')
|
$(grep -h '^<p>' "dist/$2" | head -n 1 | sed 's/<p>//;s/<\/p>//;/<!--/d;s/^/ /')
|
||||||
|
</summary>
|
||||||
|
<content type=\"html\" xml:base=\"$blog_domain$2\"><![CDATA[
|
||||||
|
$(pandoc $3 | sed '/<!--/d;s/^/ /')]]>
|
||||||
</content>
|
</content>
|
||||||
</entry>"
|
</entry>"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_entry() {
|
create_entry() {
|
||||||
path="$9"
|
path="$9"
|
||||||
outpath="content/$(basename "$path" .md).html"
|
outpath="$(basename "$path" .md).html"
|
||||||
|
created=$(grep -h '^date: ' "$path" | sed 's/date: //g')
|
||||||
|
created_date=$(date +'%b %d, %Y' --date="$created")
|
||||||
|
published_date=$(date --iso-8601=seconds --date="$created")
|
||||||
# convert new markdown posts to html
|
# convert new markdown posts to html
|
||||||
pandoc "$path" -t html -f markdown -o "$outpath"
|
pandoc -s --css=/css/sakura-vader.css --template=./pandoc-template-v2.2.1.html5 \
|
||||||
|
-V og-url="https://$outpath" -V published-date="$published_date" \
|
||||||
|
-V include-footer="$footer" \
|
||||||
|
src/meta/default.yaml "$path" -t html5 -f markdown -o "dist/$outpath"
|
||||||
# then add it to the index
|
# then add it to the index
|
||||||
title="$(rg 'h1' "$outpath" | head -n1 | rg -o '(?<=>).*(?=<)' --pcre2)"
|
title=$(grep -h '<title>' "dist/$outpath" | sed 's/<title>//g;s/<\/title>//g')
|
||||||
created=$(git log --follow --format=%as "$path" | tail -1)
|
html_entry "$outpath" "$created_date" "$title"
|
||||||
html_entry "$outpath" "created on $created" "$title"
|
rss_entry "$title" "$outpath" $path $created
|
||||||
rss_entry "$title" "$outpath"
|
}
|
||||||
|
|
||||||
|
convert_static() {
|
||||||
|
path="$9"
|
||||||
|
outpath="$(basename "$path" .md).html"
|
||||||
|
pandoc -s --css=/css/sakura-vader.css --template=./pandoc-template-v2.2.1.html5 "$path" \
|
||||||
|
-V include-footer="$footer" \
|
||||||
|
-t html5 -f markdown -o "dist/$outpath"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
has_updates() {
|
has_updates() {
|
||||||
|
@ -72,15 +102,15 @@ has_updates() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
cd /home/nginx/html/blog
|
footer="$(cat src/footer/footer.html)"
|
||||||
if has_updates; then
|
cd /home/lucy/blog-content/
|
||||||
git pull &> /dev/null
|
rm -R dist/*
|
||||||
rm -f index.html
|
rsync -q --delete -avxt static/ dist/
|
||||||
rm -f rss.xml
|
add_header
|
||||||
add_header
|
ls -lr src/posts/*.md | tail -n+1 | while read f; do create_entry $f; done
|
||||||
ls -ltu src/*.md | tail -n+1 | while read f; do create_entry $f; done
|
ls -l src/*.md | tail -n+1 | while read f; do convert_static $f; done
|
||||||
add_footer
|
add_footer
|
||||||
# Human-readable output for the cron notification
|
pandoc -s --css=/css/sakura-vader.css \
|
||||||
echo 'Updated blog to:'
|
-V include-after="$footer" \
|
||||||
git log -1
|
src/index/index_header.md dist/posts-table.html src/index/after-entry-list.md \
|
||||||
fi
|
-t html5 -f markdown -o dist/index.html
|
||||||
|
|
Loading…
Reference in New Issue
Block a user