~kris/dots

srice

ref: 178c9a25a484ead715392d50e21d03df486b8b41 srice/.local/bin/blog-new -rwxr-xr-x 638 bytes
178c9a25 — Kris Yotam conky: sync proper config from moirai (was the greenred variant) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env sh
set -eu

if [ "$#" -lt 1 ]; then
  printf 'usage: blog-new "Title" [directory]\n' >&2
  exit 2
fi

title=$1
dir=${2:-content/drafts}
date=$(date +%F)
slug=$(printf '%s' "$title" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9]/-/g' -e 's/-\{2,\}/-/g' -e 's/^-//' -e 's/-$//')
file="$dir/$date-$slug.md"

mkdir -p "$dir"
if [ -e "$file" ]; then
  printf 'exists: %s\n' "$file" >&2
  exit 1
fi

{
  printf '%s\n' '---'
  printf 'title: "%s"\n' "$title"
  printf 'date: %s\n' "$date"
  printf 'status: draft\n'
  printf 'tags: []\n'
  printf '%s\n\n' '---'
  printf '# %s\n\n' "$title"
} > "$file"

printf '%s\n' "$file"