aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-04-01 12:47:12 +0200
committerlonkaars <l.leblansch@gmail.com>2021-04-01 12:47:12 +0200
commit5a9da62ded70cfb05309aebcb1c1ee09d17948c5 (patch)
tree0ddbdff0a75279bd6d4dae48fe83510cb5e32108 /scripts
parent71ab18ec4264197aae27efe64e4565c4989a19cd (diff)
added scripts for post meta json things
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/meta18
-rwxr-xr-xscripts/postinfo20
-rwxr-xr-xscripts/posts16
-rwxr-xr-xscripts/tags4
4 files changed, 57 insertions, 1 deletions
diff --git a/scripts/meta b/scripts/meta
new file mode 100755
index 0000000..f33ea3d
--- /dev/null
+++ b/scripts/meta
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+tag_name=$1
+filename=$2
+
+output=$(grep -Poh "^\[meta\]:\s+<$tag_name>\s+\(\K(.+)(?=\)$)" $filename)
+
+if [[ $tag_name = "tags" ]]; then
+ echo $output |\
+ sed "s/,\s*/\n/g" |\
+ sed -z '$ s/\n$//' |\
+ jq --raw-input --slurp 'split("\n")'
+else
+ echo $output |\
+ sed -z '$ s/\n$//' |\
+ jq --raw-input
+fi
+
diff --git a/scripts/postinfo b/scripts/postinfo
new file mode 100755
index 0000000..94827f1
--- /dev/null
+++ b/scripts/postinfo
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+filename=$1
+
+jq -n \
+ --argjson title "$(./meta title $filename)" \
+ --argjson subtitle "$(./meta subtitle $filename)" \
+ --argjson author "$(./meta author $filename)" \
+ --argjson date "$(./meta date $filename)" \
+ --argjson tags "$(./meta tags $filename)" \
+ --argjson urlname "$(basename $filename .md | jq --raw-input)" \
+'{
+ "title": $title,
+ "subtitle": $subtitle,
+ "author": $author,
+ "date": $date,
+ "tags": $tags,
+ "urlname": $urlname
+}'
+
diff --git a/scripts/posts b/scripts/posts
new file mode 100755
index 0000000..12900e1
--- /dev/null
+++ b/scripts/posts
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+postsmeta=$( find ../posts \
+ -name "*.md" \
+ -type f \
+ -exec ./postinfo {} \; |\
+ jq -s '.')
+
+jq -n \
+ --argjson valid_tags "$(./tags)" \
+ --argjson posts "$postsmeta" \
+'{
+ "valid_tags": $valid_tags,
+ "posts": $posts
+}'
+
diff --git a/scripts/tags b/scripts/tags
index 3b9272c..c0e784b 100755
--- a/scripts/tags
+++ b/scripts/tags
@@ -4,5 +4,7 @@ grep -Proh \
"^\[meta\]:\s+<tags>\s+\(\K(.+)(?=\)$)" ../posts |\
sed "s/,\s*/\n/g" |\
sort |\
- uniq
+ uniq |\
+ sed -z '$ s/\n$//' |\
+ jq --raw-input --slurp 'split("\n")'