ferron

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

commit 05eaa44d521fea71e29cc10e369ad4351d281538
parent c6182f250fb66a28568f1f139810d1f3dc821f90
Author: Hugo Soucy <hugo.soucy@savoirfairelinux.com>
Date:   Thu, 25 Jan 2018 15:35:41 -0500

Start the shortlinks mecanism.

Diffstat:
Mfunctions/ferron-utils.lua | 13+++++++++++++
Mfunctions/make-pages.lua | 15++++++++++++++-
2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/functions/ferron-utils.lua b/functions/ferron-utils.lua @@ -9,4 +9,17 @@ function ferronutils.sethtmlpath(folder) return Ferron.site.path .. Ferron.site.config.SITE.PATHS.HTML .. folder end +function ferronutils.shorturlencode(num) + local alphabet = "23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ-_" + local base = alphabet:len() + local str = "" + + while num > 0 do + str = string.sub(alphabet, num % base, num % base) .. str + num = math.floor(num / base) + end + + return str +end + return ferronutils diff --git a/functions/make-pages.lua b/functions/make-pages.lua @@ -9,6 +9,9 @@ local templateutils = require("functions.template-utils") local function makepages() local contentpath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.CONTENT + local datapath = Ferron.site.path .. Ferron.site.config.SITE.PATHS.DATA + local pagesrelpath = {} + local shortlinks = {} -- Loop in the content directory print("- Looking for markdown in " .. contentpath) @@ -60,6 +63,8 @@ local function makepages() print(" !! " .. md_relpath .. ".html - error!") end + pagesrelpath[#pagesrelpath +1] = md_relpath + -- Update the JSON file data fileutils.pushfilecontent(md_noextension .. ".json", json.encode(md_metadatas, {indent = true, keyorder = {"bridgy","cite","citeurl","content","date","datetime","description","id","keywords","permalink","section","template","title","updated"}})) end @@ -67,10 +72,18 @@ local function makepages() { delay = true; -- use snapshot of directory recurse = true; -- include subdirs - reverse = false; -- subdirs at first + reverse = true; -- subdirs at first } ) + for k, v in pairs(pagesrelpath) do + shortlinks[v] = ferronutils.shorturlencode(k) + end + + print(inspect(shortlinks)) + + fileutils.pushfilecontent(datapath .. "/shortlinks.json", json.encode(shortlinks, {indent = true})) + print("==========") end