satelito

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit d96161d269f3a34b70a5fb523ffc0a82412c7cc2
parent 13dd3b0a80a9c2e8f8e450af6bac372d15c258ff
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Mon,  3 Jul 2023 20:05:34 -0400

Set the markdown or HTML to compile lua code in it before the page build

Diffstat:
Msatelito/model.lua | 22++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/satelito/model.lua b/satelito/model.lua @@ -8,6 +8,7 @@ local dirtree = require 'satelito.dirtree' local file = require 'satelito.file' local markdown = require 'discount' -- lua-discount local template = require 'satelito.template' +local inspect = require 'inspect' function model.set(filepath) local pagedata = file.get_metafile(filepath) or {} @@ -47,10 +48,23 @@ function model.set(filepath) pagedata.idorder = pagedata.rellinkdir .. time_created -- HTML content - if file.is_markdown(filepath) then - pagedata.content = markdown(file.read(filepath)) - elseif file.is_html(filepath) then - pagedata.content = file.read(filepath) + if file.is_content(filepath) then + local that_content + + -- Lua compilation (with etlua) is needed in content + if pagedata.lua then + local lua_in_content = etlua.compile(file.read(filepath)) + + that_content = lua_in_content(lume.extend({}, config, pagedata)) + else + that_content = file.read(filepath) + end + + if file.is_markdown(filepath) then + pagedata.content = markdown(that_content) + elseif file.is_html(filepath) then + pagedata.content = that_content + end end -- Summary