firehose/scripts/new-post.sh
2026-04-02 10:59:06 +00:00

49 lines
914 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: $0 \"Post Title\" [blog]"
echo " blog: engineering (default) or release-notes"
exit 1
}
[[ $# -lt 1 ]] && usage
title="$1"
blog="${2:-engineering}"
# Title to slug: lowercase, spaces/underscores to hyphens, strip non-alphanumeric
slug=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' _' '-' | sed 's/[^a-z0-9-]//g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
year=$(date +%Y)
month_day=$(date +%m-%d)
dir="app/priv/blog/${blog}/${year}"
file="${dir}/${month_day}-${slug}.md"
# Find repo root
cd "$(dirname "$0")/.."
mkdir -p "$dir"
if [[ -f "$file" ]]; then
echo "File already exists: $file"
exit 1
fi
cat > "$file" <<EOF
%{
title: "${title}",
author: "Firehose Team",
tags: ~w(),
description: "",
published: false
}
---
EOF
echo "Created: $file"
if [[ -n "${EDITOR:-}" ]] && [[ -t 1 ]]; then
exec "$EDITOR" "$file"
fi