Split templates into templates and pages

This commit is contained in:
Talia 2022-03-26 09:05:25 +01:00
parent 13121e0481
commit dbaf7e963c
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E
4 changed files with 20 additions and 8 deletions

View file

@ -39,6 +39,11 @@ local templates = restia.config.bind('templates', {
})
package.loaded.templates = templates
local pages = restia.config.bind('pages', {
(require 'restia.config.skooma');
})
package.loaded.pages = pages
-- General purpose utility functions
local function split(str, pattern)
@ -117,6 +122,9 @@ end)
local function render(name, ...)
return templates.main(templates[name], ...)
end
local function page(name, ...)
return templates.main(pages[name], ...)
end
-- Render Posts
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)
end
tree["index.html"] = render("index", posts)
if params.delete then
restia.utils.delete(params.output)
end
@ -151,4 +157,6 @@ tree["posts.json"] = json.encode(
:totable()
)
tree["index.html"] = page("index", posts, tree["posts.json"])
restia.utils.builddir(params.output, tree)

1
pages/Tupfile Normal file
View file

@ -0,0 +1 @@
include_rules

9
pages/index.skooma.yue Normal file
View 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}`)"
}

View file

@ -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"