www.eamoncaddigan.net

Content and configuration for https://www.eamoncaddigan.net
git clone https://git.eamoncaddigan.net/www.eamoncaddigan.net.git
Log | Files | Refs | Submodules | README

commit a1d26ecca1438525f377ba2d7e4d4374ea211cac
parent 0f24c9f5c4f5be8dc2cff6df1ab86358b1d621b1
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Sat, 28 Dec 2024 21:24:38 -0800

Complete first draft of weeknote script

Diffstat:
Acontent/december-adventure/2024-29/weeknote.sh | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+), 0 deletions(-)

diff --git a/content/december-adventure/2024-29/weeknote.sh b/content/december-adventure/2024-29/weeknote.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# Create or edit next Monday's weeknote + +set -eu + +HUGODIR=<path-to-hugo-root> +POSTFILE=index.md +WEEKSTR=$(date +"%G-W%V" --date="07:59 next Mon") +POSTDIR=$(echo "content/posts/weeknotes/${WEEKSTR}" | tr A-Z a-z) + +pushd "$HUGODIR" +GITCURRBRANCH=$(git branch --show-current) + +if ! grep -q "$WEEKSTR" <(git branch --list) +then + git branch "$WEEKSTR" main +fi +git switch "$WEEKSTR" + +if [[ ! -d "$POSTDIR" ]] +then + mkdir -p "$POSTDIR" +fi +pushd "$POSTDIR" + +if [[ ! -f "$POSTFILE" ]] +then + # Fill in the frontmatter + cat << HERE > "$POSTFILE" +--- +title: "Weeknote for $WEEKSTR" +description: "Things I learned or read in the last week" +date: $(date -Iseconds --date="07:59 next Mon") +draft: true +--- +HERE + + COMMITMSG="Add weeknote for $WEEKSTR" +else + COMMITMSG="Update weeknote for $WEEKSTR" +fi + +# Edit the weeknote +$EDITOR "$POSTFILE" + +# Commit the weeknote +git add "$POSTFILE" +git commit -m "$COMMITMSG" "$POSTFILE" + +# Clean up +git switch "$GITCURRBRANCH" +popd +popd