From 51680203e09001522b1d1fa0b3c1ad204b797cd6 Mon Sep 17 00:00:00 2001 From: Lukas Date: Sun, 24 Mar 2024 15:45:15 -0400 Subject: [PATCH] shortnotes --- content/shortnotes/20240131/index.md | 10 +++++ newpost.sh | 57 ++++++++++++++++++---------- 2 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 content/shortnotes/20240131/index.md diff --git a/content/shortnotes/20240131/index.md b/content/shortnotes/20240131/index.md new file mode 100644 index 0000000..39e0206 --- /dev/null +++ b/content/shortnotes/20240131/index.md @@ -0,0 +1,10 @@ ++++ +title = "Shortnotes Change" +# description = "" +date = 2024-01-31 +# updated = 2024-01-31 +[taxonomies] +tags = ["shortnotes"] ++++ + +In the interest of keeping things easier to read, I've migrated all of my "shortnotes" posts to a separate page. diff --git a/newpost.sh b/newpost.sh index 67f7b3a..855fdb2 100755 --- a/newpost.sh +++ b/newpost.sh @@ -3,6 +3,7 @@ # Get location of script, posts root parent_path=$(cd "$(dirname "$BASH_SOURCE[0]}")" ; pwd -P) posts_root="$parent_path/content/posts" +shortnotes_root="$parent_path/content/shortnotes" # Get time year=$(date +%Y) @@ -10,7 +11,9 @@ month=$(date +%m) day=$(date +%d) post_name="$year$month$day" -OPTSTRING=":n:" +OPTSTRING=":n:s" + +shortnotestag="" # Get options while getopts ${OPTSTRING} opt; do @@ -18,6 +21,12 @@ while getopts ${OPTSTRING} opt; do n) post_name=${OPTARG} ;; + s) + shortnote=true + shortnotestag="\"shortnotes\"" + posts_root=$shortnotes_root + ;; + :) echo "Option -${OPTARG} requires an argument" exit 1 @@ -33,22 +42,30 @@ done # Fix post name for filesystem post_file_name=$(echo $post_name | sed "s/[ _]/-/g" | tr '[:upper:]' '[:lower:]') -# Verify year path -if ! [ -d $posts_root/$year ]; then - # Create new year - mkdir $posts_root/$year - cp $posts_root/2023/_index.md $posts_root/$year/_index.md +post_path="$posts_root/$post_file_name" + +if [ $shortnote == false ] ; then + # Verify year path + if ! [ -d $posts_root/$year ]; then + # Create new year + mkdir $posts_root/$year + cp $posts_root/2023/_index.md $posts_root/$year/_index.md + fi + + # Verify month path + if ! [ -d $posts_root/$year/$month ]; then + # Create new year + mkdir $posts_root/$year/$month + cp $posts_root/2023/_index.md $posts_root/$year/$month/_index.md + fi + + post_path="$posts_root/$year/$month/$posts_file_name" fi -# Verify month path -if ! [ -d $posts_root/$year/$month ]; then - # Create new year - mkdir $posts_root/$year/$month - cp $posts_root/2023/_index.md $posts_root/$year/$month/_index.md -fi # Create folder for post (in case of images) -mkdir -p "$posts_root/$year/$month/$post_file_name" +mkdir -p "$post_path" + # Create template file read -r -d '' TEMPLATE << EOF @@ -59,24 +76,24 @@ date = $year-$month-$day # updated = $year-$month-$day draft = true [taxonomies] -tags = [] +tags = [$shortnotestag] +++ EOF # Skip overwrite if exists -if ! [ -f $posts_root/$year/$month/$post_file_name/index.md ]; then +if ! [ -f $post_path/index.md ]; then echo "Creating a new post..." - echo "$TEMPLATE" >> $posts_root/$year/$month/$post_file_name/index.md + echo "$TEMPLATE" >> $post_path/index.md fi -echo "Post file is at $posts_root/$year/$month/$post_file_name/index.md" +echo "Post file is at $post_path/index.md" # Open vim/vi/nano if command -v vim &> /dev/null; then - vim $posts_root/$year/$month/$post_file_name/index.md + vim $post_path/index.md elif command -v vi &> /dev/null; then - vi $posts_root/$year/$month/$post_file_name/index.md + vi $post_path/index.md else - nano $posts_root/$year/$month/$post_file_name/index.md + nano $post_path/index.md fi