2020-04-01 22:13:13 +02:00
#!/bin/sh
2020-07-11 00:28:31 +02:00
blog_domain = 'https://lucy.moe/'
2020-04-26 17:37:47 +02:00
2020-04-01 22:13:13 +02:00
output( ) {
2020-07-15 21:20:25 +02:00
echo " $1 " >> dist/index-alt.html
2020-07-12 20:09:10 +02:00
}
output_entrylist( ) {
2020-07-15 21:20:25 +02:00
echo " $1 " >> dist/entry_list.md
2020-04-01 22:13:13 +02:00
}
2020-04-26 17:37:47 +02:00
output_rss( ) {
2020-07-15 21:20:25 +02:00
echo " $1 " >> dist/rss.xml
2020-04-26 17:37:47 +02:00
}
2020-04-26 16:58:43 +02:00
add_header( ) {
2020-07-11 00:28:31 +02:00
output '<h1>posts</h1><table id="linklist">'
2020-07-12 20:09:10 +02:00
output_entrylist " title| date
----| ----:"
2020-04-26 17:37:47 +02:00
output_rss ' <?xml version = "1.0" encoding = "UTF-8" ?>
2020-05-04 20:15:48 +02:00
<feed xmlns = "http://www.w3.org/2005/Atom" xml:lang= "en" >
2020-07-11 00:45:58 +02:00
<author><name>Lucy</name></author>
<title>Lucys blog</title>'
2020-07-17 14:29:37 +02:00
output_rss " <link href=\"https://lucy.moe/rss.xml\" rel=\"self\" type=\"application/atom+xml\"/>
2020-07-11 00:28:31 +02:00
<description>Lucys blog</description>"
2020-04-26 16:58:43 +02:00
}
add_footer( ) {
2020-07-15 21:50:30 +02:00
html_entry "https://asagi.moe" "before July 2020" "Old site" "de/en"
2020-04-26 16:58:43 +02:00
output '</table>'
2020-05-04 20:15:48 +02:00
output_rss '</feed>'
2020-04-26 16:58:43 +02:00
}
2020-04-01 22:13:13 +02:00
html_entry( ) {
output '<tr>'
2020-07-17 14:29:37 +02:00
webpath = " $1 "
2020-04-01 22:13:13 +02:00
time = " $2 "
title = " $3 "
output " <td class=\"first\"><a href=\" $path \"> $title </a></td> "
output " <td class=\"second\"> $time </td></tr> "
2020-07-17 14:29:37 +02:00
output_entrylist " [ $title ]( $webpath )| $time "
2020-04-01 22:13:13 +02:00
}
2020-04-26 17:37:47 +02:00
rss_entry( ) {
2020-05-04 20:15:48 +02:00
# 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>
2020-07-17 14:29:37 +02:00
<title type = \" text\" >$1 </title>
<published>$( date --rfc-3339= seconds -d $4 | sed 's/ /T/' ) </published>
<id>$blog_domain $2 </id>
2020-05-04 20:15:48 +02:00
<link href = \" $blog_domain $2 \" type = \" text/html\" title = \" $1 \" />
2020-07-17 14:29:37 +02:00
<summary type = \" html\" >
$( grep -h '^<p>' " dist/ $2 " | head -n 1 | sed 's/^/ /' )
</summary>
2020-05-04 20:15:48 +02:00
<content type = \" html\" xml:base= \" $blog_domain $2 \" >
2020-07-17 14:29:37 +02:00
$( pandoc $3 | sed 's/^/ /' )
2020-05-04 20:15:48 +02:00
</content>
</entry>"
2020-07-17 14:29:37 +02:00
# $(tail -n+2 "$2" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g')
2020-04-26 17:37:47 +02:00
}
2020-04-01 22:13:13 +02:00
create_entry( ) {
path = " $9 "
2020-07-12 02:49:52 +02:00
outpath = " $( basename " $path " .md) .html "
2020-04-01 22:13:13 +02:00
# convert new markdown posts to html
2020-07-15 21:20:25 +02:00
pandoc -s --css= /css/sakura-vader.css " $path " src/footer/footer.md -t html5 -f markdown -o " dist/ $outpath "
2020-04-01 22:13:13 +02:00
# then add it to the index
2020-07-17 00:38:30 +02:00
title = $( grep -h '<title>' " dist/ $outpath " | sed 's/<title>//g;s/<\/title>//g' )
2020-07-11 00:28:31 +02:00
created = $( grep -h '^date: ' " $path " | sed 's/date: //g' )
2020-07-12 20:09:10 +02:00
html_entry " $outpath " " $created " " $title "
2020-07-17 14:29:37 +02:00
rss_entry " $title " " $outpath " $path $created
2020-04-01 22:13:13 +02:00
}
2020-07-13 01:02:01 +02:00
convert_static( ) {
path = " $9 "
outpath = " $( basename " $path " .md) .html "
2020-07-15 22:59:29 +02:00
pandoc -s --css= /css/sakura-vader.css " $path " src/footer/footer.md -t html5 -f markdown -o " dist/ $outpath "
2020-07-13 01:02:01 +02:00
}
2020-04-01 22:13:13 +02:00
has_updates( ) {
git fetch & > /dev/null
diff = " $( git diff master origin/master) "
if [ " $diff " ] ; then
return 0
else
return 1
fi
}
2020-07-17 14:34:06 +02:00
cd /home/lucy/blog-content/
2020-07-15 21:20:25 +02:00
rm -R dist/*
rsync --delete -avxt static/ dist/
2020-07-12 02:40:30 +02:00
add_header
2020-07-15 21:50:30 +02:00
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
2020-07-12 02:40:30 +02:00
add_footer
2020-07-15 21:20:25 +02:00
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