Files
website/hugo.sh
T
2026-03-24 21:41:09 -07:00

48 lines
1.1 KiB
Bash

#!/bin/bash
set -e
# Usage: ./hugo-new.sh "<title>" [md|rmd]
TITLE="$2"
EXTENSION="${1:-rmd}" # default to Rmd if not specified
# Validate extension
if [[ "$EXTENSION" != "md" && "$EXTENSION" != "rmd" ]]; then
echo "⚠️ Usage: ./hugo-new.sh \"Post Title\" [md|rmd]"
exit 1
fi
DATE=$(date '+%Y-%m-%d')
SLUG=$(echo "$TITLE" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
POST_DIR="content/posts/${DATE}-${SLUG}"
# Create new post using Hugo archetype
if [ "$EXTENSION" == "rmd" ]; then
POST_FILE="index.Rmd"
else
POST_DIR="content/posts/${DATE}-${SLUG}"
EXTENSION="md"
fi
hugo new "posts/${DATE}-${SLUG}/index.${EXTENSION}"
# Change to post directory
cd "$POST_DIR"
# Set up .gitignore and renv (for R Markdown)
if [ "$EXTENSION" == "rmd" ]; then
# Ignore generated Markdown file
echo "index.md" > .gitignore
# Set up minimal renv environment from base snapshot
cp ../../../../scripts/base-renv.lock ./renv.lock
Rscript -e '
if (!require("renv")) install.packages("renv");
renv::init(bare = TRUE);
renv::restore();
'
fi
echo "✅ Created post at ${POST_DIR}/index.${EXTENSION}"