commit faec6382b1e0075109ac7ce0882fdd286f5b74ca
parent f41e1503232cee47d2e4edce9783c679f9434aee
Author: Hugo Soucy <hs0ucy@users.noreply.github.com>
Date: Fri, 19 Apr 2019 10:51:05 -0400
Merge pull request #4 from hs0ucy/refactoring_fev2019
Refactoring fev2019
Diffstat:
18 files changed, 297 insertions(+), 271 deletions(-)
diff --git a/cornelius b/cornelius
@@ -3,33 +3,33 @@
-- Cornelius Ferron is the CLI of Ferron SSG and it's a WIP.
-- <https://en.wikipedia.org/wiki/Cornelius_the_First>
-local config = require "ferron.config"
+local config = require 'ferron.config'
-if arg[1] == "install" and tonumber(_VERSION:match("%d+%.%d+")) >= config.dependencies.lua then
+if arg[1] == 'install' and tonumber(_VERSION:match('%d+%.%d+')) >= config.dependencies.lua then
-- First, check if luarocks is present in the env.
- if pcall(require, "luarocks.loader") then
+ if pcall(require, 'luarocks.loader') then
-- Then install each dependency from the main configuration
for i, dependency in ipairs(config.dependencies.modules) do
- os.execute ("luarocks install --tree lua_modules " .. dependency)
+ os.execute ('luarocks install --tree lua_modules ' .. dependency)
end
else
- print("Ferron needs Luarocks for installing his dependencies.")
- print("Please install it on your system https://luarocks.org/.")
+ print('Ferron needs Luarocks for installing his dependencies.')
+ print('Please install it on your system https://luarocks.org/.')
end
-elseif arg[1] == "build" and arg[2] == "--dev" then
- os.execute("lua -l ferron.setpaths ferron.lua --dev")
-elseif arg[1] == "build" then
- os.execute("lua -l ferron.setpaths ferron.lua")
-elseif arg[1] == "create" then
- os.execute("lua -l ferron.setpaths ferron.lua --set content")
-elseif arg[1] == "start" then
- os.execute("lua -l ferron.setpaths ferron.lua --make site")
-elseif arg[1] == "plugin" and type(arg[2]) == "string" and arg[2] ~= "" then
- os.execute("lua -l ferron.setpaths ferron.lua --run " .. arg[2])
+elseif arg[1] == 'build' and arg[2] == '--dev' then
+ os.execute('lua -l ferron.setpaths ferron.lua --dev')
+elseif arg[1] == 'build' then
+ os.execute('lua -l ferron.setpaths ferron.lua')
+elseif arg[1] == 'create' then
+ os.execute('lua -l ferron.setpaths ferron.lua --set content')
+elseif arg[1] == 'start' then
+ os.execute('lua -l ferron.setpaths ferron.lua --make site')
+elseif arg[1] == 'plugin' and type(arg[2]) == 'string' and arg[2] ~= '' then
+ os.execute('lua -l ferron.setpaths ferron.lua --run ' .. arg[2])
else
print("Hi, I'm Cornelius Ferron, the eminence of the great horn of the static site generator... or if you prefer, the CLI.")
- print("What Can I Do for You?")
+ print('What Can I Do for You?')
print([[Your options are:
* `install` - Install Ferron and his dependencies
* `start` - Create a new website from the sample repository
diff --git a/ferron.lua b/ferron.lua
@@ -1 +1 @@
-return require "ferron.init"
+return require 'ferron.init'
diff --git a/ferron/app.lua b/ferron/app.lua
@@ -8,9 +8,9 @@ local appmeta = {
function app.exec(...)
for argkey, argval in pairs({...}) do
- if type(argval) == "table" then
+ if type(argval) == 'table' then
for funckey, funcval in ipairs(argval) do
- if type(funcval) == "function" then
+ if type(funcval) == 'function' then
funcval()
end
end
diff --git a/ferron/config.lua b/ferron/config.lua
@@ -4,52 +4,52 @@
return {
source = {
- url = "https://github.com/hs0ucy/ferron-ssg"
+ url = 'https://github.com/hs0ucy/ferron-ssg'
},
description = {
- homepage = "https://github.com/hs0ucy/Ferron",
- license = "MIT"
+ homepage = 'https://github.com/hs0ucy/Ferron',
+ license = 'MIT'
},
- sites = "sites/",
+ sites = 'sites/',
-- Ferron Dependencies
dependencies = {
lua = 5.3,
modules = {
- "luafilesystem",
- "lustache",
- "lua-discount",
- "dkjson",
- "inspect",
- "mimetypes"
+ 'luafilesystem',
+ 'lustache',
+ 'lua-discount',
+ 'dkjson',
+ 'inspect',
+ 'mimetypes'
}
},
feedtypes = {
atom = {
- name = "feed.atom",
- extension = ".xml",
+ name = 'feed.atom',
+ extension = '.xml',
},
rss2 = {
- name = "feed.rss2",
- extension = ".xml",
+ name = 'feed.rss2',
+ extension = '.xml',
},
json = {
- name = "feed",
- extension = ".json",
+ name = 'feed',
+ extension = '.json',
},
},
-- Accepted mime types of the non-textual content
mimetypes = {
- "image/svg+xml",
- "image/gif",
- "image/jpeg",
- "image/png",
- "application/pdf",
+ 'image/svg+xml',
+ 'image/gif',
+ 'image/jpeg',
+ 'image/png',
+ 'application/pdf',
},
- metaskeyorder = {"bridgy","content","date","datetime","description","id","keywords","permalink","shortlink","template","title"},
+ metaskeyorder = {'bridgy','content','date','datetime','description','id','keywords','permalink','shortlink','template','title'},
}
diff --git a/ferron/content.lua b/ferron/content.lua
@@ -10,10 +10,10 @@ local contentmeta = {
}
-- Required Packages
-local fileutils = require "ferron.utilities.file-utils"
-local slugify = require "ferron.utilities.lua-slugify.slugify"
-local tableutils = require "ferron.utilities.table-utils"
-local templateutils = require "ferron.utilities.template-utils"
+local fileutils = require 'ferron.utilities.file-utils'
+local slugify = require 'ferron.utilities.lua-slugify.slugify'
+local tableutils = require 'ferron.utilities.table-utils'
+local templateutils = require 'ferron.utilities.template-utils'
function content.getarchetypes(dir)
local archetypes = {}
@@ -21,10 +21,10 @@ function content.getarchetypes(dir)
if fileutils.isDirectory(archetypesdir) then
for archetype, attr in fileutils.getdirtree(archetypesdir) do
- if attr.mode ~= "directory"
- and archetype:match("^.+(%..+)$") == ".json"
+ if attr.mode ~= 'directory'
+ and archetype:match('^.+(%..+)$') == '.json'
then
- archetypes[#archetypes+1] = archetype:match("^.+/(.+)$"):match("(.+)%..*")
+ archetypes[#archetypes+1] = archetype:match('^.+/(.+)$'):match('(.+)%..*')
end
end
@@ -38,24 +38,24 @@ function content.setcontent()
local whichtitle = nil
repeat
- io.write("Which archetypes do you need to complete your request? \n")
+ io.write('Which archetypes do you need to complete your request? \n')
for k, v in ipairs(archetypes) do
- io.write(k .. ") " .. v .. "\n")
+ io.write(k .. ') ' .. v .. '\n')
end
- io.write("Please enter the number... \n")
+ io.write('Please enter the number... \n')
io.flush()
whicharchetype=io.read()
until (tableutils.haskey(archetypes, tonumber(whicharchetype))) == true
repeat
- io.write("Please write the title of your new content... \n")
+ io.write('Please write the title of your new content... \n')
io.flush()
whichtitle=io.read()
- until (type(tostring(whichtitle))) == "string"
+ until (type(tostring(whichtitle))) == 'string'
return content.makecontent(archetypes[tonumber(whicharchetype)], tostring(whichtitle))
end
@@ -64,15 +64,15 @@ function content.makecontent(contenttype, contenttitle)
local archetypetype = contenttype or arg[1]
local title = contenttitle or arg[2]
- if tableutils.hasvalue(content.getarchetypes(), archetypetype) and type(title) == "string" then
+ if tableutils.hasvalue(content.getarchetypes(), archetypetype) and type(title) == 'string' then
local archetype = {}
- local contentpath = Ferron.site.content .. "/" .. archetypetype .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/"
- local archetypepath = Ferron.site.archetypes .. "/"
+ local contentpath = Ferron.site.content .. '/' .. archetypetype .. '/' .. os.date('%Y') ..'/'..os.date('%m') .. '/'
+ local archetypepath = Ferron.site.archetypes .. '/'
archetype.title = title
archetype.filename = slugify(archetype.title)
- archetype.date = os.date("%Y-%m-%d")
- archetype.datetime = os.date("%H:%M:%S")
+ archetype.date = os.date('%Y-%m-%d')
+ archetype.datetime = os.date('%H:%M:%S')
archetype.template = archetypetype
if not fileutils.isDirectory(contentpath) then
@@ -81,30 +81,30 @@ function content.makecontent(contenttype, contenttitle)
-- Build the markdown file
fileutils.pushfilecontent(
- contentpath .. archetype.filename .. ".md",
+ contentpath .. archetype.filename .. '.md',
templateutils.rendermustache(
- fileutils.pullfilecontent(archetypepath .. archetypetype .. ".md" ),
- Ferron.site.templates .. "/partials",
+ fileutils.pullfilecontent(archetypepath .. archetypetype .. '.md' ),
+ Ferron.site.templates .. '/partials',
archetype
)
)
-- Build the JSON file
fileutils.pushfilecontent(
- contentpath .. archetype.filename .. ".json",
+ contentpath .. archetype.filename .. '.json',
templateutils.rendermustache(
- fileutils.pullfilecontent(archetypepath .. archetypetype .. ".json"),
- Ferron.site.templates .. "/partials",
+ fileutils.pullfilecontent(archetypepath .. archetypetype .. '.json'),
+ Ferron.site.templates .. '/partials',
archetype
)
)
- if fileutils.isFile(contentpath .. archetype.filename .. ".md")
- and fileutils.isFile(contentpath .. archetype.filename .. ".json")
+ if fileutils.isFile(contentpath .. archetype.filename .. '.md')
+ and fileutils.isFile(contentpath .. archetype.filename .. '.json')
then
- print("¤¤ The files `" .. contentpath .. "{" .. archetype.filename .. ".md," .. archetype.filename .. ".json}` have been created. ¤¤")
+ print('¤¤ The files `' .. contentpath .. '{' .. archetype.filename .. '.md,' .. archetype.filename .. '.json}` have been created. ¤¤')
else
- print("! Error, something went wrong !")
+ print('! Error, something went wrong !')
end
end
end
diff --git a/ferron/feed.lua b/ferron/feed.lua
@@ -6,20 +6,20 @@ local feedmeta = {
end
}
-local fileutils = require "ferron.utilities.file-utils"
-local tableutils = require "ferron.utilities.table-utils"
-local templateutils = require "ferron.utilities.template-utils"
+local fileutils = require 'ferron.utilities.file-utils'
+local tableutils = require 'ferron.utilities.table-utils'
+local templateutils = require 'ferron.utilities.template-utils'
function feed.makefeed(entries, destination)
local feedtypes = Ferron.site.config.feedtypes
- local feedpartials = fileutils.isDirectory(Ferron.site.templates .. "/partials")
+ local feedpartials = fileutils.isDirectory(Ferron.site.templates .. '/partials')
for k, v in pairs(feedtypes) do
- local feedtemplate = Ferron.site.templates .. "/feed/" .. k .. ".mustache"
+ local feedtemplate = Ferron.site.templates .. '/feed/' .. k .. '.mustache'
if fileutils.isFile(feedtemplate) then
fileutils.pushfilecontent(
- destination .. "/" .. v.name .. v.extension,
+ destination .. '/' .. v.name .. v.extension,
templateutils.rendermustache(
fileutils.pullfilecontent(feedtemplate),
feedpartials,
@@ -27,7 +27,7 @@ function feed.makefeed(entries, destination)
)
)
else
- print("*** Warning! The `" .. feedtemplate .. "` template is missing!")
+ print('*** Warning! The `' .. feedtemplate .. '` template is missing!')
end
end
end
diff --git a/ferron/init.lua b/ferron/init.lua
@@ -3,26 +3,26 @@
--
-- Required Modules
-inspect = require "inspect"
-
-local lfs = require "lfs"
-local config = require "ferron.config"
-local site = require "ferron.site"
-local content = require "ferron.content"
-local page = require "ferron.page"
-local list = require "ferron.list"
-local link = require "ferron.link"
-local static = require "ferron.static"
-local plugin = require "ferron.plugin"
-local app = require "ferron.app"
+inspect = require 'inspect'
+
+local lfs = require 'lfs'
+local config = require 'ferron.config'
+local site = require 'ferron.site'
+local content = require 'ferron.content'
+local page = require 'ferron.page'
+local list = require 'ferron.list'
+local link = require 'ferron.link'
+local static = require 'ferron.static'
+local plugin = require 'ferron.plugin'
+local app = require 'ferron.app'
-- App's Globals
-- Init the main namespace
Ferron = {
- devmode = (arg[1] == "--dev" and true or false),
+ devmode = (arg[1] == '--dev' and true or false),
site = {
- location = lfs.currentdir() .. "/" .. config.sites,
+ location = lfs.currentdir() .. '/' .. config.sites,
config = nil,
path = nil,
pagestable = {},
@@ -44,15 +44,15 @@ Ferron = {
},
}
-if arg[1] == "--set" and arg[2] == "content" then
+if arg[1] == '--set' and arg[2] == 'content' then
return content.setcontent(site.setsite())
end
-if arg[1] == "--make" and arg[2] == "site" then
+if arg[1] == '--make' and arg[2] == 'site' then
return site.startsite()
end
-if arg[1] == "--run" and type(arg[2]) == "string" and arg[2] ~= "" then
+if arg[1] == '--run' and type(arg[2]) == 'string' and arg[2] ~= '' then
return plugin.run(site.setsite(), arg[2])
end
diff --git a/ferron/link.lua b/ferron/link.lua
@@ -7,24 +7,24 @@ local linkmeta = {
}
-- @TODO Make sure to always keep the alphanumerical order
-local json = require "dkjson"
-local fileutils = require "ferron.utilities.file-utils"
-local tableutils = require "ferron.utilities.table-utils"
-local templateutils = require "ferron.utilities.template-utils"
+local json = require 'dkjson'
+local fileutils = require 'ferron.utilities.file-utils'
+local tableutils = require 'ferron.utilities.table-utils'
+local templateutils = require 'ferron.utilities.template-utils'
function link.makeshorts()
local links = {}
local links_keyorder = {}
- local links_db = Ferron.site.data .. "/shortlinks.json"
+ local links_db = Ferron.site.data .. '/shortlinks.json'
-- If `links_db` dosen't exists create it
if fileutils.isFile(links_db) == false then
local counter = 0
- fileutils.pushfilecontent(links_db, "")
+ fileutils.pushfilecontent(links_db, '')
for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do
- if v.rellink ~= "" then
+ if v.rellink ~= '' then
counter = counter + 1
table.insert(links_keyorder, v.rellink)
@@ -38,7 +38,7 @@ function link.makeshorts()
links = json.decode(fileutils.pullfilecontent(links_db))
for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do
- if v.rellink ~= "" and links[v.rellink] == nil then
+ if v.rellink ~= '' and links[v.rellink] == nil then
table.insert(links_keyorder, v.rellink)
links[v.rellink] = fileutils.shorturlencode(tableutils.length(links) + 1)
@@ -50,21 +50,21 @@ function link.makeshorts()
end
function link.makerewritemap()
- local links_db = Ferron.site.data .. "/shortlinks.json"
- local links_map = Ferron.site.html .. "/shortlinksmap.txt"
+ local links_db = Ferron.site.data .. '/shortlinks.json'
+ local links_map = Ferron.site.html .. '/shortlinksmap.txt'
if fileutils.isFile(links_db) then
links = json.decode(fileutils.pullfilecontent(links_db))
if links then
-- Create an empty map file
- fileutils.pushfilecontent(links_map, "")
+ fileutils.pushfilecontent(links_map, '')
-- Open it
- map, map_err = io.open(links_map, "a")
+ map, map_err = io.open(links_map, 'a')
for k, v in pairs(links) do
- map:write(v .. " " .. k, "\n")
+ map:write(v .. ' ' .. k, '\n')
end
-- Close it when it's done
diff --git a/ferron/list.lua b/ferron/list.lua
@@ -6,13 +6,16 @@ local listmeta = {
end
}
-local json = require "dkjson"
-local markdown = require "discount"
-local fileutils = require "ferron.utilities.file-utils"
-local tableutils = require "ferron.utilities.table-utils"
-local templateutils = require "ferron.utilities.template-utils"
-local feed = require "ferron.feed"
-local static = require "ferron.static"
+
+local json = require 'dkjson'
+local markdown = require 'discount'
+local fileutils = require 'ferron.utilities.file-utils'
+local tableutils = require 'ferron.utilities.table-utils'
+local templateutils = require 'ferron.utilities.template-utils'
+local feed = require 'ferron.feed'
+local static = require 'ferron.static'
+
+print(page)
local function sortentries(entries_tb, list_mt)
local list_length = list_mt.length or nil
@@ -21,18 +24,18 @@ local function sortentries(entries_tb, list_mt)
if entries_count then
for k, v in tableutils.sortdescendingpairs(entries_tb) do
if entries_count < list_length then
- table.insert(list_mt["entries"], v)
+ table.insert(list_mt['entries'], v)
entries_count = entries_count + 1
end
end
else
for k, v in tableutils.sortdescendingpairs(entries_tb) do
- table.insert(list_mt["entries"], v)
+ table.insert(list_mt['entries'], v)
end
end
- return list_mt["entries"]
+ return list_mt['entries']
end
local function setentries(directory, list_mt)
@@ -41,16 +44,16 @@ local function setentries(directory, list_mt)
tableutils.each(
function(entry)
local entry_metadatas = fileutils.getpageconf(entry)
- local entry_key = entry_metadatas.date .. "|" .. entry_metadatas.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(entry))
+ local entry_key = entry_metadatas.date .. 'T' .. entry_metadatas.datetime .. ':' .. fileutils.getrelpath(fileutils.removeextension(entry))
entries_tb[entry_key] = Ferron.site.pagestable[entry_key]
end,
- tableutils.filter(fileutils.isNotIndex, tableutils.settable(fileutils.getdirtree(directory)))
+ tableutils.filter(fileutils.isNotIndex, tableutils.from(fileutils.getdirtree(directory)))
)
sortentries(entries_tb, list_mt)
- return list_mt["entries"]
+ return list_mt['entries']
end
function list.render(listsource)
@@ -59,18 +62,18 @@ function list.render(listsource)
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)) .. '` 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)))
-- Import site configuration in the metatable
- list_conf_mt["site"] = Ferron.site.config
+ list_conf_mt['site'] = Ferron.site.config
-- Import site navigation in the metatable
- list_conf_mt["navigation"] = Ferron.site.navigation
+ list_conf_mt['navigation'] = Ferron.site.navigation
-- Set a table for the list of entries
- list_conf_mt["entries"] = {}
+ list_conf_mt['entries'] = {}
-- Set and get entries of the list
setentries(fileutils.getdirname(list), list_conf_mt)
@@ -87,15 +90,15 @@ function list.render(listsource)
-- Move static files in the public HTML folder
-- static.dispatch(list)
- print("==========")
+ print('==========')
-- Build and push the HTML page
fileutils.pushfilecontent(
- list_htmlpath .. "/" .. fileutils.getplainname(list) .. ".html",
+ list_htmlpath .. '/' .. fileutils.getplainname(list) .. '.html',
templateutils.rendertemplate(
templateutils.selecttemplate(false, list_conf.template),
list_conf_mt,
- Ferron.site.templates .. "/partials"
+ Ferron.site.templates .. '/partials'
)
)
end
@@ -103,7 +106,7 @@ end
function list.init()
local contentpath = assert(fileutils.isDirectory(Ferron.site.content))
- tableutils.each(list.render, tableutils.filter(fileutils.isIndex, tableutils.settable(fileutils.getdirtree(contentpath))))
+ tableutils.each(list.render, tableutils.filter(fileutils.isIndex, tableutils.from(fileutils.getdirtree(contentpath))))
return
end
diff --git a/ferron/page.lua b/ferron/page.lua
@@ -6,63 +6,79 @@ local pagemeta = {
end
}
-local json = require "dkjson"
-local markdown = require "discount"
-local fileutils = require "ferron.utilities.file-utils"
-local tableutils = require "ferron.utilities.table-utils"
-local templateutils = require "ferron.utilities.template-utils"
+local json = require 'dkjson'
+local markdown = require 'discount'
+local fileutils = require 'ferron.utilities.file-utils'
+local tableutils = require 'ferron.utilities.table-utils'
+local templateutils = require 'ferron.utilities.template-utils'
-function page.render(pagesource)
- local page = pagesource
- local page_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(page)))
- 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 function setpagetable(meta, relpath)
+ local pagekey = meta.date .. 'T' .. meta.datetime .. ':' .. relpath
- -- 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["navigation"] = Ferron.site.navigation
+ Ferron.site.pagestable[pagekey] = meta
- 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)
- end
+ return
+end
- Ferron.site.pagestable[page_key] = page_conf_mt
+local function setmetaprops(pagesource, relpath)
+ return {
+ content = markdown(fileutils.pullfilecontent(pagesource)),
+ navigation = Ferron.site.navigation,
+ permalink = Ferron.site.config.baseurl .. (fileutils.getplainname(pagesource) ~= 'index' and relpath .. '.html' or ''),
+ rellink = (fileutils.getplainname(pagesource) ~= 'index' and relpath .. '.html' or ''),
+ site = Ferron.site.config,
+ updated = os.date('%Y-%m-%dT%H:%M:%S', lfs.attributes(pagesource).modification),
+ id = 'tag:' .. Ferron.site.config.domainname .. ',' .. fileutils.getpageconf(pagesource).date .. ':' .. relpath,
+ }
+end
+
+function page.render(pagesource)
+ local page = pagesource
+ local pathRel = fileutils.getrelpath(fileutils.removeextension(page))
+ local pathToHtml = fileutils.sethtmlpath(fileutils.getrelpath(fileutils.getdirname(page)))
+ local metaTable = setmetatable(
+ setmetaprops(page, pathRel), {__index = fileutils.getpageconf(page)}
+ )
+
+ -- Populate Ferron.site.pagestable{}
+ setpagetable(metaTable, pathRel)
-- If the ancestors of the page dosen't exists make it
- if not fileutils.isDirectory(page_htmlpath) then
- fileutils.mkdir(page_htmlpath)
+ if not fileutils.isDirectory(pathToHtml) then
+ fileutils.mkdir(pathToHtml)
end
-- Build and push the HTML page
fileutils.pushfilecontent(
- page_htmlpath .. "/" .. fileutils.getplainname(page) .. ".html",
+ -- Create that page
+ pathToHtml .. '/' .. fileutils.getplainname(page) .. '.html',
+ -- With that mustache template
templateutils.rendertemplate(
- templateutils.selecttemplate(false, page_conf.template),
- page_conf_mt,
- assert(fileutils.isDirectory(Ferron.site.templates)) .. "/partials"
+ templateutils.selecttemplate(false, metaTable.template),
+ metaTable,
+ assert(fileutils.isDirectory(Ferron.site.templates)) .. '/partials'
)
)
- print(page_conf.date .. " - " .. page_conf.title)
-
- return true
+ return print(metaTable.date .. ' - ' .. metaTable.title)
end
function page.init()
local contentpath = assert(fileutils.isDirectory(Ferron.site.content))
- tableutils.each(page.render, tableutils.filter(fileutils.isNotIndex, tableutils.settable(fileutils.getdirtree(contentpath))))
+ tableutils.each(
+ page.render,
+ tableutils.filter(
+ fileutils.isNotIndex,
+ tableutils.from(fileutils.getdirtree(contentpath))
+ )
+ )
- print("==========")
- print("§ " .. tableutils.length(Ferron.site.pagestable) .. " HTML pages have been created.")
- print("==========")
+ print('==========')
+ print('§ ' .. tableutils.length(Ferron.site.pagestable) .. ' HTML pages have been created.')
+ print('==========')
- return --print(inspect(Ferron.site.pagestable))
+ return
end
return setmetatable(page, pagemeta)
diff --git a/ferron/plugin.lua b/ferron/plugin.lua
@@ -6,10 +6,10 @@ local pluginmeta = {
end
}
-local fileutils = require "ferron.utilities.file-utils"
+local fileutils = require 'ferron.utilities.file-utils'
function plugin.run(site, plugname)
- local plugin = require(Ferron.site.config.sites .. fileutils.getbasename(Ferron.site.path) .. Ferron.site.config.paths.plugins .. "/" .. plugname)
+ local plugin = require(Ferron.site.config.sites .. fileutils.getbasename(Ferron.site.path) .. Ferron.site.config.paths.plugins .. '/' .. plugname)
return plugin.init(site)
end
diff --git a/ferron/setpaths.lua b/ferron/setpaths.lua
@@ -1,5 +1,5 @@
-- setpaths.lua
-local version = _VERSION:match("%d+%.%d+")
+local version = _VERSION:match('%d+%.%d+')
package.path = 'lua_modules/share/lua/' .. version .. '/?.lua;lua_modules/share/lua/' .. version .. '/?/init.lua;' .. package.path
package.cpath = 'lua_modules/lib/lua/' .. version .. '/?.so;' .. package.cpath
diff --git a/ferron/site.lua b/ferron/site.lua
@@ -6,10 +6,10 @@ local sitemeta = {
end
}
-local lfs = require "lfs"
-local config = require "ferron.config"
-local tableutils = require "ferron.utilities.table-utils"
-local fileutils = require "ferron.utilities.file-utils"
+local lfs = require 'lfs'
+local config = require 'ferron.config'
+local tableutils = require 'ferron.utilities.table-utils'
+local fileutils = require 'ferron.utilities.file-utils'
function site.getsitelist(siteslocation)
local location = siteslocation or Ferron.site.location
@@ -17,23 +17,23 @@ function site.getsitelist(siteslocation)
local siteslist = tableutils.map(
function(site, i)
if fileutils.isDirectory(location .. site)
- and site ~= "."
- and site ~= ".."
+ and site ~= '.'
+ and site ~= '..'
then
return site
end
end,
- tableutils.settable(lfs.dir(location))
+ tableutils.from(lfs.dir(location))
)
return siteslist
end
function site.getsiteconfig(sitename)
- package.path = package.path .. ";sites/".. sitename .."/?.lua"
+ package.path = package.path .. ';sites/'.. sitename ..'/?.lua'
- return require "config"
+ return require 'config'
end
function site.setsite(sitename)
@@ -42,13 +42,13 @@ function site.setsite(sitename)
if #siteslist > 1 and not sitename then
repeat
- io.write("For which website do you want to proceed? \n")
+ io.write('For which website do you want to proceed? \n')
for k, v in ipairs(siteslist) do
- io.write(k .. ") " .. v .. "\n")
+ io.write(k .. ') ' .. v .. '\n')
end
- io.write("Please enter the number... \n")
+ io.write('Please enter the number... \n')
io.flush()
whichsite=io.read()
@@ -84,11 +84,11 @@ function site.setnavigation(contentlocation)
if meta.navigation then
local label = meta.navigation.label and meta.navigation.label or meta.title
- local location = Ferron.site.config.baseurl .. fileutils.removeextension(fileutils.getrelpath(f)) .. ".html"
+ local location = Ferron.site.config.baseurl .. fileutils.removeextension(fileutils.getrelpath(f)) .. '.html'
local attributes = meta.navigation.attributes
local order = meta.navigation.order
- if fileutils.getbasename(location) == "index.html" then
+ if fileutils.getbasename(location) == 'index.html' then
location = fileutils.getdirname(location)
end
@@ -96,7 +96,7 @@ function site.setnavigation(contentlocation)
end
end,
-- The data table
- tableutils.filter(fileutils.isMarkdown, tableutils.settable(fileutils.getdirtree(location)))
+ tableutils.filter(fileutils.isMarkdown, tableutils.from(fileutils.getdirtree(location)))
)
-- It's a dumb way to sort but it works for now.
@@ -130,12 +130,12 @@ function site.startsite(samplelocation)
name = nil,
location = nil,
config = nil,
- sample = Ferron.site.location .. "ferron-ssg.tld",
+ sample = Ferron.site.location .. 'ferron-ssg.tld',
}
local location = samplelocation or newsite.sample
- io.write("How do you want names your new website? \n")
- io.write("Please enter that name below... \n")
+ io.write('How do you want names your new website? \n')
+ io.write('Please enter that name below... \n')
io.flush()
newsite.name = io.read()
@@ -143,12 +143,12 @@ function site.startsite(samplelocation)
fileutils.mkdir(newsite.location)
- os.execute("cp -Rp " .. location .. "/*" .. " " .. newsite.location)
+ os.execute('cp -Rp ' .. location .. '/*' .. ' ' .. newsite.location)
if fileutils.isDirectory(newsite.location) then
- return print("Your new website is ready to be cutomize here '" .. newsite.location .. "'!")
+ return print('Your new website is ready to be cutomize here "' .. newsite.location .. '"!')
else
- return print("!! Error, something went wrong !")
+ return print('!! Error, something went wrong !')
end
end
@@ -157,30 +157,34 @@ function site.sitereset(htmllocation)
local location = htmllocation or Ferron.site.html
local function removefiles(dir)
local ok, errormsg
- -- remove files from directory
- for file in lfs.dir(dir) do
- if file == "." or file == ".." or file == ".gitignore" then -- skip system files
- -- do nothing
- else
- local thefile = dir.."/"..file
-
- if lfs.attributes(thefile, "mode") == "directory" then
- removefiles(thefile)
- else
- ok, errormsg = os.remove(thefile)
-
- if not ok then
- print("Error removing file: "..file..":"..errormsg)
+
+ tableutils.each(
+ function(file)
+ if file ~= '.'
+ and file ~= '..'
+ and file ~= '.gitignore'
+ then
+ local thefile = dir..'/'..file
+
+ if lfs.attributes(thefile, 'mode') == 'directory' then
+ removefiles(thefile)
+ else
+ ok, errormsg = os.remove(thefile)
+
+ if not ok then
+ print('Error removing file: '..file..':'..errormsg)
+ end
end
end
- end
- end
+ end,
+ tableutils.from(lfs.dir(dir))
+ )
-- remove directory
ok, errormsg = os.remove(dir)
if not ok then
- print("Can't removing directory: "..dir..":"..errormsg)
+ print('Can\'t removing directory: '..dir..':'..errormsg)
end
end
diff --git a/ferron/static.lua b/ferron/static.lua
@@ -7,24 +7,24 @@ local staticmeta = {
}
-- Required Packages
-local fileutils = require "ferron.utilities.file-utils"
-local tableutils = require "ferron.utilities.table-utils"
+local fileutils = require 'ferron.utilities.file-utils'
+local tableutils = require 'ferron.utilities.table-utils'
local function dispatchnontextual(file)
- return os.execute("cp -p " .. file .. " " .. Ferron.site.html)
+ return os.execute('cp -p ' .. file .. ' ' .. Ferron.site.html)
end
local function movestaticfolder()
- return os.execute("cp -Rp " .. Ferron.site.static .. "/*" .. " " .. Ferron.site.html)
+ return os.execute('cp -Rp ' .. Ferron.site.static .. '/*' .. ' ' .. Ferron.site.html)
end
function static.init()
local contentpath = assert(fileutils.isDirectory(Ferron.site.content))
- print("¤¤ Your site is ready at `" .. Ferron.site.html .. "` ¤¤")
+ print('¤¤ Your site is ready at `' .. Ferron.site.html .. '` ¤¤')
return movestaticfolder(),
- tableutils.each(dispatchnontextual, tableutils.filter(fileutils.isNonTextual, tableutils.settable(fileutils.getdirtree(contentpath))))
+ tableutils.each(dispatchnontextual, tableutils.filter(fileutils.isNonTextual, tableutils.from(fileutils.getdirtree(contentpath))))
end
return setmetatable(static, staticmeta)
diff --git a/ferron/tag.lua b/ferron/tag.lua
@@ -6,10 +6,10 @@ local tagmeta = {
end
}
-local json = require "dkjson"
-local fileutils = require "ferron.utilities.file-utils"
-local tableutils = require "ferron.utilities.table-utils"
-local templateutils = require "ferron.utilities.template-utils"
+local json = require 'dkjson'
+local fileutils = require 'ferron.utilities.file-utils'
+local tableutils = require 'ferron.utilities.table-utils'
+local templateutils = require 'ferron.utilities.template-utils'
local function maketagstable()
local tagstable = {}
@@ -47,16 +47,16 @@ function tag.maketagpage()
tagurls = urls
}
- if fileutils.isDirectory(Ferron.site.html .. "/tag") == false then
- fileutils.mkdir(Ferron.site.html .. "/tag")
+ if fileutils.isDirectory(Ferron.site.html .. '/tag') == false then
+ fileutils.mkdir(Ferron.site.html .. '/tag')
end
-- Build the HTML file
fileutils.pushfilecontent(
- Ferron.site.html .. "/tag/" .. tag .. ".html",
+ Ferron.site.html .. '/tag/' .. tag .. '.html',
templateutils.rendermustache(
- fileutils.pullfilecontent(Ferron.site.templates .. "/tag.mustache"),
- Ferron.site.templates .. "/partials",
+ fileutils.pullfilecontent(Ferron.site.templates .. '/tag.mustache'),
+ Ferron.site.templates .. '/partials',
tag_tb
)
)
diff --git a/ferron/utilities/file-utils.lua b/ferron/utilities/file-utils.lua
@@ -6,19 +6,19 @@ local fileutilsmeta = {
end
}
-local json = require "dkjson"
-local lfs = require "lfs"
-local mimetypes = require "mimetypes"
-local config = require "ferron.config"
-local tableutils = require "ferron.utilities.table-utils"
+local json = require 'dkjson'
+local lfs = require 'lfs'
+local mimetypes = require 'mimetypes'
+local config = require 'ferron.config'
+local tableutils = require 'ferron.utilities.table-utils'
function fileutils.getbasename(filepath)
- return string.gsub(filepath, "(.*/)(.*)", "%2")
+ return string.gsub(filepath, '(.*/)(.*)', '%2')
end
function fileutils.isFile(filepath)
if lfs.attributes(filepath)
- and lfs.attributes(filepath).mode == "file"
+ and lfs.attributes(filepath).mode == 'file'
then
return filepath
end
@@ -28,7 +28,7 @@ end
function fileutils.isDirectory(filepath)
if lfs.attributes(filepath)
- and lfs.attributes(filepath).mode == "directory"
+ and lfs.attributes(filepath).mode == 'directory'
then
return filepath
end
@@ -38,8 +38,8 @@ end
function fileutils.isMarkdown(filepath)
if fileutils.isFile(filepath)
- and (mimetypes.guess(filepath) == "text/x-markdown"
- or fileutils.getextension(filepath) == ".md")
+ and (mimetypes.guess(filepath) == 'text/x-markdown'
+ or fileutils.getextension(filepath) == '.md')
then
return filepath
end
@@ -49,7 +49,7 @@ end
function fileutils.isIndex(filepath)
if fileutils.isMarkdown(filepath)
- and fileutils.getbasename(filepath) == "index.md"
+ and fileutils.getbasename(filepath) == 'index.md'
then
return filepath
end
@@ -73,22 +73,22 @@ end
-- getdirtree
function fileutils.getdirtree(dir)
- assert(dir and dir ~= "", "directory parameter is missing or empty")
+ assert(dir and dir ~= '', 'directory parameter is missing or empty')
- if string.sub(dir, -1) == "/" then
+ if string.sub(dir, -1) == '/' then
dir = string.sub(dir, 1, -2)
end
local function yieldtree(dir)
for entry in lfs.dir(dir) do
- if entry ~= "." and entry ~= ".." then
- entry = dir.."/"..entry
+ if entry ~= '.' and entry ~= '..' then
+ entry = dir..'/'..entry
local attr = lfs.attributes(entry)
coroutine.yield(entry,attr)
- if attr.mode == "directory" then
+ if attr.mode == 'directory' then
yieldtree(entry)
end
end
@@ -100,9 +100,9 @@ end
-- mkdir
function fileutils.mkdir(path)
- local sep, pStr = package.config:sub(1, 1), ""
+ local sep, pStr = package.config:sub(1, 1), ''
- for dir in path:gmatch("[^" .. sep .. "]+") do
+ for dir in path:gmatch('[^' .. sep .. ']+') do
pStr = pStr .. sep .. dir
lfs.mkdir(pStr)
@@ -111,8 +111,8 @@ end
-- pullfilecontent
function fileutils.pullfilecontent(pathtofile)
- local file = assert(io.open(pathtofile, "r"))
- local content = file:read "*a"
+ local file = assert(io.open(pathtofile, 'r'))
+ local content = file:read '*a'
file:close()
@@ -121,7 +121,7 @@ end
-- pushfilecontent
function fileutils.pushfilecontent(pathtofile, data)
- local file = io.open(pathtofile, "w+")
+ local file = io.open(pathtofile, 'w+')
file:write(data)
file:close()
@@ -138,28 +138,28 @@ function fileutils.sethtmlpath(folder)
end
function fileutils.removeextension(file)
- return file:match("(.+)%..*")
+ return file:match('(.+)%..*')
end
function fileutils.getextension(file)
- return file:match("^.+(%..+)$")
+ return file:match('^.+(%..+)$')
end
function fileutils.getplainname(file)
- return fileutils.removeextension(file):match("^.+/(.+)$")
+ return fileutils.removeextension(file):match('^.+/(.+)$')
end
function fileutils.getdirname(file)
- return file:match("(.*/)")
+ return file:match('(.*/)')
end
function fileutils.getpageconf(pagepath)
local pageconf = nil
- local conflua = fileutils.isFile(fileutils.removeextension(pagepath) .. ".lua")
- local confjson = fileutils.isFile(fileutils.removeextension(pagepath) .. ".json")
+ local conflua = fileutils.isFile(fileutils.removeextension(pagepath) .. '.lua')
+ local confjson = fileutils.isFile(fileutils.removeextension(pagepath) .. '.json')
if conflua then
- package.path = package.path .. ";" .. fileutils.getdirname(conflua) .. "/?.lua"
+ package.path = package.path .. ';' .. fileutils.getdirname(conflua) .. '/?.lua'
pageconf = require(fileutils.getplainname(conflua))
elseif confjson then
pageconf = json.decode(fileutils.pullfilecontent(confjson))
@@ -169,9 +169,9 @@ function fileutils.getpageconf(pagepath)
end
function fileutils.shorturlencode(num)
- local alphabet = "23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ-_"
+ local alphabet = '23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ-_'
local base = alphabet:len()
- local str = ""
+ local str = ''
while num > 0 do
str = string.sub(alphabet, num % base, num % base) .. str
diff --git a/ferron/utilities/table-utils.lua b/ferron/utilities/table-utils.lua
@@ -13,13 +13,16 @@ function tableutils.sortdescendingpairs(tbl)
for k in pairs(tbl) do table.insert(keys, k) end
- table.sort(keys, function(a,b)
- if tonumber(a) and tonumber(b) then
- return a > b
- else
- return tostring(a)>tostring(b)
- end
- end)
+ table.sort(
+ keys,
+ function(a,b)
+ if tonumber(a) and tonumber(b) then
+ return a > b
+ else
+ return tostring(a) > tostring(b)
+ end
+ end
+ )
return function()
if i < #keys then
@@ -76,7 +79,7 @@ function tableutils.extend(list, ...)
end
-function tableutils.settable(...)
+function tableutils.from(...)
local _tbl = {}
for x in ... do _tbl[#_tbl + 1] = x end
diff --git a/ferron/utilities/template-utils.lua b/ferron/utilities/template-utils.lua
@@ -6,29 +6,29 @@ local templateutilsmeta = {
end
}
-local lustache = require "lustache"
-local etlua = require "etlua"
-local fileutils = require "ferron.utilities.file-utils"
+local lustache = require 'lustache'
+local etlua = require 'etlua'
+local fileutils = require 'ferron.utilities.file-utils'
-- set template
function templateutils.selecttemplate(index, templatename)
- local templatepath = Ferron.site.path .. Ferron.site.config.paths.templates .. "/"
+ local templatepath = Ferron.site.path .. Ferron.site.config.paths.templates .. '/'
local template = nil
- if templatename and type(templatename) == "string" then
+ if templatename and type(templatename) == 'string' then
template = templatepath .. templatename
else
- if type(index) == "boolean" and index == true then
- template = templatepath .. "default-index"
+ if type(index) == 'boolean' and index == true then
+ template = templatepath .. 'default-index'
else
- template = templatepath .. "default"
+ template = templatepath .. 'default'
end
end
-- etlua or mustache
-- etlua templates will outrank the mustache ones
- return assert(fileutils.isFile(template .. ".etlua") and template .. ".etlua" or template .. ".mustache",
- "You need to add some templates to your site.")
+ return assert(fileutils.isFile(template .. '.etlua') and template .. '.etlua' or template .. '.mustache',
+ 'You need to add some templates to your site.')
end
-- process mustache
@@ -36,8 +36,8 @@ function templateutils.rendermustache(tpl, partialspath, data)
local partials = {}
for i,v in ipairs(lustache:parse(tpl)) do
- if v.type == ">" then
- partials[v.value] = fileutils.pullfilecontent(partialspath .. "/" .. v.value .. ".mustache")
+ if v.type == '>' then
+ partials[v.value] = fileutils.pullfilecontent(partialspath .. '/' .. v.value .. '.mustache')
end
end
@@ -56,9 +56,9 @@ function templateutils.rendertemplate(template, data, partials)
local extension = fileutils.getextension(template)
local render = nil
- if extension == ".etlua" then
+ if extension == '.etlua' then
render = templateutils.renderetlua(fileutils.pullfilecontent(template), data)
- elseif extension == ".mustache" then
+ elseif extension == '.mustache' then
render = templateutils.rendermustache(fileutils.pullfilecontent(template), partials, data)
end