From 5a9da62ded70cfb05309aebcb1c1ee09d17948c5 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 1 Apr 2021 12:47:12 +0200 Subject: added scripts for post meta json things --- scripts/meta | 18 ++++++++++++++++++ scripts/postinfo | 20 ++++++++++++++++++++ scripts/posts | 16 ++++++++++++++++ scripts/tags | 4 +++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100755 scripts/meta create mode 100755 scripts/postinfo create mode 100755 scripts/posts 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+\s+\(\K(.+)(?=\)$)" ../posts |\ sed "s/,\s*/\n/g" |\ sort |\ - uniq + uniq |\ + sed -z '$ s/\n$//' |\ + jq --raw-input --slurp 'split("\n")' -- cgit v1.2.3