ferron

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

commit 91ef49131ef720880e0ec56814cfe81080553d40
parent 0f0cfa8b6994b7adb5e19e6d571f80d98ee3ff86
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date:   Wed, 17 Jan 2018 14:37:47 -0500

Refactor the listindex mechanism + add archive function

Diffstat:
Mfunctions/make-lists-of-pages.lua | 56++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 38 insertions(+), 18 deletions(-)

diff --git a/functions/make-lists-of-pages.lua b/functions/make-lists-of-pages.lua @@ -18,12 +18,14 @@ local function makelistsofpages() local listindex = listindex local listindex_noextension = listindex:match("(.+)%..*") local listindex_plainname = listindex_noextension:match("^.+/(.+)$") + local listindex_dir = path.dirname(listindex) local listindex_relpath = ferronutils.getrelpath(listindex_noextension) local listindex_htmlpath = ferronutils.sethtmlpath(ferronutils.getrelpath(path.dirname(listindex))) local listindex_section = path.dirname(listindex):match("^.+/(.+)$") local listindex_metadatas = json.decode(fileutils.pullfilecontent(listindex_noextension .. ".json")) local listindex_metadatas_mt = setmetatable({}, { __index = listindex_metadatas }) local listindex_length = listindex_metadatas_mt.length ~= nil and listindex_metadatas_mt.length or nil + local pagecounter = listindex_length ~= nil and 0 or nil print("ยง Make an index page for the `" .. listindex_section .. "` section:") @@ -36,34 +38,52 @@ local function makelistsofpages() -- Set a table for the list of entries listindex_metadatas_mt["entries"] = {} - local pagecounter = listindex_length ~= nil and 0 or nil - - if pagecounter ~= nil then - for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do - local date, datetime, section, relpath = k:match("(.-)|(.-)|(.-)|(.-)$") + local function setlistindexentries() + local listindex_tmp_tab = {} - if section == listindex_section or relpath:match("%/"..listindex_section.."%/") then - if pagecounter < listindex_length then - table.insert(listindex_metadatas_mt["entries"], v) + path.each( + listindex_dir .. "/*.md", + function(md) + if path.basename(md) ~= "index.md" or md == contentpath .. "/index.md" then + local md_noextension = md:match("(.+)%..*") + local md_relpath = ferronutils.getrelpath(md_noextension) + local md_section = md_relpath:match("/(%a-)/") + local md_metadatas = json.decode(fileutils.pullfilecontent(md_noextension .. ".json")) + local md_key = md_metadatas.date .. "|" .. md_metadatas.datetime .. "|" .. (md_section ~= nil and md_section or "root") .. "|" .. md_relpath - pagecounter = pagecounter + 1 + listindex_tmp_tab[md_key] = Ferron.site.pagestable[md_key] end + end, + { + delay = true; -- use snapshot of directory + recurse = true; -- include subdirs + reverse = false; -- subdirs at first + } + ) + + local function sortentries() + if pagecounter ~= nil then + for k, v in tableutils.sortdescendingpairs(listindex_tmp_tab) do + if pagecounter < listindex_length then + table.insert(listindex_metadatas_mt["entries"], v) - print(section) + pagecounter = pagecounter + 1 + end + end + else + for k, v in tableutils.sortdescendingpairs(listindex_tmp_tab) do + table.insert(listindex_metadatas_mt["entries"], v) + end end end - else - for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do - local date, datetime, section, relpath = k:match("(.-)|(.-)|(.-)|(.-)$") - if section == listindex_section or relpath:match("%/"..listindex_section.."%/") then - table.insert(listindex_metadatas_mt["entries"], v) + sortentries() - print(section) - end - end + return listindex_metadatas_mt["entries"] end + setlistindexentries() + if path.isdir(listindex_htmlpath) == false then fileutils.mkdir(listindex_htmlpath) end