pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

commit 0bee6e2e566a29699d099a34ee89fecaf1cd1d6c
parent 15c8dc3db8bc87d35a0128a29d80f35b381b28cf
Author: pyratebeard <root@pyratebeard.net>
Date:   Wed,  3 Mar 2021 12:03:51 +0000

add comments

Diffstat:
Mpyratelog.sh | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/pyratelog.sh b/pyratelog.sh @@ -1,23 +1,34 @@ #!/bin/bash function initialise() { + # find all markdown files in 'entry' directory find_md=$(find entry/ -type f -name "*.md" | sort) + + # for each markdown file for md in ${find_md} ; do + + # get the title and date from the filename input=$(echo ${md} | cut -f2 -d '/' | cut -f1 -d '.') + # cut the date and turn into epoch time input_date=$(echo ${input} | cut -f1 -d '-' ) ls -l /bin/date | grep busybox >/dev/null && \ # busybox `date` works differently index_date=$(date -d ${input_date} -D "%Y%m%d" +%s) || \ index_date=$(date -d ${input_date} +%s) + # cut the title and replace underscores with spaces for menu input_title=$(echo ${input} | cut -f2 -d '-' | sed 's/_/\ /g') index_title=$(echo ${input_title}) + # create menu link for index page input_link="<li><a class='index' href='entry/${input}.html'><b>${index_date}</b> ${index_title}</a></li>" + # if link already exists we can stop grep ${input} index.html >/dev/null && return + # for new files we turn the markdown into html + # using a template file pandoc -s \ --template=./post_template.html \ --metadata title="${input_title}" \ @@ -26,14 +37,18 @@ function initialise() { -o entry/${input}.html \ entry/${input}.md + # add the link to the top of the menu sed "/<ul class='index'>/a ${input_link}" index.html > index.html.bak + # replace old index page cat index.html.bak >index.html + # tidy up rm -f index.html.bak done } +# watch the entry directory for new files while : ; do ls ./entry/*.md >/dev/null 2>&1 && initialise || sleep 30 done