ferron

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

commit 71703c6a2214df069c3f3f5542147efcb6df8a22
parent 250d96be74b56785e9371a03f829dca1f7a1eef5
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sat, 29 Dec 2018 22:47:31 -0500

Refactor the site module

Diffstat:
Mferron/site.lua | 65+++++++++++++++++++++++++++++------------------------------------
1 file changed, 29 insertions(+), 36 deletions(-)

diff --git a/ferron/site.lua b/ferron/site.lua @@ -5,20 +5,14 @@ local fileutils = require "ferron.utilities.file-utils" local site = { location = lfs.currentdir() .. "/" .. config.sites, - paths = { - archetypes = nil , - content = nil, - data = nil, - html = nil, - plugins = nil, - static = nil, - templates = nil, - } + config = nil, + path = nil, + pagestable = {}, } function site.listsites() -- Create a simple array with the directory name of the sites - local sites_list = {} + local siteslist = {} tableutils.each( function(s) @@ -26,38 +20,32 @@ function site.listsites() and s ~= "." and s ~= ".." then - sites_list[#sites_list+1] = s + siteslist[#siteslist+1] = s end end, tableutils.settable(lfs.dir(site.location)) ) - return sites_list + return siteslist end -function site.getsiteinfos(sitename) +function site.getsiteconfig(sitename) package.path = package.path .. ";sites/".. sitename .."/?.lua" - local site_config = require "config" - -- Create a table with the basic infos of the site - local site_infos = { - path = site.location .. sitename, - config = tableutils.extend({}, config, site_config), - pagestable = {}, - } + local siteconfig = require "config" - return site_infos + return siteconfig end function site.setsite(name) - local sites_list = site.listsites() + local siteslist = site.listsites() local whichsite = nil - if #sites_list > 1 and not name then + if #siteslist > 1 and not name then repeat io.write("For which website do you want to proceed? \n") - for k, v in ipairs(sites_list) do + for k, v in ipairs(siteslist) do io.write(k .. ") " .. v .. "\n") end @@ -65,23 +53,28 @@ function site.setsite(name) io.flush() whichsite=io.read() - until (tableutils.haskey(sites_list, tonumber(whichsite))) == true + until (tableutils.haskey(siteslist, tonumber(whichsite))) == true elseif not name then whichsite = 1 end - Ferron.site = site.getsiteinfos((name ~= nil and name or sites_list[tonumber(whichsite)])) - Ferron.site.config.baseurl = (Ferron.devmode == true and Ferron.site.config.urldev or Ferron.site.config.url) + -- Assign values to site.path and site.config + site.path = site.location .. (name ~= nil and name or siteslist[tonumber(whichsite)]) + site.config = tableutils.extend({}, config, site.getsiteconfig((name ~= nil and name or siteslist[tonumber(whichsite)]))) + + -- Have different values if devmode is at trur or not + site.config.baseurl = (Ferron.devmode == true and site.config.urldev or site.config.url) - site.paths.archetypes = Ferron.site.path .. Ferron.site.config.paths.archetypes - site.paths.content = Ferron.site.path .. Ferron.site.config.paths.content - site.paths.data = Ferron.site.path .. Ferron.site.config.paths.data - site.paths.html = Ferron.site.path .. Ferron.site.config.paths.html - site.paths.plugins = Ferron.site.path .. Ferron.site.config.paths.plugins - site.paths.static = Ferron.site.path .. Ferron.site.config.paths.static - site.paths.templates = Ferron.site.path .. Ferron.site.config.paths.templates + -- Create absolute path properties for site's folders + site.archetypes = site.path .. site.config.paths.archetypes + site.content = site.path .. site.config.paths.content + site.data = site.path .. site.config.paths.data + site.html = site.path .. site.config.paths.html + site.plugins = site.path .. site.config.paths.plugins + site.static = site.path .. site.config.paths.static + site.templates = site.path .. site.config.paths.templates - return Ferron.site + return true end function site.makesite() @@ -113,7 +106,7 @@ end -- Reset the `public_html/` folder of the selected site function site.reset() - local publichtml = site.paths.html + local publichtml = site.html local function removefiles(dir) local ok, errormsg -- remove files from directory