ferron

Ferron is a fast and simple static website generator made with Lua.
Log | Files | Refs | Submodules | README | LICENSE

commit 7e59cc2a8b60f0244c74da663d6ba4a188cbeff0
parent e9efbfeb3dc33f22c7fc38d3f8ebbd614a5df4a1
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date:   Mon, 10 Dec 2018 15:53:57 -0500

Replace path methods by custom ones

Diffstat:
Mferron/content.lua | 21++++-----------------
Mferron/feed.lua | 5++---
Mferron/link.lua | 4++--
Mferron/site.lua | 4++--
Mferron/static.lua | 2+-
Mferron/tag.lua | 2+-
Mferron/utilities/file-utils.lua | 6+++++-
Mferron/utilities/template-utils.lua | 2+-
8 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/ferron/content.lua b/ferron/content.lua @@ -16,7 +16,7 @@ function content.getarchetypes(dir) local archetypes = {} local archetypesdir = (dir ~= nil and dir or Ferron.site.path .. Ferron.site.config.paths.archetypes) - if path.isdir(archetypesdir) then + if fileutils.isDirectory(archetypesdir) then for archetype, attr in fileutils.getdirtree(archetypesdir) do if attr.mode ~= "directory" and archetype:match("^.+(%..+)$") == ".json" @@ -72,7 +72,7 @@ function content.makecontent(contenttype, contenttitle) archetype.datetime = os.date("%H:%M:%S") archetype.template = archetypetype - if not path.isdir(contentpath) then + if not fileutils.isDirectory(contentpath) then fileutils.mkdir(contentpath) end @@ -96,8 +96,8 @@ function content.makecontent(contenttype, contenttitle) ) ) - if path.isfile(contentpath .. archetype.filename .. ".md") - and path.isfile(contentpath .. archetype.filename .. ".json") + if fileutils.isFile(contentpath .. archetype.filename .. ".md") + and fileutils.isFile(contentpath .. archetype.filename .. ".json") then print("¤¤ The files `" .. contentpath .. "{" .. archetype.filename .. ".md," .. archetype.filename .. ".json}` have been created. ¤¤") else @@ -106,17 +106,4 @@ function content.makecontent(contenttype, contenttitle) end end -function content.getFiles() - local contentpath = assert(fileutils.isDirectory(Ferron.site.path .. Ferron.site.config.paths.content)) - - for file in fileutils.getdirtree(contentpath) do - if fileutils.isFile(file) then - table.insert(Ferron.files, file) - end - end - -- print(inspect(Ferron.files)) - -- os.exit("1") - return Ferron.files -end - return content diff --git a/ferron/feed.lua b/ferron/feed.lua @@ -1,5 +1,4 @@ -- -local path = require "path" local fileutils = require "ferron.utilities.file-utils" local tableutils = require "ferron.utilities.table-utils" local templateutils = require "ferron.utilities.template-utils" @@ -7,12 +6,12 @@ local feed = {} function feed.makefeed(entries, destination) local feedtypes = Ferron.site.config.feedtypes - local feedpartials = path.isdir(Ferron.site.path .. Ferron.site.config.paths.templates .. "/partials") + local feedpartials = fileutils.isDirectory(Ferron.site.path .. Ferron.site.config.paths.templates .. "/partials") for k, v in pairs(feedtypes) do local feedtemplate = Ferron.site.path .. Ferron.site.config.paths.templates .. "/feed/" .. k .. ".mustache" - if path.isfile(feedtemplate) then + if fileutils.isFile(feedtemplate) then fileutils.pushfilecontent( destination .. "/" .. v.name .. v.extension, templateutils.rendermustache( diff --git a/ferron/link.lua b/ferron/link.lua @@ -12,7 +12,7 @@ function link.makeshorts() local links_db = Ferron.site.path .. Ferron.site.config.paths.data .. "/shortlinks.json" -- If `links_db` dosen't exists create it - if path.isfile(links_db) == false then + if fileutils.isFile(links_db) == false then local counter = 0 fileutils.pushfilecontent(links_db, "") @@ -47,7 +47,7 @@ function link.makerewritemap() local links_db = Ferron.site.path .. Ferron.site.config.paths.data .. "/shortlinks.json" local links_map = Ferron.site.path .. Ferron.site.config.paths.html .. "/shortlinksmap.txt" - if path.isfile(links_db) then + if fileutils.isFile(links_db) then links = json.decode(fileutils.pullfilecontent(links_db)) if links then diff --git a/ferron/site.lua b/ferron/site.lua @@ -12,7 +12,7 @@ function site.listsites() local sites_list = {} for s in path.each(site.location .. "*", "f", {delay = true; reverse = true;}) do - if path.isdir(s) then + if fileutils.isDirectory(s) then sites_list[#sites_list+1] = s:match("^.+/(.+)$") end end @@ -79,7 +79,7 @@ function site.makesite() path.copy(newsite.sample .. "/*", path.mkdir(newsite.location), {delay = true; recurse = true}) - if path.isdir(newsite.location) then + if fileutils.isDirectory(newsite.location) then return print("Your new website is ready to be cutomize here '" .. newsite.location .. "'!") else return print("!! Error, something went wrong !") diff --git a/ferron/static.lua b/ferron/static.lua @@ -28,7 +28,7 @@ function static.dispatch(file) -- Then with those copies create symlinks from those -- non-textuals for list index pages - if path.isfile(htmlfolder .. fileutils.getrelpath(img)) then + if fileutils.isFile(htmlfolder .. fileutils.getrelpath(img)) then lfs.link("." .. img:sub((listindex_dirname):len() + 1), htmlfolder .. fileutils.getrelpath(path.dirname(file)) .. "/" .. path.basename(img), true) end diff --git a/ferron/tag.lua b/ferron/tag.lua @@ -43,7 +43,7 @@ function tag.maketagpage() tagurls = urls } - if path.isdir(htmlpath .. "/tag") == false then + if fileutils.isDirectory(htmlpath .. "/tag") == false then fileutils.mkdir(htmlpath .. "/tag") end diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua @@ -121,7 +121,7 @@ function fileutils.pushfilecontent(pathtofile, data) file:write(data) file:close() - return assert(path.isfile(pathtofile)) + return assert(fileutils.isFile(pathtofile)) end function fileutils.getrelpath(file) @@ -136,6 +136,10 @@ function fileutils.removeextension(file) return file:match("(.+)%..*") end +function fileutils.getextension(file) + return file:match("^.+(%..+)$") +end + function fileutils.getplainname(file) return fileutils.removeextension(file):match("^.+/(.+)$") end diff --git a/ferron/utilities/template-utils.lua b/ferron/utilities/template-utils.lua @@ -22,7 +22,7 @@ function templateutils.selecttemplate(index, templatename) end -- etlua or mustache -- etlua templates will outrank the mustache ones - return assert(path.isfile(template .. ".etlua") and template .. ".etlua" or template .. ".mustache", + return assert(fileutils.isFile(template .. ".etlua") and template .. ".etlua" or template .. ".mustache", "You need to add some templates to your site.") end