ferron

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

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

Rename archetype.lua to content.lua

Diffstat:
Dferron/archetype.lua | 72------------------------------------------------------------------------
Aferron/content.lua | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+), 72 deletions(-)

diff --git a/ferron/archetype.lua b/ferron/archetype.lua @@ -1,72 +0,0 @@ --- -local path = require "path" -local fileutils = require "ferron.utilities.file-utils" -local tableutils = require "ferron.utilities.table-utils" -local templateutils = require "ferron.utilities.template-utils" -local archetype = {} - -function archetype.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 - -function archetype.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 archetype diff --git a/ferron/content.lua b/ferron/content.lua @@ -0,0 +1,80 @@ +--[[ + +]]-- + +-- Required Packages +local path = require "path" +local fileutils = require "ferron.utilities.file-utils" +local tableutils = require "ferron.utilities.table-utils" +local templateutils = require "ferron.utilities.template-utils" + +-- Module Declaration +local content = {} + +content.archetypes = {} + +function content.getarchetypes() + local archetypesdir = Ferron.site.path .. Ferron.site.siteconfig.paths.archetypes + + if path.isdir(archetypesdir) then + for archetype, attr in fileutils.getdirtree(archetypesdir) do + if attr.mode ~= "directory" + and archetype:match("^.+(%..+)$") == ".json" + then + content.archetypes[#content.archetypes+1] = archetype:match("^.+/(.+)$"):match("(.+)%..*") + end + end + + return content.archetypes + end +end + +function content.makecontent() + if tableutils.hasvalue(content.archetypes, arg[1]) and type(arg[2]) == "string" then + local archetype = {} + local contentpath = Ferron.site.path .. Ferron.site.siteconfig.paths.content .. "/" .. arg[1] .. "/" .. os.date("%Y") .."/"..os.date("%m") .. "/" + local archetypepath = Ferron.site.path .. Ferron.site.siteconfig.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.siteconfig.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.siteconfig.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 content