Skip to content

Instantly share code, notes, and snippets.

@fmeyer
Last active June 13, 2022 22:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmeyer/dfbe320b7f53808f52e2fa7edd12b810 to your computer and use it in GitHub Desktop.
Save fmeyer/dfbe320b7f53808f52e2fa7edd12b810 to your computer and use it in GitHub Desktop.
Renders a Github Wiki with the content and entries from a log book
#!/bin/bash
cd ~/code/logdata.wiki/ || exit
TS=$(date +'%H:%M:%S')
DS=$(date +'%Y-%m-%d')
YEAR=$(date +'%Y')
CURRENT_LOG_DIR="logs/$YEAR/"
# check if current log year exists, creates if no
if [ ! -d "$CURRENT_LOG_DIR" ]; then
mkdir -p "$CURRENT_LOG_DIR"
fi
# check if the first paramether is a note, otherwise points to
# a log entry
if [[ -n $1 ]]; then
TS="$(date +'%d.%m.%Y') $TS"
FILENAME=notes/$1.md
else
FILENAME=logs/$YEAR/$DS.md
fi
git pull --quiet --rebase
# appends the current date and timestamp to the end of the file
printf "\n**%s**\n" "$TS" >> "$FILENAME"
# starts vim without loading any plugins, starts the cursor at the end of the file
# and don't create a swap file
vim -u NONE --cmd "set tw=79" + -n --noplugin "$FILENAME"
tree=$(tree notes -tf --noreport -I '*~' --charset ascii $1 |
sed -e 's/| \+/ /g' -e 's/[|`]-\+/ */g' -e 's:\(* \)\(\(.*/\)\([^/]\+\)\):\1[\4](\4):g' -e 's/\.md//g')
printf "%s\n" "$tree" > _Sidebar.md
tree=$(tree logs -tfr --noreport -I '*~' --charset ascii $1 |
sed -e 's/| \+/ /g' -e 's/[|`]-\+/ */g' -e 's:\(* \)\(\(.*/\)\([^/]\+\)\):\1[\4](\4):g' -e 's/\.md//g')
printf "\n\n%s\n" "$tree" >> _Sidebar.md
git add . && git commit --quiet -am "Updating $FILENAME entry on $TS" && echo "syncing" && git push --quiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment