commit 5129c930495cfe19f2de9ab21d79689ab5ac4624
parent 44be5197c59dcec5cde0d9a003707bd50c8c64bc
Author: Hugo Soucy <hugo@soucy.cc>
Date: Mon, 11 Oct 2021 20:02:07 -0400
Remplace pairs/ipairs by a basic for loop
Diffstat:
4 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/satelito/assets.lua b/satelito/assets.lua
@@ -13,10 +13,10 @@ function assets.export(filemeta)
return lume.any(mtypes, function(mtype) return mtype == mimetypes.guess(f) end)
end
- for _, sibling in ipairs(siblings) do
- if is_in_mimetypes(sibling) then
- local source = file.get_dirname(filemeta.paths.content..filemeta.relpath)..sibling
- local target = file.get_dirname(filemeta.exportlink) .. sibling
+ for i = 1, #siblings do
+ if is_in_mimetypes(siblings[i]) then
+ local source = file.get_dirname(filemeta.paths.content..filemeta.relpath)..siblings[i]
+ local target = file.get_dirname(filemeta.exportlink)..siblings[i]
if not lfs.attributes(target)
or lfs.attributes(source).modification > lfs.attributes(target).modification
diff --git a/satelito/init.lua b/satelito/init.lua
@@ -110,7 +110,7 @@ if args['pipe'] then
print('=> Fetching the markdown and HTML content ...')
end
- sitemap[meta.relpath] = lume.extend({}, meta)
+ sitemap[#sitemap+1] = lume.extend({}, meta)
end
end
end
@@ -151,7 +151,7 @@ if args['make'] then
if file.is_markdown(filepath) or file.is_html(filepath) then
local meta = model.set(filepath, config, contentdir)
- sitemap[meta.relpath] = lume.extend({}, meta)
+ sitemap[#sitemap+1] = lume.extend({}, meta)
end
end
diff --git a/satelito/list.lua b/satelito/list.lua
@@ -3,29 +3,27 @@ local list = {}
--
local dirtree = require 'satelito.dirtree'
local file = require 'satelito.file'
-local inspect = require 'inspect'
local lume = require 'satelito.lib.lume.lume'
-- Children
function list.get_children(children_list, sitemap, asc)
- local children
+ local children = {}
if children_list then
+ for i = 1, #sitemap do
+ local is_child = lume.find(children_list, sitemap[i].relpath)
+
+ if is_child then
+ children[#children+1] = sitemap[i]
+ end
+ end
+
-- Sorting ASC if list have asc set to true
if asc then
- table.sort(
- children_list,
- function(a , b) return tonumber(sitemap[a].time_created) < tonumber(sitemap[b].time_created) end
- )
- -- Otherwise it's DESC
+ table.sort(children, function(a, b) return tonumber(a.time_created) < tonumber(b.time_created) end)
else
- table.sort(
- children_list,
- function(a , b) return tonumber(sitemap[a].time_created) > tonumber(sitemap[b].time_created) end
- )
+ table.sort(children, function(a, b) return tonumber(a.time_created) > tonumber(b.time_created) end)
end
-
- children = lume.map(children_list, function(item) return sitemap[item] end)
end
return children
diff --git a/satelito/site.lua b/satelito/site.lua
@@ -30,15 +30,15 @@ end
-- Make the site
function site.make(sitemap, templates, export, timestart)
- for k, v in pairs(sitemap) do
+ for i = 1, #sitemap do
local html, html_path
local feed_xml, feed_xml_path
- v.root = sitemap
- v.children = list.get_children(v.list, sitemap, v.asc)
+ sitemap[i].root = sitemap
+ sitemap[i].children = list.get_children(sitemap[i].list, sitemap, sitemap[i].asc)
-- Make the page
- html, html_path = page.make(v, templates)
+ html, html_path = page.make(sitemap[i], templates)
-- Export the page
if export then
@@ -48,14 +48,14 @@ function site.make(sitemap, templates, export, timestart)
end
-- Feed
- if file.is_index(k) and export then
- feed_xml, feed_xml_path = feed.make(v, templates)
+ if file.is_index(sitemap[i].relpath) and export then
+ feed_xml, feed_xml_path = feed.make(sitemap[i], templates)
file.export(feed_xml_path, feed_xml)
end
-- Copy assets to the public_html/ folder
if export then
- assets.export(v)
+ assets.export(sitemap[i])
end
end