ferron

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

commit c3a79d9ff22b9853fdae55c7b3dc3112c14fe09d
parent cf8c3cc0ce44935860b70e3bc6855a4d6d45cd01
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date:   Fri,  2 Feb 2018 16:08:21 -0500

Refactor the site configuration calls.

Diffstat:
Mferron.lua | 11++++-------
Mferron/feed.lua | 12++++++------
Mferron/list.lua | 14+++++++-------
Mferron/page.lua | 12++++++------
Mferron/site.lua | 12++++++------
Mferron/static.lua | 12++++++------
Mferron/utilities/file-utils.lua | 4++--
Asites/ferron-ssg.tld/templates/rss2.mustache | 18++++++++++++++++++
8 files changed, 55 insertions(+), 40 deletions(-)

diff --git a/ferron.lua b/ferron.lua @@ -2,13 +2,13 @@ -- Ferron SSG -- --- Init the main module +-- Init the Main Namespace Ferron = {} -- Ferron's Modules local config = require "config" local site = require "ferron.site" -local archetype = require "ferron.archetype" +local content = require "ferron.content" local page = require "ferron.page" local list = require "ferron.list" local feed = require "ferron.feed" @@ -28,7 +28,6 @@ end Ferron.config = config Ferron.site = {} -Ferron.archetypes = {} Ferron.devmode = (arg[1] == "--dev" and true or false) if Ferron.devmode == true then @@ -38,8 +37,8 @@ end Ferron.init = { site.getsites, site.setsite, - archetype.getarchetypes, - archetype.createcontent + content.getarchetypes, + content.makecontent } Ferron.build = { @@ -50,5 +49,3 @@ Ferron.build = { } exec(Ferron.init, Ferron.build) - ---return Ferron diff --git a/ferron/feed.lua b/ferron/feed.lua @@ -7,15 +7,15 @@ local feed = {} function feed.makefeed() local feed_tb = {} - local feedtemplate = path.isfile(Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/feed.mustache") - local feedrsstemplate = path.isfile(Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/rss2.mustache") - local feedpartials = path.isdir(Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials") - local feedfile = Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. "/feed.atom.xml" - local feedrssfile = Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. "/feed.rss.xml" + local feedtemplate = path.isfile(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/feed.mustache") + local feedrsstemplate = path.isfile(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/rss2.mustache") + local feedpartials = path.isdir(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials") + local feedfile = Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "/feed.atom.xml" + local feedrssfile = Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "/feed.rss.xml" print("§ Make an ATOM feed with all the pages of the site ...") - feed_tb["SITE"] = Ferron.site.config.SITE + feed_tb["site"] = Ferron.site.siteconfig feed_tb["entries"] = {} for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do diff --git a/ferron/list.lua b/ferron/list.lua @@ -31,7 +31,7 @@ local function sortentries(entries_tb, list_mt) end local function setentries(directory, list_mt) - local contentpath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT + local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content local entries_tb = {} path.each( @@ -59,7 +59,7 @@ local function setentries(directory, list_mt) end function list.makelist() - local contentpath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT + local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content path.each( contentpath .. "/*.md", @@ -78,9 +78,9 @@ function list.makelist() -- Convert the markdown file to HTML list_conf_mt.content = markdown(fileutils.pullfilecontent(list)) -- Set a dynamic permalink - list_conf_mt.permalink = Ferron.site.config.SITE.BASEURL .. path.dirname(list_relpath) + list_conf_mt.permalink = Ferron.site.siteconfig.baseurl .. path.dirname(list_relpath) -- Import site configuration in the metatable - list_conf_mt["SITE"] = Ferron.site.config.SITE + list_conf_mt["site"] = Ferron.site.siteconfig -- Set a table for the list of entries list_conf_mt["entries"] = {} @@ -97,8 +97,8 @@ function list.makelist() fileutils.pushfilecontent( list_htmlpath .. "/" .. list_plainname .. ".html", templateutils.setmustache( - fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/" .. list_conf.template .. ".mustache"), - Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", + fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/" .. list_conf.template .. ".mustache"), + Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials", list_conf_mt ) ) @@ -111,7 +111,7 @@ function list.makelist() -- Update the JSON file data list_conf["entries"] = nil - list_conf["SITE"] = nil + list_conf["site"] = nil fileutils.pushfilecontent(list_noextension .. ".json", json.encode(list_conf, {indent = true, keyorder = {"bridgy","cite","citeurl","content","date","datetime","description","id","keywords","permalink","section","template","title","updated"}})) end diff --git a/ferron/page.lua b/ferron/page.lua @@ -8,7 +8,7 @@ local templateutils = require "ferron.utilities.template-utils" local page = {} function page.makepage() - local contentpath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT + local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content -- Loop in the content directory print("- Looking for markdown in " .. contentpath .. " ...") @@ -27,15 +27,15 @@ function page.makepage() local page_key = page_conf.date .. "|" .. page_conf.datetime .. "|" .. page_relpath page_conf.updated = os.date("%Y-%m-%dT%H:%M:%S", path.mtime(page)) - page_conf.id = "tag:" .. Ferron.site.config.SITE.DOMAINNAME .. "," .. page_conf.date .. ":" .. string.sub(page_conf.date, 0, 4) .. "/" .. string.sub(page_conf.date, 6, 7) .. "/" .. page_plainname + page_conf.id = "tag:" .. Ferron.site.siteconfig.domainname .. "," .. page_conf.date .. ":" .. string.sub(page_conf.date, 0, 4) .. "/" .. string.sub(page_conf.date, 6, 7) .. "/" .. page_plainname -- Convert the markdown file to HTML -- And put it in a metatable page_conf_mt.content = markdown(fileutils.pullfilecontent(page)) - page_conf_mt.permalink = Ferron.site.config.SITE.BASEURL .. (page_plainname ~= "index" and page_relpath .. ".html" or "") + page_conf_mt.permalink = Ferron.site.siteconfig.baseurl .. (page_plainname ~= "index" and page_relpath .. ".html" or "") page_conf_mt.section = nil - page_conf_mt["SITE"] = Ferron.site.config.SITE + page_conf_mt["site"] = Ferron.site.siteconfig Ferron.site.pagestable[page_key] = page_conf_mt @@ -47,8 +47,8 @@ function page.makepage() fileutils.pushfilecontent( page_htmlpath .. "/" .. page_plainname .. ".html", templateutils.setmustache( - fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/" .. page_conf.template .. ".mustache"), - Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", + fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/" .. page_conf.template .. ".mustache"), + Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials", page_conf_mt ) ) diff --git a/ferron/site.lua b/ferron/site.lua @@ -12,18 +12,17 @@ function site.getsites() for s in path.each(Ferron.config.paths.sites .. "/*", "f", {delay = true; reverse = true;}) do if path.isdir(s) then -- Load site configuration - local siteconfig, siteconfig_err = fileutils.loadlocalconfig(s .. "/site.config.lua") + local s_config, s_config_err = fileutils.loadlocalconfig(s .. "/site-config.lua") -- Create a table with the basic infos of the site sites_tb[s:match("^.+/(.+)$")] = { path = s, - config = siteconfig, - pagestable = {} + siteconfig = s_config["siteconfig"], + pagestable = {}, } -- Create a simple array with the name of the sites sites_list[#sites_list+1] = s:match("^.+/(.+)$") - end end @@ -48,8 +47,9 @@ function site.setsite() until (tableutils.haskey(sites_list, tonumber(whichsite))) == true Ferron.site = sites_tb[sites_list[tonumber(whichsite)]] - Ferron.site.config.SITE.BASEURL = (Ferron.devmode == true and Ferron.site.config.SITE.URLDEV or Ferron.site.config.SITE.URL) - Ferron.site.config.SITE.PREFETCHLIST = {} + Ferron.site.siteconfig.baseurl = (Ferron.devmode == true and Ferron.site.siteconfig.urldev or Ferron.site.siteconfig.url) + Ferron.site.siteconfig.prefetchlist = {} + return Ferron.site end diff --git a/ferron/static.lua b/ferron/static.lua @@ -13,8 +13,8 @@ local tableutils = require "ferron.utilities.table-utils" local static = {} function static.dispatch(file) - local mimestable = Ferron.site.config.SITE.MIMETYPES - local prefetchedtable = Ferron.site.config.SITE.PREFETCHLIST + local mimestable = Ferron.site.siteconfig.mimetypes + local prefetchedtable = Ferron.site.siteconfig.prefetchlist path.each( path.dirname(file) .. "/*", "f", @@ -24,7 +24,7 @@ function static.dispatch(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 + local htmlfolder = Ferron.site.path .. Ferron.site.siteconfig.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) @@ -40,10 +40,10 @@ function static.dispatch(file) 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}) + -- 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.config.SITE.PATHS.HTML .. "` ¤¤") + print("¤¤ Your site is ready at `" .. Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "` ¤¤") end return static diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua @@ -71,11 +71,11 @@ function fileutils.pushfilecontent(pathtofile, data) end function fileutils.getrelpath(file) - return file:sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT):len() + 1) + return file:sub((Ferron.site.path .. Ferron.site.siteconfig.paths.content):len() + 1) end function fileutils.sethtmlpath(folder) - return Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. folder + return Ferron.site.path .. Ferron.site.siteconfig.paths.html .. folder end function fileutils.shorturlencode(num) diff --git a/sites/ferron-ssg.tld/templates/rss2.mustache b/sites/ferron-ssg.tld/templates/rss2.mustache @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<rss version="2.0"> + <channel> + <title>RSS Feed of {{{ site.domainname }}}</title> + <description>{{{ site.metas.description }}}</description> + <lastBuildDate>{{{ lastupdate }}}Z</lastBuildDate> + <link>{{{ site.url }}}</link> + + {{# entries }} + <item> + <!-- <title></title> --> + <description>{{ content }}</description> + <pubDate>{{ updated }}Z</pubDate> + <link>{{{ permalink }}}</link> + </item> + {{/ entries }} + </channel> +</rss>