← Back to all posts

Sunday Updates


First, little correction from the last post - Jason (Sam’s Show Host character) said Jin is a glob as in his personality. I was tired, and writing while really trying to watch the show is harder than I thought it’d be.


I also had Claude make me a little zsh script this morning while I watched the fish.

#!/usr/bin/env zsh

# Blog directory
BLOG_DIR="$HOME/Docs/Blog/mustardfizz.com/src/content/blog"

# Prompt for title
echo -n "Enter blog post title: "
read title

# Slugify the title
slugified=$(echo "$title" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/-\+/-/g' | sed 's/^-//' | sed 's/-$//')

# Get current date
date_prefix=$(date +%Y-%m-%d)

# Create directory name
dir_name="${date_prefix}-${slugified}"
full_path="${BLOG_DIR}/${dir_name}"

# Find all categories from existing posts
categories=()
# Search .md files
for file in $BLOG_DIR/*.md; do
    if [[ -f "$file" ]]; then
        category=$(grep -E "^category:" "$file" | sed 's/category:[[:space:]]*//' | tr -d "'\"")
        if [[ -n "$category" ]]; then
            categories+=("$category")
        fi
    fi
done
# Search index.mdx files
for file in $BLOG_DIR/*/index.mdx; do
    if [[ -f "$file" ]]; then
        category=$(grep -E "^category:" "$file" | sed 's/category:[[:space:]]*//' | tr -d "'\"")
        if [[ -n "$category" ]]; then
            categories+=("$category")
        fi
    fi
done

# Remove duplicates while preserving order
unique_categories=()
for cat in "${categories[@]}"; do
    if [[ ! " ${unique_categories[@]} " =~ " ${cat} " ]]; then
        unique_categories+=("$cat")
    fi
done

# Present category menu
echo "\nSelect a category:"
count=1
for cat in "${unique_categories[@]}"; do
    echo "$count) $cat"
    ((count++))
done
echo "$count) [New Category]"

# Get category selection
echo -n "\nEnter selection: "
read selection

# Determine category
if [[ "$selection" -le "${#unique_categories[@]}" ]]; then
    category="${unique_categories[$selection]}"
else
    echo -n "Enter new category: "
    read category
fi

# Create directory
mkdir -p "$full_path"

# Get current timestamp
timestamp=$(date +%Y-%m-%dT%H:%M:%S)

# Create index.mdx
cat > "${full_path}/index.mdx" << EOF
---
title: '${title}'
date: ${timestamp}
draft: true
description: '[Placeholder]'
category: '${category}'
---
EOF

# Open in neovim
nvim "${full_path}/index.mdx"

It’s nothing special. I just wanted to make getting a blog together even easier.

The script prompts for a title, finds used categories and offers selection/creation, sets up the front matter with the current date/time, sets up the dir/file and opens the mdx in neovim.