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
|
# Get location of script, posts root
|
||||||
parent_path=$(cd "$(dirname "$BASH_SOURCE[0]}")" ; pwd -P)
|
parent_path=$(cd "$(dirname "$BASH_SOURCE[0]}")" ; pwd -P)
|
||||||
posts_root="$parent_path/content/posts"
|
posts_root="$parent_path/content/posts"
|
||||||
|
shortnotes_root="$parent_path/content/shortnotes"
|
||||||
|
|
||||||
# Get time
|
# Get time
|
||||||
year=$(date +%Y)
|
year=$(date +%Y)
|
||||||
@ -10,7 +11,9 @@ month=$(date +%m)
|
|||||||
day=$(date +%d)
|
day=$(date +%d)
|
||||||
|
|
||||||
post_name="$year$month$day"
|
post_name="$year$month$day"
|
||||||
OPTSTRING=":n:"
|
OPTSTRING=":n:s"
|
||||||
|
|
||||||
|
shortnotestag=""
|
||||||
|
|
||||||
# Get options
|
# Get options
|
||||||
while getopts ${OPTSTRING} opt; do
|
while getopts ${OPTSTRING} opt; do
|
||||||
@ -18,6 +21,12 @@ while getopts ${OPTSTRING} opt; do
|
|||||||
n)
|
n)
|
||||||
post_name=${OPTARG}
|
post_name=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
s)
|
||||||
|
shortnote=true
|
||||||
|
shortnotestag="\"shortnotes\""
|
||||||
|
posts_root=$shortnotes_root
|
||||||
|
;;
|
||||||
|
|
||||||
:)
|
:)
|
||||||
echo "Option -${OPTARG} requires an argument"
|
echo "Option -${OPTARG} requires an argument"
|
||||||
exit 1
|
exit 1
|
||||||
@ -33,22 +42,30 @@ done
|
|||||||
# Fix post name for filesystem
|
# Fix post name for filesystem
|
||||||
post_file_name=$(echo $post_name | sed "s/[ _]/-/g" | tr '[:upper:]' '[:lower:]')
|
post_file_name=$(echo $post_name | sed "s/[ _]/-/g" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
# Verify year path
|
post_path="$posts_root/$post_file_name"
|
||||||
if ! [ -d $posts_root/$year ]; then
|
|
||||||
# Create new year
|
if [ $shortnote == false ] ; then
|
||||||
mkdir $posts_root/$year
|
# Verify year path
|
||||||
cp $posts_root/2023/_index.md $posts_root/$year/_index.md
|
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
|
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)
|
# Create folder for post (in case of images)
|
||||||
mkdir -p "$posts_root/$year/$month/$post_file_name"
|
mkdir -p "$post_path"
|
||||||
|
|
||||||
|
|
||||||
# Create template file
|
# Create template file
|
||||||
read -r -d '' TEMPLATE << EOF
|
read -r -d '' TEMPLATE << EOF
|
||||||
@ -59,24 +76,24 @@ date = $year-$month-$day
|
|||||||
# updated = $year-$month-$day
|
# updated = $year-$month-$day
|
||||||
draft = true
|
draft = true
|
||||||
[taxonomies]
|
[taxonomies]
|
||||||
tags = []
|
tags = [$shortnotestag]
|
||||||
+++
|
+++
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Skip overwrite if exists
|
# 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 "Creating a new post..."
|
||||||
echo "$TEMPLATE" >> $posts_root/$year/$month/$post_file_name/index.md
|
echo "$TEMPLATE" >> $post_path/index.md
|
||||||
fi
|
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
|
# Open vim/vi/nano
|
||||||
if command -v vim &> /dev/null; then
|
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
|
elif command -v vi &> /dev/null; then
|
||||||
vi $posts_root/$year/$month/$post_file_name/index.md
|
vi $post_path/index.md
|
||||||
else
|
else
|
||||||
nano $posts_root/$year/$month/$post_file_name/index.md
|
nano $post_path/index.md
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user