ferron

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

commit 8f1392fb07e0a6129e374405e19968734fa99a97
parent bfc05da3bcab86653812d7011b6afde893d64bd5
Author: Hugo Soucy <hs0ucy@users.noreply.github.com>
Date:   Sat, 18 Aug 2018 10:20:39 -0400

Merge pull request #1 from hs0ucy/test

Test
Diffstat:
Mconfig.lua | 4++--
Mferron/content.lua | 4+---
Mferron/site.lua | 152++++++++++++++++++++++++++++++++++---------------------------------------------
Mferron/utilities/file-utils.lua | 3+--
4 files changed, 69 insertions(+), 94 deletions(-)

diff --git a/config.lua b/config.lua @@ -13,8 +13,8 @@ local config = { }, paths = { - functions = "./functions", - sites = "./sites" + functions = "functions/", + sites = "sites/" }, -- Ferron Dependencies diff --git a/ferron/content.lua b/ferron/content.lua @@ -102,9 +102,7 @@ function content.makecontent(contenttype, contenttitle) print("¤¤ The files `" .. contentpath .. "{" .. archetype.filename .. ".md," .. archetype.filename .. ".json}` have been created. ¤¤") else print("! Error, something went wrong !") - end - - os.exit() + end end end diff --git a/ferron/site.lua b/ferron/site.lua @@ -5,111 +5,89 @@ local fileutils = require "ferron.utilities.file-utils" local site = {} -function site.listsites() - -- Create a simple array with the directory name of the sites - local sites_arr = {} +Ferron.sites = path.currentdir() .. "/" .. config.paths.sites - for s in path.each(config.paths.sites .. "/*", "f", {delay = true; reverse = true;}) do - if path.isdir(s) then - sites_arr[#sites_arr+1] = s:match("^.+/(.+)$") - end - end +function site.listsites() + -- Create a simple array with the directory name of the sites + local sites_list = {} - print(inspect(sites_arr)) + for s in path.each(Ferron.sites .. "*", "f", {delay = true; reverse = true;}) do + if path.isdir(s) then + sites_list[#sites_list+1] = s:match("^.+/(.+)$") + end + end - return sites_arr + return sites_list end function site.getsiteinfos(sitename) - local site = config.paths.sites .. "/" .. sitename - local site_config, site_err = fileutils.loadlocalconfig(site .. "/site-config.lua") - local site_infos = {} - - -- Create a table with the basic infos of the site - site_infos = { - path = site, - siteconfig = site_config["siteconfig"], - pagestable = {}, - } - - return site_infos -end - -function site.getsites() - local sites_tb = {} - local sites_arr = {} - - -- Create a table with the content of `config.paths.sites` - for s in path.each(config.paths.sites .. "/*", "f", {delay = true; reverse = true;}) do - if path.isdir(s) then - -- Load site configuration - local s_config, s_config_err = fileutils.loadlocalconfig(s .. "/site-config.lua") - - -- Create a table with the basic infos of the site - sites_tb[s:match("^.+/(.+)$")] = { - path = s, - siteconfig = s_config["siteconfig"], - pagestable = {}, - } - - -- Create a simple array with the name of the sites - sites_arr[#sites_arr+1] = s:match("^.+/(.+)$") - end - end - - return sites_tb, sites_arr + package.path = package.path .. ";sites/".. sitename .."/?.lua" + + local site = Ferron.sites .. sitename + local site_config = require "site-config" + local site_infos = {} + + -- Create a table with the basic infos of the site + site_infos = { + path = site, + siteconfig = site_config, + pagestable = {}, + } + + return site_infos end function site.setsite() - local sites_tb, sites_arr = site.getsites() - -- Site chooser: Which site do you want to build? - local whichsite = nil - - repeat - io.write("For which website do you want to proceed? \n") + local sites_list = site.listsites() + -- Site chooser: Which site do you want to build? + local whichsite = nil - for k, v in ipairs(sites_arr) do - io.write(k .. ") " .. v .. "\n") - end + repeat + io.write("For which website do you want to proceed? \n") - io.write("Please enter the number... \n") - io.flush() + for k, v in ipairs(sites_list) do + io.write(k .. ") " .. v .. "\n") + end - whichsite=io.read() - until (tableutils.haskey(sites_arr, tonumber(whichsite))) == true + io.write("Please enter the number... \n") + io.flush() - site.getsiteinfos("hugosoucycc") + whichsite=io.read() + until (tableutils.haskey(sites_list, tonumber(whichsite))) == true - Ferron.site = sites_tb[sites_arr[tonumber(whichsite)]] - Ferron.site.siteconfig.baseurl = (Ferron.devmode == true and Ferron.site.siteconfig.urldev or Ferron.site.siteconfig.url) - Ferron.site.siteconfig.prefetchlist = {} + Ferron.site = site.getsiteinfos(sites_list[tonumber(whichsite)]) + Ferron.site.siteconfig.baseurl = (Ferron.devmode == true and Ferron.site.siteconfig.urldev or Ferron.site.siteconfig.url) + Ferron.site.siteconfig.prefetchlist = {} - return Ferron.site + return Ferron.site end function site.makesite() - local newsite = { - domain = nil, - name = nil, - location = nil, - config = nil, - sample = config.paths.sites .. "/ferron-ssg.tld", - } - - io.write("How do you want names your new website? \n") - io.write("Please enter that name below... \n") - io.flush() - - newsite.name = io.read() - newsite.location = config.paths.sites .. "/" .. newsite.name - - os.execute("cp -Rv " .. newsite.sample .. " " .. newsite.location) - - if path.isdir(newsite.location) then - return print("Your new website is ready to be cutomize here '" .. newsite.location .. "'!") - end - - return + local newsite = { + domain = nil, + name = nil, + location = nil, + config = nil, + sample = Ferron.sites .. "ferron-ssg.tld", + } + + -- print(inspect(newsite)) + -- os.exit('1') + + io.write("How do you want names your new website? \n") + io.write("Please enter that name below... \n") + io.flush() + + newsite.name = io.read() + newsite.location = Ferron.sites .. newsite.name + + path.copy(newsite.sample .. "/*", path.mkdir(newsite.location), {delay = true; recurse = true}) + + if path.isdir(newsite.location) then + return print("Your new website is ready to be cutomize here '" .. newsite.location .. "'!") + else + return print("!! Error, something went wrong !") + end end return site diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua @@ -70,7 +70,7 @@ function fileutils.pushfilecontent(pathtofile, data) file:close() end -function fileutils.getrelpath(file) +function fileutils.getrelpath(file) return file:sub((Ferron.site.path .. Ferron.site.siteconfig.paths.content):len() + 1) end @@ -91,6 +91,5 @@ function fileutils.shorturlencode(num) return str end - -- Export `fileutils` module return fileutils