Split templates into templates and pages
This commit is contained in:
parent
13121e0481
commit
dbaf7e963c
4 changed files with 20 additions and 8 deletions
12
build.lua
12
build.lua
|
@ -39,6 +39,11 @@ local templates = restia.config.bind('templates', {
|
||||||
})
|
})
|
||||||
package.loaded.templates = templates
|
package.loaded.templates = templates
|
||||||
|
|
||||||
|
local pages = restia.config.bind('pages', {
|
||||||
|
(require 'restia.config.skooma');
|
||||||
|
})
|
||||||
|
package.loaded.pages = pages
|
||||||
|
|
||||||
-- General purpose utility functions
|
-- General purpose utility functions
|
||||||
|
|
||||||
local function split(str, pattern)
|
local function split(str, pattern)
|
||||||
|
@ -117,6 +122,9 @@ end)
|
||||||
local function render(name, ...)
|
local function render(name, ...)
|
||||||
return templates.main(templates[name], ...)
|
return templates.main(templates[name], ...)
|
||||||
end
|
end
|
||||||
|
local function page(name, ...)
|
||||||
|
return templates.main(pages[name], ...)
|
||||||
|
end
|
||||||
|
|
||||||
-- Render Posts
|
-- Render Posts
|
||||||
for idx, post in ipairs(posts) do
|
for idx, post in ipairs(posts) do
|
||||||
|
@ -125,8 +133,6 @@ for idx, post in ipairs(posts) do
|
||||||
restia.utils.deepinsert(tree, post.path, body)
|
restia.utils.deepinsert(tree, post.path, body)
|
||||||
end
|
end
|
||||||
|
|
||||||
tree["index.html"] = render("index", posts)
|
|
||||||
|
|
||||||
if params.delete then
|
if params.delete then
|
||||||
restia.utils.delete(params.output)
|
restia.utils.delete(params.output)
|
||||||
end
|
end
|
||||||
|
@ -151,4 +157,6 @@ tree["posts.json"] = json.encode(
|
||||||
:totable()
|
:totable()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tree["index.html"] = page("index", posts, tree["posts.json"])
|
||||||
|
|
||||||
restia.utils.builddir(params.output, tree)
|
restia.utils.builddir(params.output, tree)
|
||||||
|
|
1
pages/Tupfile
Normal file
1
pages/Tupfile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
include_rules
|
9
pages/index.skooma.yue
Normal file
9
pages/index.skooma.yue
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import output from require 'params'
|
||||||
|
|
||||||
|
link = =>
|
||||||
|
a @title, href: "/"..output..@uri
|
||||||
|
|
||||||
|
(json) => (ul [li link post.head, prefix for post in *@]), {
|
||||||
|
title "Index"
|
||||||
|
script "window.posts = JSON.parse(`#{json}`)"
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
import output from require 'params'
|
|
||||||
|
|
||||||
link = =>
|
|
||||||
a @title, href: "/"..output..@uri
|
|
||||||
|
|
||||||
(prefix) => ul [li link post.head, prefix for post in *@], title "Index"
|
|
Loading…
Reference in a new issue