ferron

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

commit 11813f83a1d7841448f6214ee0ba7d8688afdf05
parent 28e7874b1774bd6c69d042b26bc944399e22d61c
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Tue, 28 Aug 2018 10:12:03 -0400

Simplify `static` module, build symlinks directly in `public_html/`

Diffstat:
Mferron/static.lua | 70+++++++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/ferron/static.lua b/ferron/static.lua @@ -1,5 +1,5 @@ --[[ - Static Module + Static Module ]]-- -- Required Packages @@ -13,43 +13,43 @@ local tableutils = require "ferron.utilities.table-utils" -- Module Declaration local static = {} -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 fileutils.isNonTextual(f) then - local listindex_dirname = path.dirname(file) - local img = f - local img_name = img:match("^.+/(.+)$") - local img_relpath = fileutils.getrelpath(img) - local htmlfolder = Ferron.site.path .. Ferron.site.siteconfig.paths.html - - -- Then symlinks from those non-textuals for list index pages - if not posix.readlink(img) then - lfs.link("." .. img:sub((listindex_dirname):len() + 1), listindex_dirname .. "/" .. img_name, true) - - path.copy(img, htmlfolder .. img_relpath) - end - - -- Copy all non-textual contents (jpg, pdf, png, svg, etc.) to `public_html/` - if posix.readlink(img) then - path.rename(img, htmlfolder .. img_relpath) - end - end - end, - {recurse = true} - ) +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 img_name = img:match("^.+/(.+)$") + local img_relpath = fileutils.getrelpath(img) + local htmlfolder = Ferron.site.path .. Ferron.site.siteconfig.paths.html + + if not posix.readlink(img) then + -- Copy content's images in the `public_html/` directory + path.copy(img, htmlfolder .. img_relpath) + + -- Then with those copies create symlinks from those + -- non-textuals for list index pages + if path.isfile(htmlfolder .. img_relpath) then + lfs.link("." .. img:sub((listindex_dirname):len() + 1), + htmlfolder .. fileutils.getrelpath(path.dirname(file)) .. "/" .. img_name, true) + end + end + end + end, + {recurse = true} + ) end function static.move() - -- Copy the entire `siteconfig.paths.static` folder in `siteconfig.paths.html` - path.copy(Ferron.site.path .. Ferron.site.siteconfig.paths.static .. "/*", Ferron.site.path .. Ferron.site.siteconfig.paths.html, {recurse = true}) - - print("¤¤ Your site is ready at `" .. Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "` ¤¤") + -- Copy the entire `siteconfig.paths.static` folder in `siteconfig.paths.html` + path.copy( + Ferron.site.path .. Ferron.site.siteconfig.paths.static .. "/*", + Ferron.site.path .. Ferron.site.siteconfig.paths.html, + {recurse = true} + ) + + print("¤¤ Your site is ready at `" .. Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "` ¤¤") end return static