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

weeknote.sh (997B)


      1 #!/usr/bin/env bash
      2 # Create or edit next Monday's weeknote
      3 
      4 set -eu
      5 
      6 HUGODIR=<path-to-hugo-root>
      7 POSTFILE=index.md
      8 WEEKSTR=$(date +"%G-W%V" --date="07:59 next Mon")
      9 POSTDIR=$(echo "content/posts/weeknotes/${WEEKSTR}" | tr A-Z a-z)
     10 
     11 pushd "$HUGODIR"
     12 GITCURRBRANCH=$(git branch --show-current)
     13 
     14 if ! grep -q "$WEEKSTR" <(git branch --list)
     15 then
     16     git branch "$WEEKSTR" main
     17 fi
     18 git switch "$WEEKSTR"
     19 
     20 if [[ ! -d "$POSTDIR" ]]
     21 then
     22     mkdir -p "$POSTDIR"
     23 fi
     24 pushd "$POSTDIR"
     25 
     26 if [[ ! -f "$POSTFILE" ]]
     27 then
     28     # Fill in the frontmatter
     29     cat << HERE > "$POSTFILE"
     30 ---
     31 title: "Weeknote for $WEEKSTR"
     32 description: "Things I learned or read in the last week"
     33 date: $(date -Iseconds --date="07:59 next Mon")
     34 draft: true
     35 ---
     36 HERE
     37 
     38     COMMITMSG="Add weeknote for $WEEKSTR"
     39 else
     40     COMMITMSG="Update weeknote for $WEEKSTR"
     41 fi
     42 
     43 # Edit the weeknote
     44 $EDITOR "$POSTFILE"
     45 
     46 # Commit the weeknote
     47 git add "$POSTFILE"
     48 git commit -m "$COMMITMSG" "$POSTFILE"
     49 
     50 # Clean up
     51 git switch "$GITCURRBRANCH"
     52 popd
     53 popd