Add post metadata JSON file
This commit is contained in:
parent
1a3a8088db
commit
e4b971c8ad
1 changed files with 37 additions and 1 deletions
38
build.lua
38
build.lua
|
@ -1,8 +1,10 @@
|
|||
local arrr = require 'arrr'
|
||||
local cmark = require 'cmark'
|
||||
local fun = require 'fun'
|
||||
local json = require 'cjson'
|
||||
local restia = require 'restia'
|
||||
local shapeshift = require 'shapeshift'
|
||||
local yaml = require 'lyaml'
|
||||
local cmark = require 'cmark'
|
||||
|
||||
local params do
|
||||
local is = shapeshift.is
|
||||
|
@ -37,6 +39,16 @@ local templates = restia.config.bind('templates', {
|
|||
})
|
||||
package.loaded.templates = templates
|
||||
|
||||
-- General purpose utility functions
|
||||
|
||||
local function split(str, pattern)
|
||||
local result = {}
|
||||
for item in str:gmatch(pattern) do
|
||||
table.insert(result, item)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function read_post(file)
|
||||
local content = io.open(file):read("*a")
|
||||
local head, body = restia.utils.frontmatter(content)
|
||||
|
@ -83,6 +95,10 @@ for file in restia.utils.files(params.input, "%.md$") do
|
|||
|
||||
post.head.timestamp = parsedate(post.head.date)
|
||||
|
||||
if "string" == type(post.head.tags) then
|
||||
post.head.tags = split(post.head.tags, "%a+")
|
||||
end
|
||||
|
||||
post.head.slug = post.head.title
|
||||
:gsub(' ', '_')
|
||||
:lower()
|
||||
|
@ -115,4 +131,24 @@ if params.delete then
|
|||
restia.utils.delete(params.output)
|
||||
end
|
||||
|
||||
local function transform(tab)
|
||||
return function(data)
|
||||
local success, result = shapeshift.table(tab, "keep")(data)
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
local function drop() return true, nil end
|
||||
|
||||
-- Generate Post Metadata
|
||||
tree["posts.json"] = json.encode(
|
||||
fun
|
||||
.iter(posts)
|
||||
:map(transform {
|
||||
body = drop;
|
||||
head = shapeshift.table({ file = drop }, 'keep');
|
||||
})
|
||||
:totable()
|
||||
)
|
||||
|
||||
restia.utils.builddir(params.output, tree)
|
||||
|
|
Loading…
Reference in a new issue