summaryrefslogtreecommitdiff
path: root/src/lua-script/script.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-01-04 15:05:41 -0600
committersanine <sanine.not@pm.me>2022-01-04 15:05:41 -0600
commitcc82d13a4f80a5a2483581dd679f06772a9e3a19 (patch)
tree6cb096ade3e7db59cc91cd836d6e7de95a01cec4 /src/lua-script/script.lua
parenta026db7389c15eb5a8905e6f04eb3a92bf31f9bc (diff)
add layout loading
Diffstat (limited to 'src/lua-script/script.lua')
-rw-r--r--src/lua-script/script.lua59
1 files changed, 54 insertions, 5 deletions
diff --git a/src/lua-script/script.lua b/src/lua-script/script.lua
index ccfe902..e5da91f 100644
--- a/src/lua-script/script.lua
+++ b/src/lua-script/script.lua
@@ -46,6 +46,40 @@ return function(config)
end
+ function load_layouts(directory, parent, layouts)
+ local directory = add_end_slash(directory) or ''
+ local parent = parent or ''
+ local layouts = layouts or {}
+
+ local fullpath = parent..directory
+ local dirs, files = argent.scanDirectory(argent.config.layout_directory..fullpath)
+
+ for _, file in ipairs(files) do
+ if string.match(file, '%.lua$') then
+ local basename = string.gsub(file, '%.lua$', '')
+ local id = string.gsub(fullpath..basename, '/', '.')
+ argent.log('debug', fmt('loading layout %q', id))
+ success, result = pcall(loadfile(argent.config.layout_directory..fullpath..file), 0, 1)
+ if not success then
+ argent.log('error', result)
+ argent.log('warn', fmt('layout %q will not be available', id))
+ else
+ layouts[id] = result
+ end
+ end
+ end
+
+ for _, dir in ipairs(dirs) do
+ if dir ~= '.' and dir ~= '..' then
+ argent.log('debug', fmt('loading layouts from %q', parent..directory))
+ load_layouts(dir, parent..directory, layouts)
+ end
+ end
+
+ return layouts
+ end
+
+
function setup(config)
argent.log('debug', 'begin setup')
@@ -72,6 +106,13 @@ return function(config)
argent.log('info', 'noprocess: '..set_tostring(argent.config.noprocess))
argent.log('info', 'rss files: '..set_tostring(argent.config.rss_include))
+ if argent.config.layout_directory then
+ argent.layouts = load_layouts()
+ else
+ argent.layouts = {}
+ end
+ argent.log('info', fmt('available layouts: %s', set_tostring(argent.layouts)))
+
if argent.config.plugin_directory then
package.path = argent.config.plugin_directory..'?.lua;'..package.path
end
@@ -115,11 +156,11 @@ return function(config)
function obliterate_file(file, parent)
if argent.config.keep[file] then
- argent.log('debug', fmt('retaining file %q', file))
+ argent.log('debug', fmt('retaining file %q', parent..file))
return true
end
- argent.log('debug', fmt('removing file %q', file))
+ argent.log('debug', fmt('removing file %q', parent..file))
os.remove(argent.config.output_directory..parent..file)
return false
end
@@ -127,7 +168,7 @@ return function(config)
function obliterate_dir(dir, parent)
if argent.config.keep[strip_end_slash(dir)] then
- argent.log('debug', fmt('retaining directory %q', dir))
+ argent.log('debug', fmt('retaining directory %q', parent..dir))
return true
end
@@ -172,11 +213,16 @@ return function(config)
function process_file(filename, parent)
if (is_dotfile(filename) and not argent.config.include[filename])
or argent.config.exclude[filename]
- then return end
+ then
+ argent.log('debug', fmt('will not process file %q', parent..filename))
+ return
+ end
if string.match(filename, '%.lua$') and not argent.config.noprocess[filename] then
+ argent.log('debug', fmt('processing %q as lua file', parent..filename))
process_lua_file(filename, parent)
else
+ argent.log('debug', fmt('processing %q as regular file', parent..filename))
argent.copyFile(
argent.config.site_directory..parent..filename,
argent.config.output_directory..parent..filename
@@ -199,7 +245,10 @@ return function(config)
function process_dir(directory, parent)
if (is_dotfile(directory) and not argent.config.include[strip_end_slash(directory)])
or argent.config.exclude[strip_end_slash(directory)]
- then return end
+ then
+ argent.log('debug', fmt('will not process directory %q', parent..directory))
+ return
+ end
if not directory_exists(directory, parent) then
argent.createDirectory(argent.config.output_directory..parent..directory)