Created
April 18, 2015 20:47
-
-
Save DirkR/aabb1b6fa97ff92ed86a to your computer and use it in GitHub Desktop.
This shell function "new_post" generates the file structure for a blog post in textbundle format (see http://textbundle.org/spec/). Append the code fragment at the end of yout `~/.bashrc` or `~/.zshrc`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# append at the end of yout ~/.bashrc or ~/.zshrc | |
new_post() { | |
local title="$*" | |
if [ -z $title ]; then | |
echo "No title given. Usage: new_post \"My post title\"" | |
return | |
fi | |
local date=$(date "+%Y-%m-%d") | |
local slug=$(echo $title | tr -cd "[:alnum:][:blank:]" | tr -s '[:blank:]' '-' | tr "[:upper:]" "[:lower:]" ) | |
local pelican_dir=~/Projects/niebegeg.net | |
local posts_dir=content/posts | |
local target_dir="${pelican_dir}/${posts_dir}/${date}_${slug}.textbundle" | |
if [ -d $target_dir ]; then | |
echo "Target folder $target_dir exists." | |
return | |
fi | |
mkdir -p "$target_dir/assets" | |
cat > "$target_dir/text.md" <<EOPOST | |
title: ${title} | |
date: ${date} | |
category: misc | |
#tags: | |
slug: ${slug} | |
EOPOST | |
cat > "$target_dir/info.json" <<EOINFO | |
{ | |
"version": 1, | |
"transient": false, | |
"creatorURL": "http://getpelican.com/", | |
"creatorIdentifier": "https://github.com/getpelican/pelican-plugins/textbundle" | |
} | |
EOINFO | |
echo "Created new post in folder $target_dir" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment