Skip to content
Open
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ These scripts will:
authors:
- chris
categories:
- Category Name
- CategoryOne
- CategoryTwo
tags:
- relevant-tag
- relevant-tag-one
- relevant-tag-two
---
```

Expand Down
12 changes: 11 additions & 1 deletion create_post.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ title: "$title"
date: $date
authors:
- chris | norm | omar
categories:
# use existing categories when possible, in YAML list format.
- CATEGORY_ONE
- CATEGORY_TWO
tags:
# use existing tags when possible, in YAML list format.
- TAG_ONE
- TAG_TWO
---

TOPIC_INTRODUCTION_HERE
Expand All @@ -55,4 +63,6 @@ Everyone and anyone are welcome to [join](https://weeklydevchat.com/join/) as lo
# Write the content to the file
Set-Content -Path $filePath -Value $yamlContent

Write-Output "Blog post template created at $filePath"
Write-Output "Blog post template created at $filePath"
Write-Output ""
Write-Output "Reminder: Use existing categories and tags when possible."
32 changes: 24 additions & 8 deletions create_post.sh
Copy link
Contributor

@normanlorrain normanlorrain Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh, my editor "cleaned up" the whitespace. I only added the last two lines.

I restored the file, and re-added my changes.

Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/bin/bash

# Calculate the next Tuesday (or today if it's Tuesday)
# In Linux date, weekday: 0=Sunday, 1=Monday, ..., 6=Saturday
current_weekday=$(date +%w) # 0=Sun ... 6=Sat
days_to_tuesday=$(( (2 - current_weekday + 7) % 7 ))

# If today is Tuesday, days_to_tuesday will be 0 → perfect
# Add the calculated days
tuesday=$(date -d "+${days_to_tuesday} days" +%Y-%m-%d)
# Add the calculated days (compatible with both macOS and Linux)
if date -v +0d &>/dev/null; then
# macOS (BSD date)
tuesday=$(date -v "+${days_to_tuesday}d" +%Y-%m-%d)
else
# Linux (GNU date)
tuesday=$(date -d "+${days_to_tuesday} days" +%Y-%m-%d)
fi

year=$(date -d "$tuesday" +%Y)
month=$(date -d "$tuesday" +%02m)
day=$(date -d "$tuesday" +%02d)
year=${tuesday%%-*} # 2026
month=${tuesday#*-}; month=${month%-*} # 02
day=${tuesday##*-} # 24

# Define paths
folder_path="docs/posts/$year/$month/$day"
Expand All @@ -27,6 +31,14 @@ title: "Your Blog Post Title"
date: $tuesday
authors:
- chris | norm | omar
categories:
# use existing categories when possible, in YAML list format.
- CATEGORY_ONE
- CATEGORY_TWO
tags:
# use existing tags when possible, in YAML list format.
- TAG_ONE
- TAG_TWO
---

TOPIC_INTRODUCTION_HERE
Expand All @@ -36,4 +48,8 @@ Everyone and anyone are welcome to [join](https://weeklydevchat.com/join/) as lo
![alt text](${tuesday}_image_filename.webp)
EOF

echo "Blog post template created at $file_path"
echo "Blog post template created at $file_path"
echo ""
echo "Reminder: Use existing categories and tags when possible."

python "./docs/find_tags_categories.py"
77 changes: 77 additions & 0 deletions docs/find_tags_categories.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrbiggred not sure if it's bad form to add a file to a PR.

This script mines the existing documents to pull out the tags and categories, so they can be displayed in the "create_post" scripts.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env python3
"""
Lists all unique tags and categories found in YAML front matter of .md files.
Looks for both 'tags' and 'categories' keys (common variations).
"""

import os
import yaml
from pathlib import Path
from typing import Set

DOCS_DIR = Path(__file__).parent
EXTENSIONS = (".md", ".markdown", ".mkd")

def extract_frontmatter(file_path: Path) -> dict:
"""Extract YAML front matter if present."""
content = file_path.read_text(encoding="utf-8")
if not content.startswith("---"):
return {}
try:
parts = content.split("---", 2)
if len(parts) < 3:
return {}
fm = yaml.safe_load(parts[1]) or {}
return fm if isinstance(fm, dict) else {}
except yaml.YAMLError:
print(f"Warning: Invalid YAML in {file_path}")
return {}

def collect_tags() -> tuple[Set[str], Set[str]]:
all_tags: Set[str] = set()
all_categories: Set[str] = set()

docs_path = Path(DOCS_DIR)
if not docs_path.is_dir():
print(f"Error: Directory not found: {docs_path}")
return all_tags, all_categories

for file_path in docs_path.rglob("*"):
if not file_path.is_file() or not file_path.suffix.lower() in EXTENSIONS:
continue

fm = extract_frontmatter(file_path)

# Handle 'tags'
tags = fm.get("tags", [])
if isinstance(tags, str):
tags = [t.strip() for t in tags.split(",") if t.strip()]
if isinstance(tags, list):
all_tags.update(str(t).strip() for t in tags if t)

# Handle 'categories' (sometimes used instead / in addition)
cats = fm.get("categories", [])
if isinstance(cats, str):
cats = [c.strip() for c in cats.split(",") if c.strip()]
if isinstance(cats, list):
all_categories.update(str(c).strip() for c in cats if c)

all_tags.discard('TAG_ONE')
all_tags.discard('TAG_TWO')
all_categories.discard('CATEGORY_ONE')
all_categories.discard('CATEGORY_TWO')

return all_tags, all_categories


def main():
tags, categories = collect_tags()

print(f"\nExisting categories: {', '.join(sorted(categories))}", )
print(f"\nExisting tags: {', '.join(sorted(tags))}", )


if __name__ == "__main__":
main()


Loading