ferron

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

commit 2c16fe87af9f8a40cd69bb6e2c9bcbc9bf07b075
parent 946824e473124186c8184e773ed1ebf94e59a079
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Thu,  1 Feb 2018 22:41:39 -0500

Optimise the site module.

Diffstat:
Mferron.lua | 2--
Mferron/site.lua | 23+++++++++++++----------
2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/ferron.lua b/ferron.lua @@ -31,8 +31,6 @@ end inspect = require("inspect") Ferron.config = config -Ferron.sites = {} -Ferron.sitesarray = {} Ferron.site = {} Ferron.archetypes = {} Ferron.devmode = (arg[1] == "--dev" and true or false) diff --git a/ferron/site.lua b/ferron/site.lua @@ -1,29 +1,32 @@ local path = require("path") local tableutils = require("ferron.utilities.table-utils") local fileutils = require("ferron.utilities.file-utils") + local site = {} +local sites_tb = {} +local sites_list = {} function site.getsites() -- Create a table with the content of `Ferron.config.paths.sites` - for site in path.each(Ferron.config.paths.sites .. "/*", "f", {delay = true; reverse = true;}) do - if path.isdir(site) then + for s in path.each(Ferron.config.paths.sites .. "/*", "f", {delay = true; reverse = true;}) do + if path.isdir(s) then -- Load site configuration - local siteconfig, siteconfig_err = fileutils.loadlocalconfig(site .. "/site.config.lua") + local siteconfig, siteconfig_err = fileutils.loadlocalconfig(s .. "/site.config.lua") -- Create a table with the basic infos of the site - Ferron.sites[site:match("^.+/(.+)$")] = { - path = site, + sites_tb[s:match("^.+/(.+)$")] = { + path = s, config = siteconfig, pagestable = {} } -- Create a simple array with the name of the sites - Ferron.sitesarray[#Ferron.sitesarray+1] = site:match("^.+/(.+)$") + sites_list[#sites_list+1] = s:match("^.+/(.+)$") end end - return Ferron.sites, Ferron.sitesarray + return sites_tb, sites_list end function site.setsite() @@ -33,7 +36,7 @@ function site.setsite() repeat io.write("Welcome to Ferron! Which site do you want to build? \n") - for k, v in ipairs(Ferron.sitesarray) do + for k, v in ipairs(sites_list) do io.write(k .. ") " .. v .. "\n") end @@ -41,9 +44,9 @@ function site.setsite() io.flush() answer=io.read() - until (tableutils.haskey(Ferron.sitesarray, tonumber(answer))) == true + until (tableutils.haskey(sites_list, tonumber(answer))) == true - Ferron.site = Ferron.sites[Ferron.sitesarray[tonumber(answer)]] + Ferron.site = sites_tb[sites_list[tonumber(answer)]] Ferron.site.config.SITE.BASEURL = (Ferron.devmode == true and Ferron.site.config.SITE.URLDEV or Ferron.site.config.SITE.URL) Ferron.site.config.SITE.PREFETCHLIST = {}