ferron

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

commit e9efbfeb3dc33f22c7fc38d3f8ebbd614a5df4a1
parent 1fd4bb0083ce54a8fc11019ed53e0b211c20eb38
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date:   Fri,  7 Dec 2018 14:09:31 -0500

Remove path utilisations

Diffstat:
Mferron/list.lua | 36+++++++++++-------------------------
1 file changed, 11 insertions(+), 25 deletions(-)

diff --git a/ferron/list.lua b/ferron/list.lua @@ -1,7 +1,6 @@ -- local json = require "dkjson" local markdown = require "discount" -local path = require "path" local fileutils = require "ferron.utilities.file-utils" local tableutils = require "ferron.utilities.table-utils" local templateutils = require "ferron.utilities.template-utils" @@ -32,24 +31,16 @@ local function sortentries(entries_tb, list_mt) end local function setentries(directory, list_mt) - local contentpath = Ferron.site.path .. Ferron.site.config.paths.content local entries_tb = {} - path.each( - directory .. "/*.md", + tableutils.each( function(entry) - if path.basename(entry) ~= "index.md" then - local entry_metadatas = json.decode(fileutils.pullfilecontent(fileutils.removeextension(entry) .. ".json")) - local entry_key = entry_metadatas.date .. "|" .. entry_metadatas.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(entry)) + local entry_metadatas = json.decode(fileutils.pullfilecontent(fileutils.removeextension(entry) .. ".json")) + local entry_key = entry_metadatas.date .. "|" .. entry_metadatas.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(entry)) - entries_tb[entry_key] = Ferron.site.pagestable[entry_key] - end + entries_tb[entry_key] = Ferron.site.pagestable[entry_key] end, - { - delay = true; -- use snapshot of directory - recurse = true; -- include subdirs - reverse = false; -- subdirs at first - } + tableutils.filter(fileutils.isNotIndex, tableutils.settable(fileutils.getdirtree(directory))) ) sortentries(entries_tb, list_mt) @@ -59,25 +50,25 @@ end function list.render(listsource) local list = listsource - local list_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(path.dirname(list))) + local list_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(list))) local list_conf = json.decode(fileutils.pullfilecontent(fileutils.removeextension(list) .. ".json")) local list_conf_mt = setmetatable({}, { __index = list_conf }) - print("§ Make a list page for the `" .. fileutils.getrelpath(path.dirname(list)) .. "` subdirectory ...") + print("§ Make a list page for the `" .. fileutils.getrelpath(fileutils.getdirname(list)) .. "` subdirectory ...") -- Convert the markdown file to HTML list_conf_mt.content = markdown(fileutils.pullfilecontent(list)) -- Set a dynamic permalink - list_conf_mt.permalink = Ferron.site.config.baseurl .. path.dirname(fileutils.getrelpath(fileutils.removeextension(list))) + list_conf_mt.permalink = Ferron.site.config.baseurl .. fileutils.getdirname(fileutils.getrelpath(fileutils.removeextension(list))) -- Import site configuration in the metatable list_conf_mt["site"] = Ferron.site.config -- Set a table for the list of entries list_conf_mt["entries"] = {} -- Set and get entries of the list - setentries(path.dirname(list), list_conf_mt) + setentries(fileutils.getdirname(list), list_conf_mt) - if not path.isdir(list_htmlpath) then + if not fileutils.isDirectory(list_htmlpath) then fileutils.mkdir(list_htmlpath) end @@ -105,13 +96,8 @@ end function list.init() local contentpath = assert(fileutils.isDirectory(Ferron.site.path .. Ferron.site.config.paths.content)) - local function test(pth) - print(fileutils.getdirname(pth)) - end + tableutils.each(list.render, tableutils.filter(fileutils.isIndex, tableutils.settable(fileutils.getdirtree(contentpath)))) - -- tableutils.each(list.render, tableutils.filter(fileutils.isIndex, tableutils.settable(fileutils.getdirtree(contentpath)))) - tableutils.each(test, tableutils.filter(fileutils.isIndex, tableutils.settable(fileutils.getdirtree(contentpath)))) - os.exit('1') return end