ferron

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

commit de24d68ed5374f25036878b40bd807dc7f2a215f
parent f2888389d1e26703f596cfbb9c485f3409f4a0b3
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Fri, 24 Nov 2017 20:32:16 -0500

Add dispatchnontextuals

Diffstat:
Afunctions/dispatch-nontextuals.lua | 35+++++++++++++++++++++++++++++++++++
Mfunctions/make-lists-of-pages.lua | 6+++++-
2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/functions/dispatch-nontextuals.lua b/functions/dispatch-nontextuals.lua @@ -0,0 +1,35 @@ +-- +local lfs = require("lfs") +local mimetypes = require('mimetypes') +local path = require("path") +local tableutils = require("functions.table-utils") + +local function dispatchnontextuals(file, filesection) + local mimestable = {"image/svg+xml", "image/jpeg", "image/png"} + + -- Create symlinks for images in section's landing page + path.each( + path.dirname(file) .. "/*", "f", + function(f) + if tableutils.hasvalue(mimestable, mimetypes.guess(f)) then + local img = f + local img_section = filesection + local img_relpath + local img_html = Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. "/" .. img_section .. img:sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/" .. img_section):len() + 1) + + -- lfs.link("." .. img:sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/" .. img_section):len() + 1), + -- path.dirname(file) .. "/" .. img:match("^.+/(.+)$"), true) + + --print(img_section .. img:sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/" .. img_section):len() + 1)) + --print(path.dirname(file) .. "/" .. img:match("^.+/(.+)$")) + --print(img_section) + ---print(img) + + path.copy(img, img_html) + end + end, + {recurse = true} + ) +end + +return dispatchnontextuals diff --git a/functions/make-lists-of-pages.lua b/functions/make-lists-of-pages.lua @@ -5,6 +5,7 @@ local path = require("path") local fileutils = require("functions.file-utils") local tableutils = require("functions.table-utils") local templateutils = require("functions.template-utils") +local dispatchnontextuals = require("functions.dispatch-nontextuals") local function makelistsofpages() for file, attr in fileutils.getdirtree(Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT) do @@ -15,12 +16,12 @@ local function makelistsofpages() local listindex = file local listindex_plainname = listindex:match("^.+/(.+)$"):match("(.+)%..*") local listindex_section = path.dirname(listindex):match("^.+/(.+)$") - local listindex_table = {} local listindex_metadatas = json.decode(fileutils.pullfilecontent(listindex:match("(.+)%..*") .. ".json")) local listindex_relpath = listindex:match("(.+)%..*"):sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT):len() + 1) local listindex_relpathfolder = (path.dirname(listindex):sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT):len() + 1)) local listindex_pathhtml = Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. listindex_relpathfolder local listindex_html = listindex_pathhtml .. "/" .. listindex_plainname .. ".html" + local listindex_table = {} print("ยง Make an index page for the `" .. listindex_section .. "` section:") @@ -39,10 +40,13 @@ local function makelistsofpages() end end + if path.isdir(listindex_pathhtml) == false then fileutils.mkdir(listindex_pathhtml) end + dispatchnontextuals(listindex, listindex_section) + -- Build the HTML file fileutils.pushfilecontent( listindex_html,