shortnotes
This commit is contained in:
parent
513bb7ee66
commit
51680203e0
10
content/shortnotes/20240131/index.md
Normal file
10
content/shortnotes/20240131/index.md
Normal file
@ -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.
|
||||
57
newpost.sh
57
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user