commit 53514ef5e5e34301e7f046af8ac2839c17cd86d0
parent be669e5bdf72cb68cb42eb75c2fce271eb701258
Author: Hugo Soucy <hugo@soucy.cc>
Date: Fri, 8 Oct 2021 18:21:31 -0400
Do some tests
Diffstat:
3 files changed, 66 insertions(+), 90 deletions(-)
diff --git a/satelito/dirtree.lua b/satelito/dirtree.lua
@@ -4,31 +4,31 @@ local dirtree = {}
local lfs = require 'lfs' -- luafilesystem
function dirtree.get(dir)
- assert(dir and dir ~= '', 'directory parameter is missing or empty')
+ assert(dir and dir ~= '', 'directory parameter is missing or empty')
- -- Removes slash if is one
- if string.sub(dir, -1) == '/' then
- dir = string.sub(dir, 1, -2)
- end
+ -- Removes slash if is one
+ if string.sub(dir, -1) == '/' then
+ dir = string.sub(dir, 1, -2)
+ end
- -- Main function of the coroutine (recursive)
- local function yieldtree(dir)
- for entry in lfs.dir(dir) do
- if entry ~= '.' and entry ~= '..' then
- entry = dir..'/'..entry
+ -- Main function of the coroutine (recursive)
+ local function yieldtree(dir)
+ for entry in lfs.dir(dir) do
+ if entry ~= '.' and entry ~= '..' then
+ entry = dir..'/'..entry
- local attr = lfs.attributes(entry)
+ local attr = lfs.attributes(entry)
- coroutine.yield(entry,dir,attr)
+ coroutine.yield(entry,dir,attr)
- if attr.mode == 'directory' then
- yieldtree(entry)
- end
- end
+ if attr.mode == 'directory' then
+ yieldtree(entry)
end
+ end
end
+ end
- return coroutine.wrap(function() yieldtree(dir) end)
+ return coroutine.wrap(function() yieldtree(dir) end)
end
return dirtree
diff --git a/satelito/init.lua b/satelito/init.lua
@@ -6,13 +6,9 @@ local inspect = require 'inspect'
--
local lume = require 'satelito.lib.lume.lume'
local model = require 'satelito.model'
-local assets = require 'satelito.assets'
local dirtree = require 'satelito.dirtree'
-local feed = require 'satelito.feed'
local file = require 'satelito.file'
-local list = require 'satelito.list'
local site = require 'satelito.site'
-local page = require 'satelito.page'
--
local init
local pipe
@@ -51,9 +47,9 @@ end
-- Example: '$ find site/content/ -name "*.md" | satelito pipe'
if args['pipe'] then
- local timestart = os.time()
local config
local templates
+ local timestart = os.time()
local sitemap = {}
for filepath in (io.lines()) do
@@ -87,60 +83,26 @@ if args['pipe'] then
-- Array of templates
templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates))
- -- Loop through the sitemap to create and export the HTML page
- for k, v in pairs(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)
-
- -- Make the page
- html, html_path = page.make(v, templates)
-
- if args['export'] then
- file.export(html_path, html)
- else
- print(html)
- end
-
- if file.is_index(k) and args['export'] then
- feed_xml, feed_xml_path = feed.make(v, templates)
-
- file.export(feed_xml_path, feed_xml)
- end
-
- -- Copy assets to the public_html/ folder
- if args['export'] then
- assets.export(v)
- end
- end
-
- print('Satelito built ' .. lume.count(sitemap) .. ' HTML page(s) in approximately ' .. os.difftime(os.time(), timestart) .. ' second(s).')
- return
+ return site.make(sitemap, templates, args['export'], timestart)
end
-- Example: '$ satelito make --export'
if args['make'] then
local config
+ local templates
+ local timestart = os.time()
+ local sitemap = {}
if file.exists('config.lua') then
-- Add the currentdir to the package.path
package.path = package.path .. ';'.. lfs.currentdir() ..'/?.lua'
- local timestart = os.time()
- local sitemap = {}
-
-- Set config.lua in a table
config = require 'config'
-- Absolute path to the 'content/' directory
local contentdir = lfs.currentdir() .. '/' .. config.paths.content
- -- Array of templates
- local templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates))
-
- --
for filepath in dirtree.get(contentdir) do
if file.is_markdown(filepath) or file.is_html(filepath) then
local meta = model.set(filepath, config, contentdir)
@@ -149,37 +111,10 @@ if args['make'] then
end
end
- --
- for k, v in pairs(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)
-
- -- Make the page
- html, html_path = page.make(v, templates)
-
- -- Export the page
- if args['export'] then
- file.export(html_path, html)
- else
- print(html)
- end
-
- if file.is_index(k) and args['export'] then
- feed_xml, feed_xml_path = feed.make(v, templates)
-
- file.export(feed_xml_path, feed_xml)
- end
-
- -- Copy assets to the public_html/ folder
- if args['export'] then
- assets.export(v)
- end
- end
+ -- Array of templates
+ templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates))
- print('Satelito built ' .. lume.count(sitemap) .. ' HTML page(s) in approximately ' .. os.difftime(os.time(), timestart) .. ' second(s).')
+ return site.make(sitemap, templates, args['export'], timestart)
else
print('There is no "config.lua" here.')
os.exit()
diff --git a/satelito/site.lua b/satelito/site.lua
@@ -2,6 +2,13 @@
local site = {}
--
local lfs = require 'lfs'
+--
+local assets = require 'satelito.assets'
+local feed = require 'satelito.feed'
+local file = require 'satelito.file'
+local list = require 'satelito.list'
+local lume = require 'satelito.lib.lume.lume'
+local page = require 'satelito.page'
--- From a filepath get the closest 'config.lua' by climbing the
-- directory tree
@@ -21,4 +28,38 @@ function site.get_config(filepath)
return site.get_config(dir_parent)
end
+-- Make the site
+function site.make(sitemap, templates, export, timestart)
+ for k, v in pairs(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)
+
+ -- Make the page
+ html, html_path = page.make(v, templates)
+
+ -- Export the page
+ if export then
+ file.export(html_path, html)
+ else
+ print(html)
+ end
+
+ -- Feed
+ if file.is_index(k) and export then
+ feed_xml, feed_xml_path = feed.make(v, templates)
+ file.export(feed_xml_path, feed_xml)
+ end
+
+ -- Copy assets to the public_html/ folder
+ if export then
+ assets.export(v)
+ end
+ end
+
+ print('Satelito built ' .. lume.count(sitemap) .. ' HTML page(s) in approximately ' .. os.difftime(os.time(), timestart) .. ' second(s).')
+end
+
return site