ferron

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

commit 2e81e04c2b13ab35569181b6ae2210023c2781c4
parent 4544c9f07efabdda70e89c0ce17602ed4bce0d8c
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date:   Thu, 24 Jan 2019 13:08:04 -0500

Add function to sort nav items

Diffstat:
Mferron/site.lua | 25+++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/ferron/site.lua b/ferron/site.lua @@ -80,6 +80,26 @@ end function site.makenavigation() local contentpath = assert(fileutils.isDirectory(site.content)) + local navigationTable = {} + + -- It's a dumb way to sort but it works for now + local function sortNavigation(tbl) + local sortTable = {} + + for idx, val in ipairs(tbl) do + if val.order then + sortTable[val.order] = val + end + end + + for idx, val in ipairs(tbl) do + if not val.order then + sortTable[#sortTable+1] = val + end + end + + return sortTable + end tableutils.map( function(f) @@ -89,19 +109,20 @@ function site.makenavigation() 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 + local order = meta.navigation.order if fileutils.getbasename(location) == "index.html" then location = fileutils.getdirname(location) end - return table.insert(site.navigation, {label = label, location = location, attributes = attributes}) + return table.insert(navigationTable, {label = label, location = location, attributes = attributes, order = order}) end end, -- The data table tableutils.filter(fileutils.isMarkdown, tableutils.settable(fileutils.getdirtree(contentpath))) ) - return site.navigation + return tableutils.extend(site.navigation, sortNavigation(navigationTable)) end function site.makesite()