satelito

Static [web] site (or page) generator (ssg) made with Lua script.
git clone git://soucy.cc/satelito.git
Log | Files | Refs | README

commit 264b389c80ade69662618c46b5cb61e8e692e4b2
parent 7c2c386932bff9426ff8d578401b5803e867932c
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Wed,  9 Feb 2022 08:27:53 -0500

Add an include function to inject partial templates

Diffstat:
Msatelito/model.lua | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/satelito/model.lua b/satelito/model.lua @@ -1,16 +1,19 @@ -- @module model local model = {} -- +local etlua = require 'etlua' local lfs = require 'lfs' -- luafilesystem local lume = require 'satelito.lib.lume.lume' local dirtree = require 'satelito.dirtree' local file = require 'satelito.file' local list = require 'satelito.list' local markdown = require 'discount' -- lua-discount +local template = require 'satelito.template' function model.set(filepath, config, contentdir) local pagemeta = file.get_metafile(filepath) or {} local time_created + local templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates)) -- If required properties are nil pagemeta.title = pagemeta.title or file.get_basename(filepath):match('(.+)%..*') @@ -50,7 +53,7 @@ function model.set(filepath, config, contentdir) -- Archives if pagemeta.archives then - pagemeta.archives_children = list.get_archives(contentdir) + pagemeta.archives_children = list.get_archives(contentdir) end -- Tags @@ -69,6 +72,14 @@ function model.set(filepath, config, contentdir) pagemeta.footer = pagemeta.footer or 'footer' pagemeta.feed = pagemeta.feed or 'feed.xml' + pagemeta.include = function(templatename) + -- Include a partial template and compile it + -- @usage <%- include("test-partial") %> + local inc = etlua.compile(file.read(template.find(templates, templatename))) + + return inc(pagemeta) + end + return lume.extend({}, config, pagemeta) end