ferron

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

commit 28e7874b1774bd6c69d042b26bc944399e22d61c
parent bccd0185fe25faf7a80a0e1d2ac85341e3324e5e
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Thu, 23 Aug 2018 10:37:54 -0400

Add and apply an empty directory funciton

Diffstat:
Mferron/static.lua | 10++++++----
Mferron/utilities/file-utils.lua | 31+++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/ferron/static.lua b/ferron/static.lua @@ -13,13 +13,15 @@ local tableutils = require "ferron.utilities.table-utils" -- Module Declaration local static = {} -function static.dispatch(file) - local mimestable = Ferron.site.siteconfig.mimetypes +local function removesymlinks() + -- Ferron.site.path .. Ferron.site.siteconfig.paths.content +end +function static.dispatch(file) path.each( path.dirname(file) .. "/*", "f", function(f) - if tableutils.hasvalue(mimestable, mimetypes.guess(f)) then + if fileutils.isNonTextual(f) then local listindex_dirname = path.dirname(file) local img = f local img_name = img:match("^.+/(.+)$") @@ -34,7 +36,7 @@ function static.dispatch(file) end -- Copy all non-textual contents (jpg, pdf, png, svg, etc.) to `public_html/` - if posix.readlink(img) then + if posix.readlink(img) then path.rename(img, htmlfolder .. img_relpath) end end diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua @@ -1,7 +1,17 @@ -- local lfs = require "lfs" +local path = require "path" +local mimetypes = require 'mimetypes' +local tableutils = require "ferron.utilities.table-utils" + local fileutils = {} +function fileutils.isNonTextual(file) + local mimestable = Ferron.site.siteconfig.mimetypes + + return (tableutils.hasvalue(mimestable, mimetypes.guess(file)) and true or false) +end + -- loadlocalconfig function fileutils.loadlocalconfig(file) local env = {} @@ -91,5 +101,26 @@ function fileutils.shorturlencode(num) return str end +function fileutils.emptydirectory(dirpath) + path.each( + dirpath .. "*", + function(P, mode) + if mode == 'directory' then + path.rmdir(P) + elseif P ~= dirpath .. ".gitignore" then + path.remove(P) + end + + return + end, + { + param = "fm"; -- request full path and mode + delay = true; -- use snapshot of directory + recurse = true; -- include subdirs + reverse = true; -- subdirs at first + } + ) +end + -- Export `fileutils` module return fileutils