~ryanford/git-blog-tup

09b2c85e1733a8fae84e5d705fb19b890b2b6cd9 — Ryan Ford 1 year, 3 months ago 7455a88 master
add get_tags plugin
2 files changed, 25 insertions(+), 0 deletions(-)

M Tuprules.tup
A plugins/get_tags
M Tuprules.tup => Tuprules.tup +1 -0
@@ 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

A plugins/get_tags => plugins/get_tags +24 -0
@@ 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)