From 9beef6bdace1e70b5f3097896a955892e324800a Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 4 Jan 2022 15:57:34 -0600 Subject: implement plugins directory --- src/lua-script/script.h | 82 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 9 deletions(-) (limited to 'src/lua-script/script.h') diff --git a/src/lua-script/script.h b/src/lua-script/script.h index 0bb6451..e29003f 100644 --- a/src/lua-script/script.h +++ b/src/lua-script/script.h @@ -88,7 +88,7 @@ const char *argent_script = " site_directory = add_end_slash(config.site_directory) or 'site/',\n" " output_directory = add_end_slash(config.output_directory) or 'public/',\n" " layout_directory = add_end_slash(config.layout_directory) or nil,\n" - " plugin_directory = add_end_slash(config.layout_directory) or nil,\n" + " plugin_directory = add_end_slash(config.plugin_directory) or nil,\n" " exclude = Set(config.exclude, strip_end_slash) or {},\n" " include = Set(config.include, strip_end_slash) or {},\n" " keep = Set(config.keep, strip_end_slash) or {},\n" @@ -115,7 +115,9 @@ const char *argent_script = " argent.log('info', fmt('available layouts: %s', set_tostring(argent.layouts)))\n" " \n" " if argent.config.plugin_directory then\n" - " package.path = argent.config.plugin_directory..'?.lua;'..package.path\n" + " package.path =\n" + " add_end_slash(argent.currentWorkingDirectory())\n" + " ..argent.config.plugin_directory..'?.lua;'..package.path\n" " end\n" " argent.log('debug', 'end setup')\n" " end\n" @@ -211,10 +213,32 @@ const char *argent_script = " --\n" " --------------------------------\n" "\n" + " function should_include(filename, parent)\n" + " for pattern in pairs(argent.config.include) do\n" + " if string.match(filename, pattern) or string.match(parent..filename, pattern) then\n" + " return true\n" + " end\n" + " end\n" + " return false\n" + " end\n" + "\n" + " function should_ignore(filename, parent)\n" + " if is_dotfile(filename) and not should_include(filename, parent) then\n" + " return false\n" + " end\n" + "\n" + " for pattern in pairs(argent.config.exclude) do\n" + " if string.match(filename, pattern)\n" + " or string.match(parent..filename, pattern) then\n" + " return true\n" + " end\n" + " end\n" + "\n" + " return false\n" + " end\n" + "\n" " function process_file(filename, parent)\n" - " if (is_dotfile(filename) and not argent.config.include[filename])\n" - " or argent.config.exclude[filename]\n" - " then\n" + " if should_ignore(filename, parent) then\n" " argent.log('debug', fmt('will not process file %q', parent..filename))\n" " return\n" " end\n" @@ -239,14 +263,54 @@ const char *argent_script = " return\n" " end\n" "\n" - " print(filename, result)\n" + " if not type(result) == 'table' then\n" + " argent.log('error', fmt('%q returned %q instead of %q', filename, type(result), 'table'))\n" + " argent.log('warn', fmt('%q will not result in file output!', filename))\n" + " return\n" + " end\n" + "\n" + " local html\n" + " if result.html then\n" + " html = result.html\n" + " elseif result.markdown then\n" + " html = argent.markdown(result.markdown)\n" + " else\n" + " argent.log('error', fmt('%q did not specify any content!', filename))\n" + " argent.log('warn', fmt('%q will not result in file output!', filename))\n" + " return\n" + " end\n" + "\n" + " if not result.title then\n" + " result.title = string.gsub(filename, '%.lua$', '')\n" + " argent.log('warn', fmt('%q did not specify a title; using default title of %q',\n" + " filename, result.title))\n" + " end\n" + "\n" + " local layout = function(html, tbl) return html end\n" + " if result.layout then\n" + " if not argent.layouts[result.layout] then\n" + " argent.log('error', fmt('%q requested nonexistent layout %q', filename, result.layout))\n" + " argent.log('warn', fmt('%q will not result in file output!', filename))\n" + " return\n" + " else\n" + " layout = argent.layouts[result.layout]\n" + " end\n" + " else -- no layout specified\n" + " argent.log('warn', fmt(\n" + " '%q did not specify a layout; output will be naked content!',\n" + " filename))\n" + " end\n" + "\n" + " local output_data = layout(html, result)\n" + " local output_name = string.gsub(filename, '%.lua$', '.html')\n" + " local output_file = io.open(argent.config.output_directory..parent..output_name, 'w')\n" + " output_file:write(output_data)\n" + " output_file:close()\n" " end\n" "\n" "\n" " function process_dir(directory, parent)\n" - " if (is_dotfile(directory) and not argent.config.include[strip_end_slash(directory)])\n" - " or argent.config.exclude[strip_end_slash(directory)]\n" - " then\n" + " if should_ignore(directory, parent) then\n" " argent.log('debug', fmt('will not process directory %q', parent..directory))\n" " return\n" " end\n" -- cgit v1.2.1