Static site generator made with Lua script.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
745 B

-- @module dirtree
local dirtree = {}
--
local lfs = require 'lfs' -- luafilesystem
function dirtree.get(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)
coroutine.yield(entry,dir,attr)
if attr.mode == 'directory' then
yieldtree(entry)
end
end
end
end
return coroutine.wrap(function() yieldtree(dir) end)
end
return dirtree