ferron

Ferron is a fast and simple static website generator made with Lua.
Log | Files | Refs | Submodules | README | LICENSE

commit acb54929f19f29a9cd25be6a7a951c57905a88e3
parent e51c2647f6e0e193e1c71ca0a8e9541d0108e3eb
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Mon, 27 Apr 2020 10:41:04 -0400

Move the template path funciton

Diffstat:
Mferron/page.lua | 6+++++-
Mferron/utilities/file-utils.lua | 8--------
Mferron/utilities/template-utils.lua | 9+++++++++
3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/ferron/page.lua b/ferron/page.lua @@ -158,13 +158,17 @@ function page.makepages(sitedata) function(p) local lastbuild = lfs.currentdir() .. '/lastbuild' + -- If there's a lastbuild file + -- Check for modifications if fl.isFile(lastbuild) then local lastbuildmod = lfs.attributes(lfs.currentdir() .. '/lastbuild').modification local pagemod = lfs.attributes(p).modification local pageconfmod = (lfs.attributes(fl.removeextension(p) .. '.json') or lfs.attributes(fl.removeextension(p) .. '.lua')).modification - local templatemod = lfs.attributes(fl.gettemplatefile(p, sitedata)).modification + local templatemod = lfs.attributes(tp.gettemplatepath(p, sitedata)).modification + -- Add a configmod too + -- Render if a page or a page conf or a template is modified if pagemod > lastbuildmod or pageconfmod > lastbuildmod or templatemod > lastbuildmod diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua @@ -260,14 +260,6 @@ function fileutils.getpageconf(pagepath) return pageconf end --- get template file -function fileutils.gettemplatefile(pagepath, sitedata) - local dir = lfs.currentdir() .. '/' .. sitedata.templates - local name = (fileutils.getpageconf(pagepath).template or 'default') - - return dir .. '/' .. name .. '.mustache' -end - function fileutils.shorturlencode(num) local alphabet = '23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ_' local base = alphabet:len() diff --git a/ferron/utilities/template-utils.lua b/ferron/utilities/template-utils.lua @@ -6,6 +6,7 @@ local templateutilsmeta = { end } +local lfs = require 'lfs' local lustache = require 'lustache' local site = require 'ferron.site' local fl = require 'ferron.utilities.file-utils' @@ -53,4 +54,12 @@ function templateutils.rendertemplate(template, data) return render end +-- get template path +function templateutils.gettemplatepath(pagepath, sitedata) + local dir = lfs.currentdir() .. '/' .. sitedata.templates + local name = (fl.getpageconf(pagepath).template or 'default') + + return fl.isFile(dir .. '/' .. name .. '.mustache') +end + return setmetatable(templateutils, templateutilsmeta)