Organizing posts according to date

Something like:

#!/usr/bin/env bash

main() {
  if [[ $# -eq 0 ]]; then
    echo "Error: missing path to new content."
    echo "Example: $0 blog/mypost.md"
    exit 1
  fi

  declare path=$1
  hugo new "${path%%/*}/$(date +%Y/%m)/${path#*/}"
}

set -euo pipefail
main "$@"
1 Like