summaryrefslogtreecommitdiffstatshomepage
path: root/post.sh
diff options
context:
space:
mode:
authorWolfgang Müller2021-06-12 14:21:59 +0200
committerWolfgang Müller2021-06-12 14:21:59 +0200
commitad2be2b20c337d99ebe6e7d4b8cf6106cfba77df (patch)
tree65c0ddbb7828fd5b174eb531739097f83a3f17ee /post.sh
downloadzunzuncito-ad2be2b20c337d99ebe6e7d4b8cf6106cfba77df.tar.gz
Initial commit
Diffstat (limited to 'post.sh')
-rw-r--r--post.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/post.sh b/post.sh
new file mode 100644
index 0000000..17ad94d
--- /dev/null
+++ b/post.sh
@@ -0,0 +1,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]
+ mentions = []
+ +++
+ 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"