From 09b2c85e1733a8fae84e5d705fb19b890b2b6cd9 Mon Sep 17 00:00:00 2001 From: Ryan Ford Date: Mon, 19 Apr 2021 19:07:07 +0800 Subject: [PATCH] add get_tags plugin --- Tuprules.tup | 1 + plugins/get_tags | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 plugins/get_tags diff --git a/Tuprules.tup b/Tuprules.tup index b62af66..44c2aab 100644 --- a/Tuprules.tup +++ b/Tuprules.tup @@ -7,6 +7,7 @@ TMP = $(ROOT)/tmp # plugins to use (in order) PIPELINE = to_json +PIPELINE += get_tags PIPELINE += syntax_highlighting PIPELINE += convert_markdown PIPELINE += to_html diff --git a/plugins/get_tags b/plugins/get_tags new file mode 100755 index 0000000..5a0721b --- /dev/null +++ b/plugins/get_tags @@ -0,0 +1,24 @@ +#!/usr/bin/env lua +local json = require("dkjson") + +local input = io.input(arg[1]) +local output = io.output(arg[2]) + +local str = input:read("*a") +if arg[1] then input:close() end +local post = assert(json.decode(str)) + +post.tags = {} +local tagline = post.body:match("%[%w*tags%w*%]: .*") +if tagline then + for tag in tagline:gmatch("#([^%s,]+)") do + table.insert(tags, tag) + end +end + +local post_json = json.encode(post) + +output:write(post_json) +if arg[2] then output:close() end + +os.exit(0, true) -- 2.45.2