ferron

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

commit 61a2bd304f10fc900b68dae82d48b2057b8f60e6
parent 7cd1c07bd055573653af1a1abfc5606eaf7fab06
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Tue, 21 Nov 2017 11:11:29 -0500

Create html directly in the public_html/ folder.

Diffstat:
Mfunctions/make-atom-feed.lua | 9+++++++--
Mfunctions/make-lists-of-pages.lua | 23++++++++++++++++++-----
Mfunctions/make-pages.lua | 19+++++++++++++++----
Mfunctions/move-to-publichtml.lua | 58+++++++++++++++++++++++++++++-----------------------------
4 files changed, 69 insertions(+), 40 deletions(-)

diff --git a/functions/make-atom-feed.lua b/functions/make-atom-feed.lua @@ -26,8 +26,13 @@ local function makeatomfeed() feed ) ) - - print("¤ /feed.atom.xml - done") + + if path.isfile(feedfile) ~= false then + print("¤ /feed.atom.xml - created") + else + print("!! /feed.atom.xml - error!") + end + print("==========") end diff --git a/functions/make-lists-of-pages.lua b/functions/make-lists-of-pages.lua @@ -6,19 +6,23 @@ local fileutils = require("functions.file-utils") local tableutils = require("functions.table-utils") local templateutils = require("functions.template-utils") -local function makelistsofpages() +local function makelistsofpages() for file, attr in fileutils.getdirtree(Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT) do if attr.mode ~= "directory" and file:match("^.+/(.+)$") == "index.md" and file ~= Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/index.md" then local listindex = file + local listindex_plainname = listindex:match("^.+/(.+)$"):match("(.+)%..*") local listindex_section = path.dirname(listindex):match("^.+/(.+)$") local listindex_table = {} local listindex_metadatas = json.decode(fileutils.pullfilecontent(listindex:match("(.+)%..*") .. ".json")) local listindex_relpath = listindex:match("(.+)%..*"):sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT):len() + 1) + local listindex_relpathfolder = (path.dirname(listindex):sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT):len() + 1)) + local listindex_pathhtml = Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. listindex_relpathfolder + local listindex_html = listindex_pathhtml .. "/" .. listindex_plainname .. ".html" - print("§ Make an index page for `" .. listindex_section .. "` section:") + print("§ Make an index page for the `" .. listindex_section .. "` section:") -- Convert the markdown file to HTML listindex_metadatas.content = markdown(fileutils.pullfilecontent(listindex)) @@ -47,9 +51,13 @@ local function makelistsofpages() {recurse = true} ) + if path.isdir(listindex_pathhtml) == false then + fileutils.mkdir(listindex_pathhtml) + end + -- Build the HTML file fileutils.pushfilecontent( - listindex:match("(.+)%..*") .. ".html", + listindex_html, templateutils.setmustache( fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/" .. listindex_metadatas.template .. ".mustache"), Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", @@ -57,7 +65,12 @@ local function makelistsofpages() ) ) - print(" " .. listindex_relpath .. ".html - done") + if path.isfile(listindex_html) ~= false then + print(" ¬ " .. listindex_relpath .. ".html - created") + else + print(" !! " .. listindex_relpath .. ".html - error!") + end + print("==========") -- Update the JSON file data @@ -65,7 +78,7 @@ local function makelistsofpages() listindex_metadatas["SITE"] = nil fileutils.pushfilecontent(listindex:match("(.+)%..*") .. ".json", json.encode(listindex_metadatas, {indent = true})) end - end + end end return makelistsofpages diff --git a/functions/make-pages.lua b/functions/make-pages.lua @@ -8,8 +8,8 @@ local templateutils = require("functions.template-utils") local function makepages() -- Loop in the content directory print("- Looking for markdown in " .. Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT) - - for file, attr in fileutils.getdirtree(Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT) do + + for file, attr in fileutils.getdirtree(Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT) do if attr.mode ~= "directory" and file:match("^.+(%..+)$") == ".md" and file:match("^.+/(.+)$") ~= "index.md" @@ -20,6 +20,9 @@ local function makepages() local md_plainname = md:match("^.+/(.+)$"):match("(.+)%..*") local md_folder = path.dirname(md) local md_relpath = md_noextension:sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT):len() + 1) + local md_relpathfolder = md_folder:sub((Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT):len() + 1) + local md_pathhtml = Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. md_relpathfolder + local md_html = md_pathhtml .. "/" .. md_plainname .. ".html" local md_section = md_relpath:match("/(%a-)/") local md_metadatas = json.decode(fileutils.pullfilecontent(md_noextension .. ".json")) local md_updated = os.date("%Y-%m-%dT%H:%M:%S", attr.modification) @@ -40,9 +43,13 @@ local function makepages() md_table = md_metadatas md_table["SITE"] = Ferron.site.config.SITE + if path.isdir(md_pathhtml) == false then + fileutils.mkdir(md_pathhtml) + end + -- Build the HTML file fileutils.pushfilecontent( - md_noextension .. ".html", + md_html, templateutils.setmustache( fileutils.pullfilecontent(Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/" .. md_metadatas.template .. ".mustache"), Ferron.site.path .. Ferron.site.config.SITE.PATHS.TEMPLATES .. "/partials", @@ -50,7 +57,11 @@ local function makepages() ) ) - print("¬ " .. md_relpath .. ".html - done") + if path.isfile(md_html) ~= false then + print(" ¬ " .. md_relpath .. ".html - created") + else + print(" !! " .. md_relpath .. ".html - error!") + end -- Update the JSON file data md_metadatas["SITE"] = nil diff --git a/functions/move-to-publichtml.lua b/functions/move-to-publichtml.lua @@ -3,39 +3,39 @@ local path = require("path") local function movetopublichtml() -- Copy the entire `SITE.PATHS.CONTENT` folder in `SITE.PATHS.HTML` - path.copy(Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/*", Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML, {recurse = true}) + --path.copy(Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/*", Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML, {recurse = true}) -- Then remove all non Web files - path.each( - Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. "/*", "f", - function(f) - if path.extension(f) == ".md" - or path.extension(f) == ".json" - then - path.remove(f) - end - end, - { - delay = true; -- use snapshot of directory - recurse = true; -- include subdirs - reverse = true; -- subdirs at first - } - ) + -- path.each( + -- Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. "/*", "f", + -- function(f) + -- if path.extension(f) == ".md" + -- or path.extension(f) == ".json" + -- then + -- path.remove(f) + -- end + -- end, + -- { + -- delay = true; -- use snapshot of directory + -- recurse = true; -- include subdirs + -- reverse = true; -- subdirs at first + -- } + -- ) -- And after that remove all HTML files in the `Ferron.PATHS.CONTENT` folder - path.each( - Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/*", "f", - function(f) - if path.extension(f) == ".html" then - path.remove(f) - end - end, - { - delay = true; -- use snapshot of directory - recurse = true; -- include subdirs - reverse = true; -- subdirs at first - } - ) + -- path.each( + -- Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT .. "/*", "f", + -- function(f) + -- if path.extension(f) == ".html" then + -- path.remove(f) + -- end + -- end, + -- { + -- delay = true; -- use snapshot of directory + -- recurse = true; -- include subdirs + -- reverse = true; -- subdirs at first + -- } + -- ) -- Copy the entire `SITE.PATHS.STATIC` folder in `SITE.PATHS.HTML` path.copy(Ferron.site.path .. Ferron.site.config.SITE.PATHS.STATIC .. "/*", Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML, {recurse = true})