ferron

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

commit d5ffc3fb38daaf3a55eee5f5c5970708dbf3ac07
parent d3b0cc97785efcc96c766eb1e24c2d73a0e4ddad
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date:   Mon,  9 Apr 2018 14:22:10 -0400

Change `makecontent` to use it in `setarchetype`.

Diffstat:
Mferron/content.lua | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/ferron/content.lua b/ferron/content.lua @@ -47,24 +47,28 @@ function content.setarchetype(site) print(inspect(archetypes[tonumber(whicharchetype)])) - return archetypes[tonumber(whicharchetype)] + -- return archetypes[tonumber(whicharchetype)] + return content.makecontent(archetypes[tonumber(whicharchetype)], "TEST de création") end -function content.makecontent(contenttype, title) - if tableutils.hasvalue(content.getarchetypes(), arg[1]) and type(arg[2]) == "string" then +function content.makecontent(contenttype, contenttitle) + local archetypetype = (contenttype ~= nil and contenttype or arg[1]) + local title = (contenttitle ~= nil and contenttitle or arg[2]) + + if tableutils.hasvalue(content.getarchetypes(), archetypetype) and type(title) == "string" then local archetype = {} - local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content .. "/" .. arg[1] .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/" + local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content .. "/" .. archetypetype .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/" local archetypepath = Ferron.site.path .. Ferron.site.siteconfig.paths.archetypes .. "/" - archetype.title = arg[2] + archetype.title = title -- string.gsub(string.gsub(str,"[^ A-Za-z]",""),"[ ]+","-") better for the slug? -- archetype.filename = string.lower(archetype.title:gsub('%p','-'):gsub('%s','-')) archetype.filename = (archetype.title:gsub("[%s_]+", "-"):gsub("[^%w%-]+", ""):gsub("-+", "-")):lower() archetype.date = os.date("%Y-%m-%d") archetype.datetime = os.date("%H:%M:%S") - archetype.template = arg[1] + archetype.template = archetypetype - if path.isdir(contentpath) == false then + if not path.isdir(contentpath) then fileutils.mkdir(contentpath) end @@ -72,7 +76,7 @@ function content.makecontent(contenttype, title) fileutils.pushfilecontent( contentpath .. archetype.filename .. ".md", templateutils.setmustache( - fileutils.pullfilecontent(archetypepath .. arg[1] .. ".md" ), + fileutils.pullfilecontent(archetypepath .. archetypetype .. ".md" ), Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials", archetype ) @@ -82,7 +86,7 @@ function content.makecontent(contenttype, title) fileutils.pushfilecontent( contentpath .. archetype.filename .. ".json", templateutils.setmustache( - fileutils.pullfilecontent(archetypepath .. arg[1] .. ".json"), + fileutils.pullfilecontent(archetypepath .. archetypetype .. ".json"), Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials", archetype )