oliverdavies.uk/run

106 lines
2.2 KiB
Plaintext
Raw Normal View History

2024-01-03 20:00:00 +00:00
#!/usr/bin/env bash
set -o nounset
set -o pipefail
function clean {
rm -fr output_*/ source/build/
2024-01-03 20:00:00 +00:00
}
2024-01-03 20:00:00 +00:00
# Create a new daily email.
function create-daily {
local date="${1}"
local title="${2}"
if [ "${date}" == "next" ]; then
next_date=$(ls -1 source/_daily_emails | tail -n 1 | tr -d '.md' | xargs -I {} date +%Y-%m-%d -d '{} +1 day')
else
next_date="${date}"
fi
filepath="source/_daily_emails/${next_date}.md"
shift 1
# Generate the title and slug.
title="${*}"
slug=$(echo "${title}" | \
tr '[:upper:]' '[:lower:]' | \
sed 's/[^a-z0-9]/-/g' | \
sed 's/\-\-+/-/g' | \
sed 's/^\-//;s/\-$//')
# Create the file.
cp -f --no-clobber stub.md "${filepath}"
date=$(date -d "${next_date}" +%Y-%m-%d)
day=$(date -d "${next_date}" +%d)
month=$(date -d "${next_date}" +%m)
year=$(date -d "${next_date}" +%Y)
# Replace the placeholders.
sed -i "s/{{ date }}/${date}/" "${filepath}"
sed -i "s/{{ title }}/${title}/" "${filepath}"
sed -i "s#{{ permalink }}#archive/${year}/${month}/${day}/${slug}#" "${filepath}"
# Create a commit with the appropriate date in the message
git add "${filepath}"
git commit --quiet -m "Add daily email for ${date}
${title}"
echo "${filepath}"
}
2024-01-03 20:00:00 +00:00
function generate {
local args=()
if [[ "${APP_ENV:-}" == "production" ]]; then
args=(--env="prod")
else
args=(--server --watch)
fi
sculpin generate "${args[@]}"
}
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
2024-01-03 20:00:00 +00:00
function npm:build:css {
local args=()
if [[ "${NODE_ENV:-}" == "production" ]]; then
args=(--minify)
else
args=(--watch)
fi
2024-01-03 20:00:00 +00:00
npx tailwindcss \
--config assets/tailwind.config.ts \
2024-01-03 20:00:00 +00:00
--output source/build/tailwind.css "${args[@]}"
}
function publish {
export NODE_ENV=production
export APP_ENV=production
git stash
clean
npm:build:css
generate
rsync --archive --verbose --compress --update --delete \
output_prod/ ssh.oliverdavies.uk:/srv/oliverdavies.uk-sculpin
git stash pop
}
2024-01-03 20:00:00 +00:00
TIMEFORMAT="Task completed in %3lR"
time "${@:-help}"