commit 645ffff9f40a36723e4317636f13379cd2e55d20
parent ec8105b7699ba67971c72ef7d06bbaf4343e7f07
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date: Thu, 9 Aug 2018 17:35:06 -0400
Optimize list and page modules.
Diffstat:
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/ferron/list.lua b/ferron/list.lua
@@ -60,6 +60,7 @@ end
function list.makelist()
local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content
+ local templatespath = Ferron.site.path .. Ferron.site.siteconfig.paths.templates
path.each(
contentpath .. "/*.md",
@@ -87,7 +88,7 @@ function list.makelist()
-- Set and get entries of the list
setentries(list_dir, list_conf_mt)
- if path.isdir(list_htmlpath) == false then
+ if not path.isdir(list_htmlpath) then
fileutils.mkdir(list_htmlpath)
end
@@ -97,13 +98,13 @@ function list.makelist()
fileutils.pushfilecontent(
list_htmlpath .. "/" .. list_plainname .. ".html",
templateutils.setmustache(
- fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/" .. list_conf.template .. ".mustache"),
- Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials",
+ fileutils.pullfilecontent(templatespath .. "/" .. (list_conf.template ~= nil and list_conf.template or "default-index") .. ".mustache"),
+ templatespath .. "/partials",
list_conf_mt
)
)
- if path.isfile(list_htmlpath .. "/" .. list_plainname .. ".html") == false then
+ if not path.isfile(list_htmlpath .. "/" .. list_plainname .. ".html") then
print(" !! " .. list_relpath .. ".html - error!")
end
diff --git a/ferron/page.lua b/ferron/page.lua
@@ -9,6 +9,7 @@ local page = {}
function page.makepage()
local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content
+ local templatespath = Ferron.site.path .. Ferron.site.siteconfig.paths.templates
local shortlinks_db = path.isfile(Ferron.site.path .. Ferron.site.siteconfig.paths.data .. "/shortlinks.json")
local shortlinks_tb = (shortlinks_db ~= false and json.decode(fileutils.pullfilecontent(shortlinks_db)) or nil)
@@ -27,7 +28,7 @@ function page.makepage()
local page_conf = json.decode(fileutils.pullfilecontent(page_noextension .. ".json"))
local page_conf_mt = setmetatable({}, { __index = page_conf })
local page_key = page_conf.date .. "|" .. page_conf.datetime .. "|" .. page_relpath
- local page_template = Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/" .. page_conf.template .. ".mustache"
+ local page_template = templatespath .. "/" .. (page_conf.template ~= nil and page_conf.template or "default") .. ".mustache"
page_conf.updated = os.date("%Y-%m-%dT%H:%M:%S", path.mtime(page))
page_conf.id = "tag:" .. Ferron.site.siteconfig.domainname .. "," .. page_conf.date .. ":" .. string.sub(page_conf.date, 0, 4) .. "/" .. string.sub(page_conf.date, 6, 7) .. "/" .. page_plainname
@@ -48,7 +49,7 @@ function page.makepage()
Ferron.site.pagestable[page_key] = page_conf_mt
- if path.isdir(page_htmlpath) == false then
+ if not path.isdir(page_htmlpath) then
fileutils.mkdir(page_htmlpath)
end
@@ -57,12 +58,12 @@ function page.makepage()
page_htmlpath .. "/" .. page_plainname .. ".html",
templateutils.setmustache(
fileutils.pullfilecontent(page_template),
- Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials",
+ templatespath .. "/partials",
page_conf_mt
)
)
- if path.isfile(page_htmlpath .. "/" .. page_plainname .. ".html") == false then
+ if not path.isfile(page_htmlpath .. "/" .. page_plainname .. ".html") then
print(" !! " .. page_relpath .. ".html - error!")
end