summaryrefslogtreecommitdiff
path: root/src/lua-script/script.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua-script/script.lua')
-rw-r--r--src/lua-script/script.lua82
1 files changed, 73 insertions, 9 deletions
diff --git a/src/lua-script/script.lua b/src/lua-script/script.lua
index e5da91f..c6c2ecb 100644
--- a/src/lua-script/script.lua
+++ b/src/lua-script/script.lua
@@ -87,7 +87,7 @@ return function(config)
site_directory = add_end_slash(config.site_directory) or 'site/',
output_directory = add_end_slash(config.output_directory) or 'public/',
layout_directory = add_end_slash(config.layout_directory) or nil,
- plugin_directory = add_end_slash(config.layout_directory) or nil,
+ plugin_directory = add_end_slash(config.plugin_directory) or nil,
exclude = Set(config.exclude, strip_end_slash) or {},
include = Set(config.include, strip_end_slash) or {},
keep = Set(config.keep, strip_end_slash) or {},
@@ -114,7 +114,9 @@ return function(config)
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
+ package.path =
+ add_end_slash(argent.currentWorkingDirectory())
+ ..argent.config.plugin_directory..'?.lua;'..package.path
end
argent.log('debug', 'end setup')
end
@@ -210,10 +212,32 @@ return function(config)
--
--------------------------------
+ function should_include(filename, parent)
+ for pattern in pairs(argent.config.include) do
+ if string.match(filename, pattern) or string.match(parent..filename, pattern) then
+ return true
+ end
+ end
+ return false
+ end
+
+ function should_ignore(filename, parent)
+ if is_dotfile(filename) and not should_include(filename, parent) then
+ return false
+ end
+
+ for pattern in pairs(argent.config.exclude) do
+ if string.match(filename, pattern)
+ or string.match(parent..filename, pattern) then
+ return true
+ end
+ end
+
+ return false
+ end
+
function process_file(filename, parent)
- if (is_dotfile(filename) and not argent.config.include[filename])
- or argent.config.exclude[filename]
- then
+ if should_ignore(filename, parent) then
argent.log('debug', fmt('will not process file %q', parent..filename))
return
end
@@ -238,14 +262,54 @@ return function(config)
return
end
- print(filename, result)
+ if not type(result) == 'table' then
+ argent.log('error', fmt('%q returned %q instead of %q', filename, type(result), 'table'))
+ argent.log('warn', fmt('%q will not result in file output!', filename))
+ return
+ end
+
+ local html
+ if result.html then
+ html = result.html
+ elseif result.markdown then
+ html = argent.markdown(result.markdown)
+ else
+ argent.log('error', fmt('%q did not specify any content!', filename))
+ argent.log('warn', fmt('%q will not result in file output!', filename))
+ return
+ end
+
+ if not result.title then
+ result.title = string.gsub(filename, '%.lua$', '')
+ argent.log('warn', fmt('%q did not specify a title; using default title of %q',
+ filename, result.title))
+ end
+
+ local layout = function(html, tbl) return html end
+ if result.layout then
+ if not argent.layouts[result.layout] then
+ argent.log('error', fmt('%q requested nonexistent layout %q', filename, result.layout))
+ argent.log('warn', fmt('%q will not result in file output!', filename))
+ return
+ else
+ layout = argent.layouts[result.layout]
+ end
+ else -- no layout specified
+ argent.log('warn', fmt(
+ '%q did not specify a layout; output will be naked content!',
+ filename))
+ end
+
+ local output_data = layout(html, result)
+ local output_name = string.gsub(filename, '%.lua$', '.html')
+ local output_file = io.open(argent.config.output_directory..parent..output_name, 'w')
+ output_file:write(output_data)
+ output_file:close()
end
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
+ if should_ignore(directory, parent) then
argent.log('debug', fmt('will not process directory %q', parent..directory))
return
end