blob: 4028f14df6a2db1f47d30cd3dee9e5052a485164 (
plain) (
blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/bin/sh
set -e
find_next_id() {
last_id=$(fd -td '\d+' content/ -x echo '{/}' | sort -nr | head -n1)
printf '%d\n' $((last_id + 1))
}
print_front_matter() {
cat <<-EOF
+++
title = ""
[taxonomies]
tags = []
[extra]
related = []
+++
EOF
}
add_date() {
sed -i "1a date = $(date -Iseconds)" "$1"
}
cleanup() {
rm -f "$tmpfile"
exit 1
}
tmpfile=$(mktemp --suffix=.md)
trap "{ rm -f $tmpfile; }" EXIT
print_front_matter > "$tmpfile"
$EDITOR "$tmpfile"
add_date "$tmpfile"
dir="content/$(find_next_id)"
mkdir "$dir/"
cp "$tmpfile" "$dir/index.md"
|