commit ae6c48bf6f86fd79dbe03b36e92cd1dd331bd735
parent 4209408025b881a210a1b71f491cd37c074297d5
Author: Hugo Soucy <hugo@soucy.cc>
Date: Sat, 29 Dec 2018 22:46:17 -0500
Remove Ferron. calls
Diffstat:
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua
@@ -1,6 +1,8 @@
--
+local json = require "dkjson"
local lfs = require "lfs"
-local mimetypes = require 'mimetypes'
+local mimetypes = require "mimetypes"
+local config = require "ferron.config"
local tableutils = require "ferron.utilities.table-utils"
local fileutils = {}
@@ -60,7 +62,7 @@ function fileutils.isNotIndex(filepath)
end
function fileutils.isNonTextual(file)
- local mimestable = Ferron.site.config.mimetypes
+ local mimestable = config.mimetypes
return (tableutils.hasvalue(mimestable, mimetypes.guess(file)) and true or false)
end
@@ -123,12 +125,12 @@ function fileutils.pushfilecontent(pathtofile, data)
return assert(fileutils.isFile(pathtofile))
end
-function fileutils.getrelpath(file)
- return file:sub((Ferron.site.path .. Ferron.site.config.paths.content):len() + 1)
+function fileutils.getrelpath(file, site)
+ return file:sub((site.path .. site.config.paths.content):len() + 1)
end
-function fileutils.sethtmlpath(folder)
- return Ferron.site.path .. Ferron.site.config.paths.html .. folder
+function fileutils.sethtmlpath(folder, site)
+ return site.path .. site.config.paths.html .. folder
end
function fileutils.removeextension(file)
@@ -147,6 +149,21 @@ function fileutils.getdirname(file)
return file:match("(.*/)")
end
+function fileutils.getpageconf(pagepath)
+ local pageconf = nil
+ local conflua = fileutils.isFile(fileutils.removeextension(pagepath) .. ".lua")
+ local confjson = fileutils.isFile(fileutils.removeextension(pagepath) .. ".json")
+
+ if conflua then
+ package.path = package.path .. ";" .. fileutils.getdirname(conflua) .. "/?.lua"
+ pageconf = require(fileutils.getplainname(conflua))
+ elseif confjson then
+ pageconf = json.decode(fileutils.pullfilecontent(confjson))
+ end
+
+ return pageconf
+end
+
function fileutils.shorturlencode(num)
local alphabet = "23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ-_"
local base = alphabet:len()
diff --git a/ferron/utilities/template-utils.lua b/ferron/utilities/template-utils.lua
@@ -6,8 +6,8 @@ local fileutils = require "ferron.utilities.file-utils"
local templateutils = {}
-- set template
-function templateutils.selecttemplate(index, templatename)
- local templatepath = Ferron.site.path .. Ferron.site.config.paths.templates .. "/"
+function templateutils.selecttemplate(index, templatename, site)
+ local templatepath = site.path .. site.config.paths.templates .. "/"
local template = nil
if templatename ~= nil and type(templatename) == "string" then