From dbaf7e963c3f5af2582b8e3936e83b8e373e7fd4 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Sat, 26 Mar 2022 09:05:25 +0100 Subject: [PATCH] Split templates into templates and pages --- build.lua | 12 ++++++++++-- pages/Tupfile | 1 + pages/index.skooma.yue | 9 +++++++++ templates/index.skooma.yue | 6 ------ 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 pages/Tupfile create mode 100644 pages/index.skooma.yue delete mode 100644 templates/index.skooma.yue diff --git a/build.lua b/build.lua index 7a23d8f..af61be8 100644 --- a/build.lua +++ b/build.lua @@ -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) diff --git a/pages/Tupfile b/pages/Tupfile new file mode 100644 index 0000000..f0fe651 --- /dev/null +++ b/pages/Tupfile @@ -0,0 +1 @@ +include_rules diff --git a/pages/index.skooma.yue b/pages/index.skooma.yue new file mode 100644 index 0000000..9daa59e --- /dev/null +++ b/pages/index.skooma.yue @@ -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}`)" +} diff --git a/templates/index.skooma.yue b/templates/index.skooma.yue deleted file mode 100644 index c91191e..0000000 --- a/templates/index.skooma.yue +++ /dev/null @@ -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"