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( ) {
echo " $1 " >> index.html
}
2020-04-26 17:37:47 +02:00
output_rss( ) {
echo " $1 " >> rss.xml
}
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-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-05-04 20:15:48 +02:00
output_rss " <link href=\" $blog_domain \" 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-11 00:45:58 +02:00
html_entry "https://asagi.moe" "before July 2020" "Old site"
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>'
path = " $1 "
time = " $2 "
title = " $3 "
output " <td class=\"first\"><a href=\" $path \"> $title </a></td> "
output " <td class=\"second\"> $time </td></tr> "
}
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-04-26 17:37:47 +02:00
<title>$1 </title>
<link>$blog_domain $2 </link>
2020-05-04 20:15:48 +02:00
<link href = \" $blog_domain $2 \" type = \" text/html\" title = \" $1 \" />
<content type = \" html\" xml:base= \" $blog_domain $2 \" >
$( tail -n+2 " $2 " | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/' "'" '/\'/g' )
</content>
</entry>"
2020-04-26 17:37:47 +02:00
}
2020-04-01 22:13:13 +02:00
create_entry( ) {
path = " $9 "
outpath = " content/ $( basename " $path " .md) .html "
# convert new markdown posts to html
2020-04-02 18:28:54 +02:00
pandoc " $path " -t html -f markdown -o " $outpath "
2020-04-01 22:13:13 +02:00
# then add it to the index
2020-07-11 00:28:31 +02:00
title = " $( grep -h '^title: ' " $path " | sed 's/title: //g' ) "
created = $( grep -h '^date: ' " $path " | sed 's/date: //g' )
2020-04-01 22:13:13 +02:00
html_entry " $outpath " " created on $created " " $title "
2020-04-26 17:37:47 +02:00
rss_entry " $title " " $outpath "
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
}
cd /home/nginx/html/blog
2020-04-02 00:06:22 +02:00
git pull & > /dev/null
rm -f index.html
2020-04-26 17:37:47 +02:00
rm -f rss.xml
2020-04-26 16:58:43 +02:00
add_header
2020-04-01 22:13:13 +02:00
ls -ltu src/*.md | tail -n+1 | while read f; do create_entry $f ; done
2020-04-26 16:58:43 +02:00
add_footer
2020-04-02 00:06:22 +02:00
# Human-readable output for the cron notification
2020-04-02 15:54:39 +02:00
echo 'Updated blog to:'
git log -1