leDailySquirrel/scripts/new-edition.sh

42 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2026-07-04 19:55:57 +00:00
#!/bin/bash
# 1. Enforce the "One Draft Limit" rule
if grep -qr "status: draft" content/editions/ 2>/dev/null; then
echo "❌ Error: An open draft already exists. Publish or delete it first."
exit 1
fi
# 2. Calculate the next edition number
LATEST_ED=$(grep -h "^edition_number:" content/editions/*/index.md 2>/dev/null | awk '{print $2}' | sort -n | tail -1)
NEXT_ED=$((LATEST_ED + 1))
NEXT_DATE=$(date +%Y-%m-%d)
DIR="content/editions/$NEXT_DATE"
# 3. Prevent overwriting today's edition if one was already published today
if [ -d "$DIR" ]; then
echo "❌ Error: An edition for $NEXT_DATE already exists."
exit 1
fi
# 4. Scaffold the directory and the index.md front matter
mkdir -p "$DIR"
cat <<EOF > "$DIR/index.md"
---
layout: edition
edition_number: $NEXT_ED
date: $NEXT_DATE
status: draft
title: "Edition No. $NEXT_ED"
---
EOF
# 5. Handle the Git branch routing
BRANCH_NAME="edition/$NEXT_DATE/open"
git checkout -b "$BRANCH_NAME"
git add "$DIR/index.md"
git commit -m "chore: scaffold draft for Edition $NEXT_ED"
echo "✅ Success! Scaffolded Edition $NEXT_ED."
echo "🌲 Moved to new branch: $BRANCH_NAME"
echo "🤖 Agents may now open PRs targeting this branch."