ferron

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

commit 4544c9f07efabdda70e89c0ce17602ed4bce0d8c
parent 04dd71366d2ad4176ff27f9ef0f2b57057d215f7
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date:   Tue, 22 Jan 2019 15:20:24 -0500

Add makenavigation function

Diffstat:
Mferron.lua | 1+
Mferron/site.lua | 39+++++++++++++++++++++------------------
2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/ferron.lua b/ferron.lua @@ -27,6 +27,7 @@ local exec = require "ferron.utilities.exec" Ferron.init = { site.setsite, site.reset, + site.makenavigation, } Ferron.build = { diff --git a/ferron/site.lua b/ferron/site.lua @@ -8,6 +8,7 @@ local site = { config = nil, path = nil, pagestable = {}, + navigation = {}, } function site.listsites() @@ -78,27 +79,29 @@ function site.setsite(name) end function site.makenavigation() - local navigation = {} - - for file in lfs.dir(site.content) do - if file ~= "." and file ~= ".." then - local filepath = site.content .. "/" .. file - local fileconf = fileutils.isMarkdown(filepath) and fileutils.getpageconf(filepath) or fileutils.getpageconf(filepath .. "/index.md") - local filerelpath = fileutils.isMarkdown(filepath) and fileutils.getplainname(filepath) .. ".html" or fileutils.getbasename(filepath) - - if fileconf and fileconf.navigationlabel and fileconf.navigation ~= false then - table.insert(navigation, {label = fileconf.navigationlabel, location = site.config.baseurl .. "/" .. filerelpath}) - elseif fileconf and fileconf.navigation ~= false then - table.insert(navigation, {label = fileconf.title, location = site.config.baseurl .. "/" .. filerelpath}) - end - end - end + local contentpath = assert(fileutils.isDirectory(site.content)) - print(inspect(navigation)) + tableutils.map( + function(f) + local meta = fileutils.getpageconf(f) - os.exit('1') + if meta.navigation then + local label = meta.navigation.label and meta.navigation.label or meta.title + local location = site.config.baseurl .. fileutils.removeextension(fileutils.getrelpath(f, site)) .. ".html" + local attributes = meta.navigation.attributes + + if fileutils.getbasename(location) == "index.html" then + location = fileutils.getdirname(location) + end + + return table.insert(site.navigation, {label = label, location = location, attributes = attributes}) + end + end, + -- The data table + tableutils.filter(fileutils.isMarkdown, tableutils.settable(fileutils.getdirtree(contentpath))) + ) - return navigation + return site.navigation end function site.makesite()