From aa9b8443c9111c553ab31b83693b1709a8ae8e92 Mon Sep 17 00:00:00 2001 From: Renken Date: Sat, 12 Mar 2022 15:39:40 +0100 Subject: [PATCH] automate blog post generation Generates a blog post under ./doc/log/archive/$year/$month/$timestamp. It'll come in handy when writing random short thoughts. --- doc/log/index.rst | 6 ++++++ gen_blogpost.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 gen_blogpost.sh diff --git a/doc/log/index.rst b/doc/log/index.rst index dd5af0b..14fb9da 100644 --- a/doc/log/index.rst +++ b/doc/log/index.rst @@ -8,3 +8,9 @@ Unfinished thoughts, unfinished projects. :maxdepth: 1 */index + +.. toctree:: + :glob: + :maxdepth: 1 + + */*/*/*/index diff --git a/gen_blogpost.sh b/gen_blogpost.sh new file mode 100755 index 0000000..c348690 --- /dev/null +++ b/gen_blogpost.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +set -eu + +timestamp="$(date '+%s')" +title="$(date '+%Y-%m-%d %H:%M' --date="@$timestamp")" +year="$(date '+%Y')" +month="$(date '+%m')" + +archive=./doc/log/archive + +for dir in "$archive" "$archive/$year" "$archive/$year/$month"; do + if [ ! -d "$dir" ]; then + mkdir -- "$dir" + name="$(basename -- "$dir")" + if [ "$name" = archive ]; then + name=Archive + fi + <<-EOF cat - >"$dir/index.rst" + $name + $(printf '%s\n' "$name" | sed -E 's|.|=|g') + + .. toctree:: + $(printf '\t'):glob: + $(printf '\t'):maxdepth: 1 + + $(printf '\t')*/index + EOF + fi +done + +mkdir -- "$archive/$year/$month/$timestamp" + + +<<-EOF cat - >"$archive/$year/$month/$timestamp/index.rst" + $title + $(printf '%s\n' "$title" | sed -E 's|.|=|g') + + .. contents:: + + TODO + ---- +EOF + +printf '%s\n' "$archive/$year/$month/$timestamp" +exit 0