commit 9d7da9f2456df9d3a206f88a88180181c6b461d3
parent f835b9122acf2bd38cb0129c38116107965b3d61
Author: Hugo Soucy <hugo@soucy.cc>
Date: Mon, 14 Nov 2022 19:33:23 -0500
Test some lua script
Diffstat:
M | bin/test | | | 65 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
1 file changed, 62 insertions(+), 3 deletions(-)
diff --git a/bin/test b/bin/test
@@ -1,7 +1,66 @@
#!/usr/bin/env lua
-
-local file = 'satelito.file'
+--
+local config = require 'config'
+local dirtree = require 'satelito.dirtree'
+local file = require 'satelito.file'
+local inspect = require 'inspect'
+local lfs = require 'lfs'
+local lume = require 'satelito.lib.lume.lume'
+local model = require 'satelito.model'
+local mimetypes = require 'mimetypes'
do
- print(package.path)
+ --
+ package.path = package.path .. ';'.. arg[0]:match("(.*/)") ..'/?.lua'
+ --
+-- print(inspect(config))
+
+ -- Absolute path to the 'content/' directory
+ local contentdir = lfs.currentdir() .. '/' .. config.paths.content
+ local templates = lume.array(dirtree.get(lfs.currentdir() .. '/' .. config.paths.templates))
+
+ local function digesttree(dir)
+ 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
+
+ -- 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)
+
+ --if attr.mode == 'file' then
+ if (file.is_markdown(entry) or file.is_html(entry))
+ --and not file.is_index(entry)
+ then
+ local meta = model.set(entry, config, contentdir)
+
+ print(inspect(entry))
+ print(inspect(meta))
+ end
+
+ coroutine.yield(entry,dir,attr)
+
+ if attr.mode == 'directory' then
+ --print('DIRECTORY', entry)
+ yieldtree(entry)
+ end
+ end
+ end
+ end
+
+ return coroutine.wrap(function() yieldtree(dir) end)
+ end
+
+ for filepath in digesttree(config.paths.content) do
+ local f = filepath
+
+ --print()
+ end
end