forked from kageru/mdb
117 lines
3.4 KiB
Bash
Executable File
117 lines
3.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
blog_domain='https://lucy.moe/'
|
|
|
|
output() {
|
|
echo "$1" >> dist/posts-table.html
|
|
}
|
|
|
|
output_rss() {
|
|
echo "$1" >> dist/rss.xml
|
|
}
|
|
|
|
add_header() {
|
|
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" ?>
|
|
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
|
|
<author><name>Lucy</name></author>
|
|
<title type="text">Lucys blog</title>'
|
|
output_rss " <updated>$(date --iso-8601=seconds)</updated>
|
|
<id>https://lucy.moe/rss.xml</id>
|
|
<link href=\"https://lucy.moe/rss.xml\" rel=\"self\" type=\"application/atom+xml\"/>"
|
|
}
|
|
|
|
add_footer() {
|
|
html_entry "https://asagi.moe" "before July 2020" "Old site"
|
|
output '</tbody>
|
|
</table>'
|
|
output_rss '</feed>'
|
|
}
|
|
|
|
html_entry() {
|
|
output '<tr>'
|
|
webpath="$1"
|
|
time="$2"
|
|
title="$3"
|
|
output "<td><a href=\"$webpath\">$title</a></td>"
|
|
output "<td style=\"text-align: right\">$time</td></tr>"
|
|
}
|
|
|
|
rss_entry() {
|
|
# this is made to represent what heise.de has done with
|
|
# their rss/atom feeds and doesn't need any escaping
|
|
output_rss " <entry>
|
|
<title type=\"text\">$1</title>
|
|
<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\"/>
|
|
<summary type=\"html\">
|
|
$(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>
|
|
</entry>"
|
|
}
|
|
|
|
create_entry() {
|
|
path="$9"
|
|
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
|
|
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
|
|
title=$(grep -h '<title>' "dist/$outpath" | sed 's/<title>//g;s/<\/title>//g')
|
|
html_entry "$outpath" "$created_date" "$title"
|
|
rss_entry "$title" "$outpath" $path $created
|
|
}
|
|
|
|
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() {
|
|
git fetch &> /dev/null
|
|
diff="$(git diff master origin/master)"
|
|
if [ "$diff" ]; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
footer="$(cat src/footer/footer.html)"
|
|
cd /home/lucy/blog-content/
|
|
rm -R dist/*
|
|
rsync -q --delete -avxt static/ dist/
|
|
add_header
|
|
ls -lr src/posts/*.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
|
|
pandoc -s --css=/css/sakura-vader.css \
|
|
-V include-after="$footer" \
|
|
src/index/index_header.md dist/posts-table.html src/index/after-entry-list.md \
|
|
-t html5 -f markdown -o dist/index.html
|