ferron

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

commit 1b0dc87e3a87447f7a1aac7102f149b7a0317778
parent 8e6c64651b21bc2d82d3bc1a3e88d6160e81666f
Author: Hugo Soucy <hs0ucy@h50ucy.local>
Date:   Wed, 19 Jun 2019 22:12:40 -0400

Try to simplify the site module

Diffstat:
Mferron/site.lua | 33+++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/ferron/site.lua b/ferron/site.lua @@ -30,27 +30,40 @@ function site.getsitelist(siteslocation) return siteslist end +function site.isSite(sitename) + if tableutils.hasvalue(site.getsitelist(), sitename) then + return sitename + end + + return false +end + function site.getsiteconfig(sitename) package.path = package.path .. ';sites/'.. sitename ..'/?.lua' return require 'config' end -function site.isSite(sitename) - if tableutils.hasvalue(site.getsitelist(), sitename) then - print(sitename) - return sitename - end +function site.setsiteconfig(sitename) + local thatSite = assert(site.isSite(sitename), "That is not a valid site") - return false + Ferron.site.config = tableutils.extend({}, config, site.getsiteconfig(thatSite)) + + return Ferron.site.config +end + +function site.setsitepath(sitename) + local thatSite = assert(site.isSite(sitename), "That is not a valid site") + + Ferron.site.path = Ferron.site.location .. thatSite + + return Ferron.site.path end function site.setsite(sitename) local siteslist = site.getsitelist() local whichsite - print((site.isSite(sitename) or siteslist[tonumber(whichsite)])) - if #siteslist > 1 and not sitename then repeat io.write('For which website do you want to proceed? \n') @@ -69,8 +82,8 @@ function site.setsite(sitename) end -- Assign values to Ferron.site.path and Ferron.site.config - Ferron.site.path = Ferron.site.location .. (site.isSite(sitename) or siteslist[tonumber(whichsite)]) - Ferron.site.config = tableutils.extend({}, config, (site.getsiteconfig(site.isSite(sitename) or siteslist[tonumber(whichsite)]))) + site.setsitepath(sitename and sitename or siteslist[tonumber(whichsite)]) + site.setsiteconfig((sitename and sitename or siteslist[tonumber(whichsite)])) -- Have different values if devmode is at true or not Ferron.site.config.baseurl = (Ferron.devmode == true and Ferron.site.config.urldev or Ferron.site.config.url)