ferron

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

commit 4209408025b881a210a1b71f491cd37c074297d5
parent 476aa3dbb0400ddbe72136c354876a2b28f80aca
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sat, 29 Dec 2018 22:35:54 -0500

Replace Ferron.site. by site.

Diffstat:
Mferron/content.lua | 10+++++-----
Mferron/feed.lua | 6+++---
Mferron/link.lua | 10+++++-----
Mferron/list.lua | 22+++++++++++-----------
Mferron/page.lua | 34+++++++++++++---------------------
Mferron/static.lua | 8++++----
Mferron/tag.lua | 12++++++------
7 files changed, 47 insertions(+), 55 deletions(-)

diff --git a/ferron/content.lua b/ferron/content.lua @@ -14,7 +14,7 @@ local content = {} function content.getarchetypes(dir) local archetypes = {} - local archetypesdir = (dir ~= nil and dir or site.paths.archetypes) + local archetypesdir = (dir ~= nil and dir or site.archetypes) if fileutils.isDirectory(archetypesdir) then for archetype, attr in fileutils.getdirtree(archetypesdir) do @@ -63,8 +63,8 @@ function content.makecontent(contenttype, contenttitle) if tableutils.hasvalue(content.getarchetypes(), archetypetype) and type(title) == "string" then local archetype = {} - local contentpath = site.paths.content .. "/" .. archetypetype .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/" - local archetypepath = site.paths.archetypes .. "/" + local contentpath = site.content .. "/" .. archetypetype .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/" + local archetypepath = site.archetypes .. "/" archetype.title = title archetype.filename = slugify(archetype.title) @@ -81,7 +81,7 @@ function content.makecontent(contenttype, contenttitle) contentpath .. archetype.filename .. ".md", templateutils.rendermustache( fileutils.pullfilecontent(archetypepath .. archetypetype .. ".md" ), - site.paths.templates .. "/partials", + site.templates .. "/partials", archetype ) ) @@ -91,7 +91,7 @@ function content.makecontent(contenttype, contenttitle) contentpath .. archetype.filename .. ".json", templateutils.rendermustache( fileutils.pullfilecontent(archetypepath .. archetypetype .. ".json"), - site.paths.templates .. "/partials", + site.templates .. "/partials", archetype ) ) diff --git a/ferron/feed.lua b/ferron/feed.lua @@ -6,11 +6,11 @@ local site = require "ferron.site" local feed = {} function feed.makefeed(entries, destination) - local feedtypes = Ferron.site.config.feedtypes - local feedpartials = fileutils.isDirectory(site.paths.templates .. "/partials") + local feedtypes = site.config.feedtypes + local feedpartials = fileutils.isDirectory(site.templates .. "/partials") for k, v in pairs(feedtypes) do - local feedtemplate = site.paths.templates .. "/feed/" .. k .. ".mustache" + local feedtemplate = site.templates .. "/feed/" .. k .. ".mustache" if fileutils.isFile(feedtemplate) then fileutils.pushfilecontent( diff --git a/ferron/link.lua b/ferron/link.lua @@ -9,7 +9,7 @@ local link = {} function link.makeshorts() local links = {} local links_keyorder = {} - local links_db = site.paths.data .. "/shortlinks.json" + local links_db = site.data .. "/shortlinks.json" -- If `links_db` dosen't exists create it if fileutils.isFile(links_db) == false then @@ -17,7 +17,7 @@ function link.makeshorts() fileutils.pushfilecontent(links_db, "") - for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do + for k, v in tableutils.sortdescendingpairs(site.pagestable) do if v.rellink ~= "" then counter = counter + 1 @@ -31,7 +31,7 @@ function link.makeshorts() else links = json.decode(fileutils.pullfilecontent(links_db)) - for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do + for k, v in tableutils.sortdescendingpairs(site.pagestable) do if v.rellink ~= "" and links[v.rellink] == nil then table.insert(links_keyorder, v.rellink) @@ -44,8 +44,8 @@ function link.makeshorts() end function link.makerewritemap() - local links_db = site.paths.data .. "/shortlinks.json" - local links_map = site.paths.html .. "/shortlinksmap.txt" + local links_db = site.data .. "/shortlinks.json" + local links_map = site.html .. "/shortlinksmap.txt" if fileutils.isFile(links_db) then links = json.decode(fileutils.pullfilecontent(links_db)) diff --git a/ferron/list.lua b/ferron/list.lua @@ -36,10 +36,10 @@ local function setentries(directory, list_mt) tableutils.each( function(entry) - local entry_metadatas = json.decode(fileutils.pullfilecontent(fileutils.removeextension(entry) .. ".json")) - local entry_key = entry_metadatas.date .. "|" .. entry_metadatas.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(entry)) + local entry_metadatas = fileutils.getpageconf(entry) + local entry_key = entry_metadatas.date .. "|" .. entry_metadatas.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(entry), site) - entries_tb[entry_key] = Ferron.site.pagestable[entry_key] + entries_tb[entry_key] = site.pagestable[entry_key] end, tableutils.filter(fileutils.isNotIndex, tableutils.settable(fileutils.getdirtree(directory))) ) @@ -51,18 +51,18 @@ end function list.render(listsource) local list = listsource - local list_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(list))) - local list_conf = json.decode(fileutils.pullfilecontent(fileutils.removeextension(list) .. ".json")) + local list_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(list), site), site) + local list_conf = fileutils.getpageconf(list) local list_conf_mt = setmetatable({}, { __index = list_conf }) - print("§ Make a list page for the `" .. fileutils.getrelpath(fileutils.getdirname(list)) .. "` subdirectory ...") + print("§ Make a list page for the `" .. fileutils.getrelpath(fileutils.getdirname(list), site) .. "` subdirectory ...") -- 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.baseurl .. fileutils.getdirname(fileutils.getrelpath(fileutils.removeextension(list))) + list_conf_mt.permalink = site.config.baseurl .. fileutils.getdirname(fileutils.getrelpath(fileutils.removeextension(list), site)) -- Import site configuration in the metatable - list_conf_mt["site"] = Ferron.site.config + list_conf_mt["site"] = site.config -- Set a table for the list of entries list_conf_mt["entries"] = {} @@ -87,15 +87,15 @@ function list.render(listsource) fileutils.pushfilecontent( list_htmlpath .. "/" .. fileutils.getplainname(list) .. ".html", templateutils.rendertemplate( - templateutils.selecttemplate(false, list_conf.template), + templateutils.selecttemplate(false, list_conf.template, site), list_conf_mt, - site.paths.templates .. "/partials" + site.templates .. "/partials" ) ) end function list.init() - local contentpath = assert(fileutils.isDirectory(site.paths.content)) + local contentpath = assert(fileutils.isDirectory(site.content)) tableutils.each(list.render, tableutils.filter(fileutils.isIndex, tableutils.settable(fileutils.getdirtree(contentpath)))) diff --git a/ferron/page.lua b/ferron/page.lua @@ -7,32 +7,25 @@ local templateutils = require "ferron.utilities.template-utils" local site = require "ferron.site" local page = {} -local getpageconf = function(page) - local conflua = fileutils.isFile(fileutils.removeextension(page) .. ".lua") - local confjson = fileutils.isFile(fileutils.removeextension(page) .. ".json") - - print(conflua) -end - function page.render(pagesource) local page = pagesource - local page_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(page))) - local page_conf = json.decode(fileutils.pullfilecontent(fileutils.removeextension(page) .. ".json")) + local page_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(page), site), site) + local page_conf = fileutils.getpageconf(page) local page_conf_mt = setmetatable({}, { __index = page_conf }) - local page_key = page_conf.date .. "|" .. page_conf.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(page)) + local page_key = page_conf.date .. "|" .. page_conf.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(page), site) -- Set some dynamic configuration properties page_conf_mt.content = markdown(fileutils.pullfilecontent(page)) page_conf_mt.updated = os.date("%Y-%m-%dT%H:%M:%S", lfs.attributes(page).modification) - page_conf_mt.permalink = Ferron.site.config.baseurl .. (fileutils.getplainname(page) ~= "index" and fileutils.getrelpath(fileutils.removeextension(page)) .. ".html" or "") - page_conf_mt.rellink = (fileutils.getplainname(page) ~= "index" and fileutils.getrelpath(fileutils.removeextension(page)) .. ".html" or "") - page_conf_mt["site"] = Ferron.site.config + page_conf_mt.permalink = site.config.baseurl .. (fileutils.getplainname(page) ~= "index" and fileutils.getrelpath(fileutils.removeextension(page), site) .. ".html" or "") + page_conf_mt.rellink = (fileutils.getplainname(page) ~= "index" and fileutils.getrelpath(fileutils.removeextension(page), site) .. ".html" or "") + page_conf_mt["site"] = site.config if page_conf.id == nil then - page_conf_mt.id = "tag:" .. Ferron.site.config.domainname .. "," .. page_conf.date .. ":" .. string.sub(page_conf.date, 0, 4) .. "/" .. string.sub(page_conf.date, 6, 7) .. "/" .. fileutils.getplainname(page) + page_conf_mt.id = "tag:" .. site.config.domainname .. "," .. page_conf.date .. ":" .. string.sub(page_conf.date, 0, 4) .. "/" .. string.sub(page_conf.date, 6, 7) .. "/" .. fileutils.getplainname(page) end - Ferron.site.pagestable[page_key] = page_conf_mt + site.pagestable[page_key] = page_conf_mt -- If the ancestors of the page dosen't exists make it if not fileutils.isDirectory(page_htmlpath) then @@ -43,26 +36,25 @@ function page.render(pagesource) fileutils.pushfilecontent( page_htmlpath .. "/" .. fileutils.getplainname(page) .. ".html", templateutils.rendertemplate( - templateutils.selecttemplate(false, page_conf.template), + templateutils.selecttemplate(false, page_conf.template, site), page_conf_mt, - assert(fileutils.isDirectory(site.paths.templates)) .. "/partials" + assert(fileutils.isDirectory(site.templates)) .. "/partials" ) ) --print(page) - getpageconf(page) return end function page.init() - local contentpath = assert(fileutils.isDirectory(site.paths.content)) + local contentpath = assert(fileutils.isDirectory(site.content)) tableutils.each(page.render, tableutils.filter(fileutils.isNotIndex, tableutils.settable(fileutils.getdirtree(contentpath)))) print("==========") - print("§ " .. tableutils.length(Ferron.site.pagestable) .. " HTML pages have been created.") + print("§ " .. tableutils.length(site.pagestable) .. " HTML pages have been created.") print("==========") - return --print(inspect(Ferron.site.pagestable)) + return --print(inspect(site.pagestable)) end return page diff --git a/ferron/static.lua b/ferron/static.lua @@ -10,17 +10,17 @@ local site = require "ferron.site" local static = {} local function dispatchnontextual(file) - return os.execute("cp -p " .. file .. " " .. site.paths.html) + return os.execute("cp -p " .. file .. " " .. site.html) end local function movestaticfolder() - return os.execute("cp -Rp " .. site.paths.static .. "/*" .. " " .. site.paths.html) + return os.execute("cp -Rp " .. site.static .. "/*" .. " " .. site.html) end function static.init() - local contentpath = assert(fileutils.isDirectory(site.paths.content)) + local contentpath = assert(fileutils.isDirectory(site.content)) - print("¤¤ Your site is ready at `" .. site.paths.html .. "` ¤¤") + print("¤¤ Your site is ready at `" .. site.html .. "` ¤¤") return movestaticfolder(), tableutils.each(dispatchnontextual, tableutils.filter(fileutils.isNonTextual, tableutils.settable(fileutils.getdirtree(contentpath)))) diff --git a/ferron/tag.lua b/ferron/tag.lua @@ -8,7 +8,7 @@ local tag = {} local function maketagstable() local tagstable = {} - local pages = Ferron.site.pagestable + local pages = site.pagestable for k, page in pairs(pages) do if page.keywords ~= nil then @@ -42,16 +42,16 @@ function tag.maketagpage() tagurls = urls } - if fileutils.isDirectory(site.paths.html .. "/tag") == false then - fileutils.mkdir(site.paths.html .. "/tag") + if fileutils.isDirectory(site.html .. "/tag") == false then + fileutils.mkdir(site.html .. "/tag") end -- Build the HTML file fileutils.pushfilecontent( - site.paths.html .. "/tag/" .. tag .. ".html", + site.html .. "/tag/" .. tag .. ".html", templateutils.rendermustache( - fileutils.pullfilecontent(site.paths.templates .. "/tag.mustache"), - site.paths.templates .. "/partials", + fileutils.pullfilecontent(site.templates .. "/tag.mustache"), + site.templates .. "/partials", tag_tb ) )