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-18 23:25:45 +02:00
echo " $1 " >> dist/posts-table.html
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-18 23:17:47 +02:00
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>'
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-18 01:13:13 +02:00
<author><name>Lucy</name></author>
<title type = "text" >Lucys blog</title>'
2020-07-18 22:43:25 +02:00
output_rss " <updated> $( date --iso-8601= seconds) </updated>
2020-07-18 01:13:13 +02:00
<id>https://lucy.moe/rss.xml</id>
<link href = \" https://lucy.moe/rss.xml\" rel = \" self\" type = \" application/atom+xml\" />"
2020-04-26 16:58:43 +02:00
}
add_footer( ) {
2020-07-18 22:43:25 +02:00
html_entry "https://asagi.moe" "before July 2020" "Old site"
2020-07-18 23:17:47 +02:00
output ' </tbody>
</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 "
2020-07-18 23:17:47 +02:00
output " <td><a href=\" $webpath \"> $title </a></td> "
output " <td style=\"text-align: right\"> $time </td></tr> "
2020-04-01 22:13:13 +02:00
}
2020-04-26 17:37:47 +02:00
rss_entry( ) {
2020-07-18 23:31:23 +02:00
# this is made to represent what heise.de has done with
# their rss/atom feeds and doesn't need any escaping
2020-05-04 20:15:48 +02:00
output_rss " <entry>
2020-07-17 14:29:37 +02:00
<title type = \" text\" >$1 </title>
2020-07-18 22:43:25 +02:00
<published>$( date --iso-8601= seconds -d $4 ) </published>
<updated>$( date --iso-8601= seconds -r $3 ) </updated>
2020-07-17 14:29:37 +02:00
<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\" >
2020-07-18 01:13:13 +02:00
$( grep -h '^<p>' " dist/ $2 " | head -n 1 | sed 's/<p>//;s/<\/p>//;/<!--/d;s/^/ /' )
2020-07-17 14:29:37 +02:00
</summary>
2020-07-18 01:13:13 +02:00
<content type = \" html\" xml:base= \" $blog_domain $2 \" ><![ CDATA[
$( pandoc $3 | sed '/<!--/d;s/^/ /' ) ] ] >
2020-05-04 20:15:48 +02:00
</content>
</entry>"
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-07-21 18:46:35 +02:00
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 " )
2020-04-01 22:13:13 +02:00
# convert new markdown posts to html
2020-07-21 14:35:51 +02:00
pandoc -s --css= /css/sakura-vader.css --template= ./pandoc-template-v2.2.1.html5 \
2020-07-21 18:46:35 +02:00
-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 "
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-18 22:43:25 +02:00
html_entry " $outpath " " $created_date " " $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-21 18:46:35 +02:00
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 "
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-21 18:46:35 +02:00
footer = " $( cat src/footer/footer.html) "
2020-07-17 14:34:06 +02:00
cd /home/lucy/blog-content/
2020-07-15 21:20:25 +02:00
rm -R dist/*
2020-07-18 23:31:23 +02:00
rsync -q --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-21 18:46:35 +02:00
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