Skip to content

Commit af9b7cd

Browse files
committed
Add post scaffolding skill and helper script (squash merge #43)
1 parent 359da71 commit af9b7cd

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
name: add-post-skill
3+
description: Create a new Jekyll blog post in _posts/ using the site's filename convention, required front matter, and a starter content shell.
4+
---
5+
6+
# Add Post Skill
7+
8+
## When to use
9+
Use this skill when asked to create, initialize, scaffold, or draft a new blog post for this site.
10+
11+
## Goal
12+
Create a new Markdown file in `_posts/` that matches this repository's Jekyll conventions.
13+
14+
## Inputs
15+
- title (required)
16+
- description (optional)
17+
- date (optional, YYYY-MM-DD)
18+
- draft flag (optional)
19+
20+
## Implementation
21+
Use the helper script:
22+
23+
```
24+
scripts/new-post.sh "<title>" "<description>" "<date>"
25+
```
26+
27+
## Behavior
28+
- Slugify title (lowercase, hyphenated)
29+
- Use provided date or default to current date
30+
- If draft flag is set, create file in `_drafts/slug.md`
31+
- Otherwise create `_posts/YYYY-MM-DD-slug.md`
32+
- Validate slug is non-empty
33+
- Quote YAML values safely
34+
- Do not overwrite existing files
35+
36+
## Template
37+
38+
---
39+
layout: post
40+
title: "<TITLE>"
41+
date: <YYYY-MM-DD>
42+
description: "<OPTIONAL>"
43+
---
44+
45+
Write your introduction here.
46+
47+
## Key points
48+
49+
-
50+
-
51+
-
52+
53+
## Details
54+
55+
## Closing
56+
57+
## Notes
58+
- Permalinks handled by `_config.yml`
59+
- Script available: `scripts/new-post.sh`

scripts/new-post.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
usage() {
5+
echo 'Usage: scripts/new-post.sh [--draft] "Post Title" [description] [date]'
6+
}
7+
8+
yaml_escape() {
9+
local value="${1:-}"
10+
value=${value//\\/\\\\}
11+
value=${value//\"/\\\"}
12+
printf '%s' "$value"
13+
}
14+
15+
DRAFT=false
16+
17+
if [[ ${1:-} == "--draft" ]]; then
18+
DRAFT=true
19+
shift
20+
fi
21+
22+
if [[ $# -lt 1 || $# -gt 3 ]]; then
23+
usage
24+
exit 1
25+
fi
26+
27+
TITLE="$1"
28+
DESCRIPTION="${2:-}"
29+
DATE="${3:-$(date +%F)}"
30+
31+
if [[ ! "$DATE" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
32+
echo "Invalid date: $DATE (expected YYYY-MM-DD)"
33+
exit 1
34+
fi
35+
36+
SLUG="$(printf '%s' "$TITLE" \
37+
| tr '[:upper:]' '[:lower:]' \
38+
| sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//; s/-+/-/g')"
39+
40+
if [[ -z "$SLUG" ]]; then
41+
echo "Unable to generate slug from title: $TITLE"
42+
exit 1
43+
fi
44+
45+
if [[ "$DRAFT" == "true" ]]; then
46+
DIR="_drafts"
47+
FILE="${DIR}/${SLUG}.md"
48+
else
49+
DIR="_posts"
50+
FILE="${DIR}/${DATE}-${SLUG}.md"
51+
fi
52+
53+
mkdir -p "$DIR"
54+
55+
if [[ -e "$FILE" ]]; then
56+
echo "Refusing to overwrite existing file: $FILE"
57+
exit 1
58+
fi
59+
60+
{
61+
echo "---"
62+
echo "layout: post"
63+
printf 'title: "%s"\n' "$(yaml_escape "$TITLE")"
64+
printf 'date: %s\n' "$DATE"
65+
if [[ -n "$DESCRIPTION" ]]; then
66+
printf 'description: "%s"\n' "$(yaml_escape "$DESCRIPTION")"
67+
fi
68+
echo "---"
69+
echo
70+
echo "Write your introduction here."
71+
echo
72+
echo "## Key points"
73+
echo
74+
echo "- Add your first point"
75+
echo "- Add your second point"
76+
echo "- Add your third point"
77+
echo
78+
echo "## Details"
79+
echo
80+
echo "Add the main body of the post here."
81+
echo
82+
echo "## Closing"
83+
echo
84+
echo "Wrap up with the takeaway or next step."
85+
} > "$FILE"
86+
87+
echo "Created $FILE"

0 commit comments

Comments
 (0)