This commit was merged in pull request #1.
This commit is contained in:
49
scripts/aw-post
Executable file
49
scripts/aw-post
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env bash
|
||||
# aw-post — Quick-post a scroll from the command line
|
||||
#
|
||||
# Usage:
|
||||
# aw-post "Title of the Post"
|
||||
# aw-post "Title" < body.md
|
||||
# echo "Post body here" | aw-post "Title"
|
||||
#
|
||||
# Creates a new markdown file in blog/posts/ with frontmatter.
|
||||
# Rebuilds the blog index and RSS feed.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
BLOG_DIR="$(cd "$(dirname "$0")/.." && pwd)/blog/posts"
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: aw-post \"Title of the Post\""
|
||||
echo " Pipe or redirect body content via stdin."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TITLE="$1"
|
||||
DATE=$(date +%Y-%m-%d)
|
||||
SLUG=$(echo "$TITLE" | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | tr -cd 'a-z0-9-')
|
||||
FILENAME="${DATE}-${SLUG}.md"
|
||||
FILEPATH="${BLOG_DIR}/${FILENAME}"
|
||||
|
||||
if [ -f "$FILEPATH" ]; then
|
||||
echo "Error: $FILEPATH already exists"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Read body from stdin if available
|
||||
BODY=""
|
||||
if [ ! -t 0 ]; then
|
||||
BODY=$(cat)
|
||||
fi
|
||||
|
||||
cat > "$FILEPATH" << EOF
|
||||
---
|
||||
title: "${TITLE}"
|
||||
date: ${DATE}
|
||||
---
|
||||
|
||||
${BODY}
|
||||
EOF
|
||||
|
||||
echo "Created: ${FILEPATH}"
|
||||
echo "Next: rebuild with 'make build'"
|
||||
Reference in New Issue
Block a user