forked from kageru/mdb
101 lines
3.0 KiB
Bash
Executable File
101 lines
3.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
blog_domain='https://lucy.moe/'
|
|
|
|
output() {
|
|
echo "$1" >> dist/index-alt.html
|
|
}
|
|
|
|
output_entrylist() {
|
|
echo "$1" >> dist/entry_list.md
|
|
}
|
|
|
|
output_rss() {
|
|
echo "$1" >> dist/rss.xml
|
|
}
|
|
|
|
add_header() {
|
|
output '<h1>posts</h1><table id="linklist">'
|
|
output_entrylist "title| date
|
|
----|----:"
|
|
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>Lucys blog</title>'
|
|
output_rss " <link href=\"https://lucy.moe/rss.xml\" rel=\"self\" type=\"application/atom+xml\"/>
|
|
<description>Lucys blog</description>"
|
|
}
|
|
|
|
add_footer() {
|
|
html_entry "https://asagi.moe" "before July 2020" "Old site" "de/en"
|
|
output '</table>'
|
|
output_rss '</feed>'
|
|
}
|
|
|
|
html_entry() {
|
|
output '<tr>'
|
|
webpath="$1"
|
|
time="$2"
|
|
title="$3"
|
|
output "<td class=\"first\"><a href=\"$path\">$title</a></td>"
|
|
output "<td class=\"second\">$time</td></tr>"
|
|
output_entrylist "[$title]($webpath)|$time"
|
|
}
|
|
|
|
rss_entry() {
|
|
# The content is the output minus the first line
|
|
# (which would otherwise be a redundant title in most rss readers)
|
|
# and with escaped html.
|
|
# The sed expression is stolen from https://stackoverflow.com/questions/12873682/12873723#12873723
|
|
output_rss " <entry>
|
|
<title type=\"text\">$1</title>
|
|
<published>$(date --rfc-3339=seconds -d $4 | sed 's/ /T/')</published>
|
|
<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/^/ /')
|
|
</summary>
|
|
<content type=\"html\" xml:base=\"$blog_domain$2\">
|
|
$(pandoc $3 | sed 's/^/ /')
|
|
</content>
|
|
</entry>"
|
|
# $(tail -n+2 "$2" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g')
|
|
}
|
|
|
|
create_entry() {
|
|
path="$9"
|
|
outpath="$(basename "$path" .md).html"
|
|
# convert new markdown posts to html
|
|
pandoc -s --css=/css/sakura-vader.css "$path" src/footer/footer.md -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')
|
|
created=$(grep -h '^date: ' "$path" | sed 's/date: //g')
|
|
html_entry "$outpath" "$created" "$title"
|
|
rss_entry "$title" "$outpath" $path $created
|
|
}
|
|
|
|
convert_static() {
|
|
path="$9"
|
|
outpath="$(basename "$path" .md).html"
|
|
pandoc -s --css=/css/sakura-vader.css "$path" src/footer/footer.md -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
|
|
}
|
|
|
|
#cd /home/lucy/blog-content/
|
|
rm -R dist/*
|
|
rsync --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 src/index/index_header.md dist/entry_list.md src/index/after-entry-list.md src/footer/footer.md -o dist/index.html
|