ferron

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

commit b30600043e5b1a2f5aa25e8f198ffffd7283d2c2
parent 5ab891ef3eb42cbfe001036fa3ea61408c5c2433
Author: Hugo Soucy <hugo.soucy@equisoft.com>
Date:   Mon, 17 Jun 2019 08:46:30 -0400

Merge branch 'master' of github.com:hs0ucy/Ferron

Diffstat:
Mcornelius | 13+++----------
Dferron/app.lua | 21---------------------
Mferron/init.lua | 46+++++++++++++++++++++++++++-------------------
Mferron/page.lua | 11+++++++++++
Mferron/site.lua | 16++++++++++++++--
5 files changed, 55 insertions(+), 52 deletions(-)

diff --git a/cornelius b/cornelius @@ -19,6 +19,7 @@ local function getdirfiles(dir) end if arg[1] == 'install' and tonumber(_VERSION:match('%d+%.%d+')) >= config.dependencies.lua then + -- Install Ferron -- First, check if luarocks is present in the env. if pcall(require, 'luarocks.loader') then -- Then install each dependency from the main configuration @@ -43,16 +44,8 @@ if arg[1] == 'install' and tonumber(_VERSION:match('%d+%.%d+')) >= config.depend print('Please install it on your system https://luarocks.org/.') end -elseif arg[1] == 'build' and arg[2] == '--dev' then - os.execute('lua -l ferron.setpaths ferron.lua --dev') -elseif arg[1] == 'build' then - os.execute('lua -l ferron.setpaths ferron.lua') -elseif arg[1] == 'create' then - os.execute('lua -l ferron.setpaths ferron.lua --set content') -elseif arg[1] == 'start' then - os.execute('lua -l ferron.setpaths ferron.lua --make site') -elseif arg[1] == 'plugin' and type(arg[2]) == 'string' and arg[2] ~= '' then - os.execute('lua -l ferron.setpaths ferron.lua --run ' .. arg[2]) +elseif arg[1] then + dofile('ferron.lua') else print("Hi, I'm Cornelius Ferron, the eminence of the great horn of the static site generator... or if you prefer, the CLI.") print('What Can I Do for You?') diff --git a/ferron/app.lua b/ferron/app.lua @@ -1,21 +0,0 @@ --- app.lua -local app = {} -local appmeta = { - __call = function(self, key, vars) - print(key) - end -} - -function app.exec(...) - for argkey, argval in pairs({...}) do - if type(argval) == 'table' then - for funckey, funcval in ipairs(argval) do - if type(funcval) == 'function' then - funcval() - end - end - end - end -end - -return setmetatable(app, appmeta) diff --git a/ferron/init.lua b/ferron/init.lua @@ -2,6 +2,9 @@ -- Ferron SSG -- +-- Get lua_modules in the package.path +require 'ferron.setpaths' + -- Required Modules inspect = require 'inspect' @@ -13,12 +16,12 @@ local page = require 'ferron.page' local link = require 'ferron.link' local static = require 'ferron.static' local plugin = require 'ferron.plugin' -local app = require 'ferron.app' +local tableutils = require 'ferron.utilities.table-utils' -- App's Globals -- Init the main namespace Ferron = { - devmode = (arg[1] == '--dev' and true or false), + devmode = (arg[2] == '--dev' and true or false), site = { location = lfs.currentdir() .. '/' .. config.sites, @@ -27,31 +30,36 @@ Ferron = { pagestable = {}, navigation = {}, }, +} - init = { - site.setsite, - site.sitereset, - site.setnavigation, - }, +if arg[1] == 'build' then + do + local sitename = arg[3] + local function build(funcTable) + for i, func in ipairs(funcTable) do + return func + end + end - build = { - page.iterator, - link.makeshorts, - link.makerewritemap, - static.init, - }, -} + return build{ + site.setsite(sitename), + site.setnavigation(), + page.iterator(), + link.makeshorts(), + link.makerewritemap(), + static.init() + } + end +end -if arg[1] == '--set' and arg[2] == 'content' then +if arg[1] == 'create' then return content.setcontent(site.setsite()) end -if arg[1] == '--make' and arg[2] == 'site' then +if arg[1] == 'start' then return site.startsite() end -if arg[1] == '--run' and type(arg[2]) == 'string' and arg[2] ~= '' then +if arg[1] == 'plugin' and type(arg[2]) == 'string' and arg[2] ~= '' then return plugin.run(site.setsite(), arg[2]) end - -return app.exec(Ferron.init, Ferron.build) diff --git a/ferron/page.lua b/ferron/page.lua @@ -80,12 +80,23 @@ function page.render(pagesource) local metaTable = setmetatable( setmetaprops(page, pathRel), {__index = fileutils.getpageconf(page)} ) + local shortlinks_db = fileutils.isFile(Ferron.site.data .. '/shortlinks.json') + local shortlinks_tb = (shortlinks_db ~= false and json.decode(fileutils.pullfilecontent(shortlinks_db)) or nil) + -- Populate Ferron.site.pagestable{} if fileutils.isNotIndex(page) then setpagetable(metaTable, pathRel) end + + -- If exists set the shortlink + if fileutils.isNotIndex(page) then + if shortlinks_tb and shortlinks_db then + metaTable.shortlink = (shortlinks_tb[metaTable.rellink] and shortlinks_tb[metaTable.rellink] or nil) + end + end + -- For index page set and get entries if fileutils.isIndex(page) then setentries(fileutils.getdirname(page), metaTable) diff --git a/ferron/site.lua b/ferron/site.lua @@ -36,10 +36,21 @@ function site.getsiteconfig(sitename) return require 'config' end +function site.isSite(sitename) + if tableutils.hasvalue(site.getsitelist(), sitename) then + print(sitename) + return sitename + end + + return false +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') @@ -58,8 +69,8 @@ function site.setsite(sitename) end -- Assign values to Ferron.site.path and Ferron.site.config - Ferron.site.path = Ferron.site.location .. (sitename or siteslist[tonumber(whichsite)]) - Ferron.site.config = tableutils.extend({}, config, (site.getsiteconfig(sitename or siteslist[tonumber(whichsite)]))) + 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)]))) -- 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) @@ -71,6 +82,7 @@ function site.setsite(sitename) Ferron.site.html = Ferron.site.path .. Ferron.site.config.paths.html Ferron.site.plugins = Ferron.site.path .. Ferron.site.config.paths.plugins Ferron.site.static = Ferron.site.path .. Ferron.site.config.paths.static + Ferron.site.static_src = Ferron.site.path .. Ferron.site.config.paths.static_src Ferron.site.templates = Ferron.site.path .. Ferron.site.config.paths.templates return Ferron.site