nichijou/gen_blogpost.sh

49 lines
742 B
Bash
Raw Normal View History

#!/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.md"
2022-07-12 18:07:32 -04:00
# $name
2022-07-12 18:07:32 -04:00
\`\`\`{toctree}
---
maxdepth: 1
glob:
2022-07-12 18:07:32 -04:00
---
*/index
2022-07-12 18:07:32 -04:00
\`\`\`
EOF
fi
done
mkdir -- "$archive/$year/$month/$timestamp"
2022-07-12 18:07:32 -04:00
<<-EOF cat - >"$archive/$year/$month/$timestamp/index.md"
# $title
*Written $title*
2022-07-12 18:07:32 -04:00
\`\`\`{contents}
\`\`\`
2022-07-12 18:07:32 -04:00
## TODO
EOF
printf '%s\n' "$archive/$year/$month/$timestamp"
exit 0