From 88a1c38a41e85a91aed94eec5ad1a610f0689dc3 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 6 Jun 2023 00:13:20 +0100 Subject: [PATCH] chore: remove run file --- justfile | 9 ++---- run | 57 ----------------------------------- tools/scripts/create-daily.sh | 36 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 64 deletions(-) delete mode 100755 run create mode 100755 tools/scripts/create-daily.sh diff --git a/justfile b/justfile index bd9bcf57..7c661549 100644 --- a/justfile +++ b/justfile @@ -6,14 +6,9 @@ default: start: nix develop --command yarn astro dev --open -create-daily: +create-daily date title: #!/usr/bin/env bash - date="$(date +%Y-%m-%d)" - filepath="source/_daily_emails" - filename="${date}.md" - - touch "${filepath}/${filename}" - eval "${EDITOR}" "${filepath}/${filename}" + ./tools/scripts/create-daily.sh {{ date }} {{ title }} deploy sha: rm -fr _deploy diff --git a/run b/run deleted file mode 100755 index 72dae772..00000000 --- a/run +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o pipefail - -# Create a new daily email post for the next subsequent date. -# args: -# - date: -# - "next" for the next subsequent date based on the existing files. -# - Any other value, e.g. a date, will be used explicitly. -# - title: The title to use for the post. -function task:daily { - # Find the next post date based on the last post in the directory. - local next_date - if [[ "${1}" == "next" ]]; then - next_date=$(ls -1 src/content/daily-email | tail -n 1 | tr -d '.md' | xargs -I {} date +%Y-%m-%d -d '{} +1 day') - else - next_date="${1}" - fi - - local filepath="src/content/daily-email/${next_date}.md" - - shift 1 - - # Generate the title and slug. - local title="${*}" - local slug - slug=$(echo "${title}" | awk '{print tolower($0)}' | tr ' ' '-') - - # Create the file. - cp -f --no-clobber stub.md "${filepath}" - - local day - local month - local year - 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 -m "daily-email: add ${date}" - - echo "${filepath}" -} - -function task:help { - echo "task:help" -} - -eval "task:${*:-help}" diff --git a/tools/scripts/create-daily.sh b/tools/scripts/create-daily.sh new file mode 100755 index 00000000..e4bc4762 --- /dev/null +++ b/tools/scripts/create-daily.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [ "${1}" == "next" ]; then + next_date=$(ls -1 src/content/daily-email | tail -n 1 | tr -d '.md' | xargs -I {} date +%Y-%m-%d -d '{} +1 day') +else + next_date="${1}" +fi + +filepath="src/content/daily-email/${next_date}.md" + +shift 1 + +# Generate the title and slug. +title="${*}" +slug=$(echo "${title}" | awk '{print tolower($0)}' | tr ' ' '-') + +# 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 -m "daily-email: add ${date}" + +echo "${filepath}"