ferron

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

commit 9daa13d36dfef94eaa0c9acb495d81e6ae567333
parent 7db6a705b178cff6cad8a580fdce97d485a428ce
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date:   Thu,  8 Feb 2018 17:12:19 -0500

Create functions to build tag pages

Diffstat:
Mferron.lua | 2+-
Mferron/tag.lua | 54+++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/ferron.lua b/ferron.lua @@ -47,7 +47,7 @@ Ferron.build = { feed.makefeed, link.makeshorts, link.makerewritemap, - --tag.gettags, + tag.maketagpage, static.move } diff --git a/ferron/tag.lua b/ferron/tag.lua @@ -6,16 +6,60 @@ local tableutils = require "ferron.utilities.table-utils" local templateutils = require "ferron.utilities.template-utils" local tag = {} -function tag.gettags() - local tags = {} +local function maketagstable() + local tagstable = {} local pages = Ferron.site.pagestable - for k, v in pairs(pages) do - if v.keywords ~= nil then - print(v.permalink, inspect(v.keywords)) + for k, page in pairs(pages) do + if page.keywords ~= nil then + for i, keyword in ipairs(page.keywords) do + if tableutils.hasvalue(tagstable, keyword) == false then + tagstable[keyword] = {} + end + end end end + for k, page in pairs(pages) do + if page.keywords ~= nil then + for i, keyword in ipairs(page.keywords) do + if tagstable[keyword] ~= nil then + table.insert(tagstable[keyword], page.rellink) + end + end + end + end + + return tagstable +end + +function tag.maketagpage() + local tagstable = maketagstable() + local htmlpath = Ferron.site.path .. Ferron.site.siteconfig.paths.html + + for tag, urls in pairs(tagstable) do + local tag_tb = { + tagname = tag, + tagurls = urls + } + + if path.isdir(htmlpath .. "/tag") == false then + fileutils.mkdir(htmlpath .. "/tag") + end + + --print(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/tag.mustache") + + -- Build the HTML file + fileutils.pushfilecontent( + htmlpath .. "/tag/" .. tag .. ".html", + templateutils.setmustache( + fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/tag.mustache"), + Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials", + tag_tb + ) + ) + end + end return tag