ferron

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

commit df4e4b5dfbc455df82f6692ad33182ed3957df5f
parent cedab4d585c40c0aba5241ce0e2f6826a6827bce
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Mon, 17 Dec 2018 23:26:19 -0500

Remove dependencies + make some path tests

Diffstat:
MREADME.md | 2--
Mferron.lua | 1-
Mferron/config.lua | 1-
Mferron/site.lua | 4+++-
Mferron/static.lua | 57++++++++++++---------------------------------------------
5 files changed, 15 insertions(+), 50 deletions(-)

diff --git a/README.md b/README.md @@ -22,11 +22,9 @@ Ferron is a static site generator (SSG) crafted with Lua >= 5.3. ### Dependencies * [dkjson](https://luarocks.org/modules/dhkolf/dkjson) -* [lua-path](https://luarocks.org/modules/moteus/lua-path) * [LuaFileSysem](https://luarocks.org/modules/hisham/luafilesystem) * [lustache](https://luarocks.org/modules/olivine-labs/lustache) * [lua-discount](https://luarocks.org/modules/luarocks/lua-discount) -* [luaposix](https://luarocks.org/modules/gvvaughan/luaposix) * [mimetypes](https://luarocks.org/modules/luarocks/mimetypes) * [inspect](https://luarocks.org/modules/kikito/inspect) diff --git a/ferron.lua b/ferron.lua @@ -34,7 +34,6 @@ Ferron.build = { list.init, link.makeshorts, link.makerewritemap, - static.move, static.init, } diff --git a/ferron/config.lua b/ferron/config.lua @@ -21,7 +21,6 @@ local config = { "luafilesystem", "lustache", "lua-path", - "luaposix", "lua-discount", "dkjson", "etlua", diff --git a/ferron/site.lua b/ferron/site.lua @@ -4,7 +4,7 @@ local config = require "ferron.config" local tableutils = require "ferron.utilities.table-utils" local fileutils = require "ferron.utilities.file-utils" -local site = {} +local site = { site = nil } site.location = lfs.currentdir() .. "/" .. config.sites @@ -59,6 +59,8 @@ function site.setsite(name) Ferron.site = site.getsiteinfos((name ~= nil and name or sites_list[tonumber(whichsite)])) Ferron.site.config.baseurl = (Ferron.devmode == true and Ferron.site.config.urldev or Ferron.site.config.url) + site.site = Ferron.site + return Ferron.site end diff --git a/ferron/static.lua b/ferron/static.lua @@ -4,63 +4,30 @@ -- Required Packages local lfs = require "lfs" -local mimetypes = require 'mimetypes' local path = require "path" -local posix = require "posix" local fileutils = require "ferron.utilities.file-utils" local tableutils = require "ferron.utilities.table-utils" - --- Module Declaration +local site = require "ferron.site" local static = {} -function static.dispatch(file) - path.each( - path.dirname(file) .. "/*", "f", - function(f) - if fileutils.isNonTextual(f) then - local listindex_dirname = path.dirname(file) - local img = f - local htmlfolder = Ferron.site.path .. Ferron.site.config.paths.html - - if not posix.readlink(img) then - -- Copy content's images in the `public_html/` directory - path.copy(img, htmlfolder .. fileutils.getrelpath(img)) - - -- Then with those copies create symlinks from those - -- non-textuals for list index pages - 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 - end - end - end, - {recurse = true} - ) +local function dispatch(file) + return os.execute("cp -p " .. file .. " " .. Ferron.site.path .. Ferron.site.config.paths.html) end -function static.moveNonTextualToRoot(file) - local htmlfolder = Ferron.site.path .. Ferron.site.config.paths.html - - os.execute("cp -pv " .. file .. " " .. htmlfolder) - --print(file) -end - -function static.move() - -- Copy the entire `siteconfig.paths.static` folder in `siteconfig.paths.html` - path.copy( - Ferron.site.path .. Ferron.site.config.paths.static .. "/*", - Ferron.site.path .. Ferron.site.config.paths.html, - {recurse = true} - ) - - print("¤¤ Your site is ready at `" .. Ferron.site.path .. Ferron.site.config.paths.html .. "` ¤¤") +function move() + return os.execute("cp -Rp " .. Ferron.site.path .. Ferron.site.config.paths.static .. "/*" .. " " .. Ferron.site.path .. Ferron.site.config.paths.html) end function static.init() local contentpath = assert(fileutils.isDirectory(Ferron.site.path .. Ferron.site.config.paths.content)) - tableutils.each(static.moveNonTextualToRoot, tableutils.filter(fileutils.isNonTextual, tableutils.settable(fileutils.getdirtree(contentpath)))) + tableutils.each(dispatch, tableutils.filter(fileutils.isNonTextual, tableutils.settable(fileutils.getdirtree(contentpath)))) + move() + + print(inspect(site.site)) + print("¤¤ Your site is ready at `" .. Ferron.site.path .. Ferron.site.config.paths.html .. "` ¤¤") + + return end return static