satelito

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

commit 4c546bbb9ef2c341336bd12b113c60ba017bfb91
parent e1fe5fdf95d2e14fe1e362e74227bf51389dd4aa
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Fri, 14 Jul 2023 16:38:16 -0400

Merge branch 'dev/2023/07/lua-in-html'

Diffstat:
MTODO.md | 2+-
Msatelito/model.lua | 22++++++++++++++++++----
2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -3,4 +3,4 @@ * Set a GPL 3 licence to Satelito. * Add an CLI option to change the base URL on build. * Tags should be lowecase to bypass doublons. -* Add the possibility to put lua in markdown/html files. +* ~~Add the possibility to put lua in markdown/html files.~~ 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