ferron

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

commit d3b0cc97785efcc96c766eb1e24c2d73a0e4ddad
parent ded2dbd3fefc27905e02587de2d1dbac141378aa
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Mon,  9 Apr 2018 08:10:42 -0400

Test and refactor some functions.

Diffstat:
Mcornelius | 9+++++++--
Mferron/content.lua | 57+++++++++++++++++++++++++++++++++++++++------------------
Mferron/site.lua | 8++++----
3 files changed, 50 insertions(+), 24 deletions(-)

diff --git a/cornelius b/cornelius @@ -1,6 +1,6 @@ #!/usr/bin/env lua --- Cornelius is the CLI of Ferron SSG and it's a WIP. +-- Cornelius Ferron is the CLI of Ferron SSG and it's a WIP. -- <https://en.wikipedia.org/wiki/Cornelius_the_First> local config = require "config" @@ -19,8 +19,13 @@ 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 archetype") end -- install - install ferron and his dependencies -- build - build site in prod or dev --- create - create content from archetypes +-- create (TODO) - create content from archetypes +-- -- 1) set site +-- -- 2) choose an archetype from the selected site +-- -- 3) create the content from the chosen archetype diff --git a/ferron/content.lua b/ferron/content.lua @@ -11,26 +11,47 @@ 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 +function content.getarchetypes(dir) + local archetypes = {} + local archetypesdir = (dir ~= nil and dir or 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 + archetypes[#archetypes+1] = archetype:match("^.+/(.+)$"):match("(.+)%..*") + end + end + + return archetypes + end +end + +function content.setarchetype(site) + local archetypes = content.getarchetypes(site.path .. site.siteconfig.paths.archetypes) + local whicharchetype = 0 + + repeat + io.write("Which archetypes do you need to complete your request? \n") + + for k, v in ipairs(archetypes) do + io.write(k .. ") " .. v .. "\n") + end + + io.write("Please enter the number... \n") + io.flush() + + whicharchetype=io.read() + until (tableutils.haskey(archetypes, tonumber(whicharchetype))) == true + + print(inspect(archetypes[tonumber(whicharchetype)])) + + return archetypes[tonumber(whicharchetype)] end -function content.makecontent() - if tableutils.hasvalue(content.archetypes, arg[1]) and type(arg[2]) == "string" then +function content.makecontent(contenttype, title) + if tableutils.hasvalue(content.getarchetypes(), 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 .. "/" diff --git a/ferron/site.lua b/ferron/site.lua @@ -4,10 +4,11 @@ local tableutils = require "ferron.utilities.table-utils" local fileutils = require "ferron.utilities.file-utils" local site = {} -local sites_tb = {} -local sites_arr = {} function site.getsites() + local sites_tb = {} + local sites_arr = {} + -- Create a table with the content of `config.paths.sites` for s in path.each(config.paths.sites .. "/*", "f", {delay = true; reverse = true;}) do if path.isdir(s) then @@ -30,11 +31,10 @@ function site.getsites() end function site.setsite() + local sites_tb, sites_arr = site.getsites() -- Site chooser: Which site do you want to build? local whichsite = nil - site.getsites() - repeat io.write("Welcome to Ferron! Which site do you want to build? \n")