Creating an editorial calendar with a bash script
By goz
I find that it really helps me to schedule posts in advance, so I know what to work on. However, since I use Hugo and a folder full of Markdown files, I couldn’t find anything that would show me what was scheduled for when, so I decided to write up a little bash script.
The only prerequisit is the faketime
command. This is used along with date
to pull up the dates needed for the calendar. To use, run the script on your folder of drafts.
There is two caveats. One, if the filename starts with a date in the format of yyyy-mm-dd
the script will drop the date before name when shown in the calendar. This means if there isn’t anything after the date in the filename, nothing will show. The second caveat is that if there are multiple posts scheduled for a day the script will only show the first one. Maybe version two will fix that…
#!/bin/bash
# Requires `faketime` to be installed
if ! command -v faketime &> /dev/null
then
echo "faketime could not be found, please install"
exit
fi
if [ $(date +"%u") == "1" ]; then
first=$(date +"%Y-%m-%d")
else
first=$(date -d "last monday" +"%Y-%m-%d")
fi
temp="##############"
for day in {0..29..7}
do
dateline=""
artline=""
blankline=""
for dow in {0..6}
do
calcday=$(($day + $dow))
tday=$(faketime "${first}" date -d "${calcday} day" +"%Y-%m-%d")
file=$(grep -i ^date\: *.md | grep "${tday}" | cut -d ":" -f 1)
if [[ ${file:0:2} == "20" ]]; then
out=${file:11:14}
else
out=${file:0:14}
fi
if [ -z ${file} ]; then out=" "; fi
dateline=${dateline}$(echo -en "|--${tday}--")
#artline="${artline}"$(echo "|${temp:0:-${#out}}${out}")
artline="${artline}"$(printf "|%-14s" ${out})
blankline="${blankline}| "
done
echo "${dateline}|"
echo "${artline}|"
echo "${blankline}|"
done