You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
996 B
Bash

2 years ago
#!/bin/bash
# pickmy.org post composer
# by: Jay/nq4t/@music_onhold
# usage: ./compose.sh [category] [title]
2 years ago
# example: /compose.sh blog MY AWESOME POST TITLE NO YOU DON'T NEED TO ENCLOSE IT!
2 years ago
# run in the root of your site files/repository
# assumes categories are directories in root
2 years ago
# Variables and category argument
2 years ago
category=$1
pd=$(date +'%Y-%m-%d')
pt=$(date +'%T')
file=blog$$.md
2 years ago
# Ditch the category argument
shift 1
# Read everything else as title.
title=$@
2 years ago
t=${title,,}
2 years ago
t=${t// /-}
2 years ago
fd=$(date +'%Y/%^b/%d')
2 years ago
# Let's write the front matter to our temp file.
printf -- "---\ntitle: $title\nlayout: post\ndate: $pd $pt\npermalink: /$category/$fd-$t.php\nexcerpt_separator: <!--more-->\n---\n\n" >> $file
2 years ago
# Write the post in whatever editor you want.
2 years ago
nano + $file
2 years ago
2 years ago
# Move the file to category/_posts replacing spaces with hyphen
2 years ago
mv $file $category/_posts/$pd-${t// /-}.md
2 years ago
# Display some output to verify it's done.
2 years ago
printf "\nPost $title created in $category: $category/_posts/$pd-$t.md\n\n"