commit 14c2c658bbcda5f55cc80ec5ab304f722564b876
parent 267a705e46409e52565bee56c1e78f3d7258ef9a
Author: Hugo Soucy <hugo@soucy.cc>
Date: Tue, 6 Apr 2021 08:50:42 -0400
Convert the function in method and remove others
Diffstat:
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/satelito/site.lua b/satelito/site.lua
@@ -4,31 +4,19 @@ local lfs = require 'lfs'
--- From a filepath get the closest 'config.lua' by climbing the
-- directory tree
-- Recursive function
-local function find_config(filepath)
- assert(filepath and filepath ~= '', 'The filepath parameter is missing or empty.')
+function site.get_config(filepath)
+ assert(filepath and filepath ~= '', 'The filepath parameter is missing or empty.')
- local dir = filepath:match("(.*/)")
- local dir_parent = string.sub(dir, 1, -2):match("(.*/)")
+ local dir = filepath:match("(.*/)")
+ local dir_parent = string.sub(dir, 1, -2):match("(.*/)")
- for entry in lfs.dir(dir) do
- if entry and entry == 'config.lua' then
- return dir .. entry
- end
+ for entry in lfs.dir(dir) do
+ if entry and entry == 'config.lua' then
+ return dir .. entry
end
+ end
- return find_config(dir_parent)
-end
-
-function site.get_root(filepath)
- return find_config(filepath):match("(.*/)"):sub(1, -2)
-end
-
-function site.set_config(filepath)
- local site_root = site.get_root(filepath)
-
- package.path = package.path .. ';'.. site_root ..'/?.lua'
-
- return require 'config'
+ return site.get_config(dir_parent)
end
return site