ferron

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

commit ea08df6c676cb58508d677782e092d7d87efc08f
parent f459ca3fbdb3849715384038f043c9f736d2f529
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Wed, 31 Jan 2018 22:23:26 -0500

Refactoring modules.

Diffstat:
Mferron.lua | 11+++++------
Aferron/archetypes.lua | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dferron/create-archetype-content.lua | 55-------------------------------------------------------
Dferron/dispatch-nontextuals.lua | 35-----------------------------------
Dferron/get-archetypes.lua | 21---------------------
Mferron/make-lists-of-pages.lua | 4++--
Dferron/move-to-publichtml.lua | 11-----------
Aferron/static.lua | 42++++++++++++++++++++++++++++++++++++++++++
8 files changed, 121 insertions(+), 130 deletions(-)

diff --git a/ferron.lua b/ferron.lua @@ -9,14 +9,13 @@ local Ferron = Ferron -- Ferron submodules local config = require("config") +local archetypes = require("ferron.archetypes") local getsites = require("ferron.get-sites") -local getarchetypes = require("ferron.get-archetypes") local setsite = require("ferron.set-site") -local createarchetypecontent = require("ferron.create-archetype-content") local makepages = require("ferron.make-pages") local makelistsofpages = require("ferron.make-lists-of-pages") local makeatomfeed = require("ferron.make-atom-feed") -local movetopublichtml = require("ferron.move-to-publichtml") +local static = require("ferron.static") local exec = require("ferron.exec") inspect = require("inspect") @@ -31,15 +30,15 @@ Ferron.devmode = (arg[1] == "--dev" and true or false) Ferron.initfunctions = { getsites, setsite, - getarchetypes, - createarchetypecontent + archetypes.get, + archetypes.createcontent } Ferron.buildfunctions = { makepages, makelistsofpages, makeatomfeed, - movetopublichtml + static.move } exec(Ferron.initfunctions, Ferron.buildfunctions) diff --git a/ferron/archetypes.lua b/ferron/archetypes.lua @@ -0,0 +1,72 @@ +-- +local path = require("path") +local fileutils = require("ferron.file-utils") +local tableutils = require("ferron.table-utils") +local templateutils = require("ferron.template-utils") +local archetypes = {} + +function archetypes.get() + local archetypesdir = Ferron.site.path .. Ferron.site.config.SITE.PATHS.ARCHETYPES + + if path.isdir(archetypesdir) then + for archetype, attr in fileutils.getdirtree(archetypesdir) do + if attr.mode ~= "directory" + and archetype:match("^.+(%..+)$") == ".json" + then + Ferron.archetypes[#Ferron.archetypes+1] = archetype:match("^.+/(.+)$"):match("(.+)%..*") + end + end + + return Ferron.archetypes + end +end + +function archetypes.createcontent() + if tableutils.hasvalue(Ferron.archetypes, arg[1]) and type(arg[2]) == "string" then + local archetype = {} + local contentpath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/" .. arg[1] .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/" + local archetypepath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.ARCHETYPES .. "/" + + archetype.title = arg[2] + archetype.filename = string.lower(archetype.title:gsub('%p','-'):gsub('%s','-')) + archetype.date = os.date("%Y-%m-%d") + archetype.datetime = os.date("%H:%M:%S") + archetype.template = arg[1] + + if path.isdir(contentpath) == false then + fileutils.mkdir(contentpath) + end + + -- Build the markdown file + fileutils.pushfilecontent( + contentpath .. archetype.filename .. ".md", + templateutils.setmustache( + fileutils.pullfilecontent(archetypepath .. arg[1] .. ".md" ), + Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", + archetype + ) + ) + + -- Build the JSON file + fileutils.pushfilecontent( + contentpath .. archetype.filename .. ".json", + templateutils.setmustache( + fileutils.pullfilecontent(archetypepath .. arg[1] .. ".json"), + Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", + archetype + ) + ) + + if path.isfile(contentpath .. archetype.filename .. ".md") + and path.isfile(contentpath .. archetype.filename .. ".json") + then + print("¤¤ The files `" .. contentpath .. "{" .. archetype.filename .. ".md," .. archetype.filename .. ".json}` have been created. ¤¤") + else + print("! Error, something went wrong !") + end + + os.exit() + end +end + +return archetypes diff --git a/ferron/create-archetype-content.lua b/ferron/create-archetype-content.lua @@ -1,55 +0,0 @@ --- -local path = require("path") -local fileutils = require("ferron.file-utils") -local tableutils = require("ferron.table-utils") -local templateutils = require("ferron.template-utils") - -local function createarchetypecontent() - if tableutils.hasvalue(Ferron.archetypes, arg[1]) and type(arg[2]) == "string" then - local archetype = {} - local contentpath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/" .. arg[1] .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/" - local archetypepath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.ARCHETYPES .. "/" - - archetype.title = arg[2] - archetype.filename = string.lower(archetype.title:gsub('%p','-'):gsub('%s','-')) - archetype.date = os.date("%Y-%m-%d") - archetype.datetime = os.date("%H:%M:%S") - archetype.template = arg[1] - - if path.isdir(contentpath) == false then - fileutils.mkdir(contentpath) - end - - -- Build the markdown file - fileutils.pushfilecontent( - contentpath .. archetype.filename .. ".md", - templateutils.setmustache( - fileutils.pullfilecontent(archetypepath .. arg[1] .. ".md" ), - Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", - archetype - ) - ) - - -- Build the JSON file - fileutils.pushfilecontent( - contentpath .. archetype.filename .. ".json", - templateutils.setmustache( - fileutils.pullfilecontent(archetypepath .. arg[1] .. ".json"), - Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", - archetype - ) - ) - - if path.isfile(contentpath .. archetype.filename .. ".md") - and path.isfile(contentpath .. archetype.filename .. ".json") - then - print("¤¤ The files `" .. contentpath .. "{" .. archetype.filename .. ".md," .. archetype.filename .. ".json}` have been created. ¤¤") - else - print("! Error, something went wrong !") - end - - os.exit() - end -end - -return createarchetypecontent diff --git a/ferron/dispatch-nontextuals.lua b/ferron/dispatch-nontextuals.lua @@ -1,35 +0,0 @@ --- -local lfs = require("lfs") -local mimetypes = require('mimetypes') -local path = require("path") -local fileutils = require("ferron.file-utils") -local tableutils = require("ferron.table-utils") - -local function dispatchnontextuals(file) - local mimestable = Ferron.site.config.SITE.MIMETYPES - local prefetchedtable = Ferron.site.config.SITE.PREFETCHLIST - - path.each( - path.dirname(file) .. "/*", "f", - function(f) - if tableutils.hasvalue(mimestable, mimetypes.guess(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.config.SITE.PATHS.HTML - - -- Then symlinks from those non-textuals for list index pages - lfs.link("." .. img:sub((listindex_dirname):len() + 1), listindex_dirname .. "/" .. img_name, true) - - -- Copy all non-textual contents (jpg, pdf, png, svg, etc.) to `public_html/` - path.copy(img, htmlfolder .. img_relpath) - - prefetchedtable[#prefetchedtable + 1] = img_relpath - end - end, - {recurse = true} - ) -end - -return dispatchnontextuals diff --git a/ferron/get-archetypes.lua b/ferron/get-archetypes.lua @@ -1,21 +0,0 @@ --- -local path = require("path") -local fileutils = require("ferron.file-utils") - -local function getarchetypes() - local archetypesdir = Ferron.site.path .. Ferron.site.config.SITE.PATHS.ARCHETYPES - - if path.isdir(archetypesdir) then - for archetype, attr in fileutils.getdirtree(archetypesdir) do - if attr.mode ~= "directory" - and archetype:match("^.+(%..+)$") == ".json" - then - Ferron.archetypes[#Ferron.archetypes+1] = archetype:match("^.+/(.+)$"):match("(.+)%..*") - end - end - - return Ferron.archetypes - end -end - -return getarchetypes diff --git a/ferron/make-lists-of-pages.lua b/ferron/make-lists-of-pages.lua @@ -5,7 +5,7 @@ local path = require("path") local fileutils = require("ferron.file-utils") local tableutils = require("ferron.table-utils") local templateutils = require("ferron.template-utils") -local dispatchnontextuals = require("ferron.dispatch-nontextuals") +local static = require("ferron.static") local function makelistsofpages() local contentpath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT @@ -87,7 +87,7 @@ local function makelistsofpages() fileutils.mkdir(listindex_htmlpath) end - dispatchnontextuals(listindex) + static.dispatch(listindex) -- Build the HTML file fileutils.pushfilecontent( diff --git a/ferron/move-to-publichtml.lua b/ferron/move-to-publichtml.lua @@ -1,11 +0,0 @@ --- -local path = require("path") - -local function movetopublichtml() - -- Copy the entire `SITE.PATHS.STATIC` folder in `SITE.PATHS.HTML` - path.copy(Ferron.site.path .. Ferron.site.config.SITE.PATHS.STATIC .. "/*", Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML, {recurse = true}) - - print("¤¤ Your site is ready at `" .. Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. "` ¤¤") -end - -return movetopublichtml diff --git a/ferron/static.lua b/ferron/static.lua @@ -0,0 +1,42 @@ +local lfs = require("lfs") +local mimetypes = require('mimetypes') +local path = require("path") +local fileutils = require("ferron.file-utils") +local tableutils = require("ferron.table-utils") +local static = {} + +function static.dispatch(file) + local mimestable = Ferron.site.config.SITE.MIMETYPES + local prefetchedtable = Ferron.site.config.SITE.PREFETCHLIST + + path.each( + path.dirname(file) .. "/*", "f", + function(f) + if tableutils.hasvalue(mimestable, mimetypes.guess(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.config.SITE.PATHS.HTML + + -- Then symlinks from those non-textuals for list index pages + lfs.link("." .. img:sub((listindex_dirname):len() + 1), listindex_dirname .. "/" .. img_name, true) + + -- Copy all non-textual contents (jpg, pdf, png, svg, etc.) to `public_html/` + path.copy(img, htmlfolder .. img_relpath) + + prefetchedtable[#prefetchedtable + 1] = img_relpath + end + end, + {recurse = true} + ) +end + +function static.move() + -- Copy the entire `SITE.PATHS.STATIC` folder in `SITE.PATHS.HTML` + path.copy(Ferron.site.path .. Ferron.site.config.SITE.PATHS.STATIC .. "/*", Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML, {recurse = true}) + + print("¤¤ Your site is ready at `" .. Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. "` ¤¤") +end + +return static