ferron

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

commit f7fecc6b4f0732245f44d1be715a38f37120f3ff
parent 3eb57e4de0ae1e3126aa83f6e22366fc63c923af
Author: Hugo Soucy <hsoucy@kronostechnologies.com>
Date:   Fri, 14 Sep 2018 13:32:17 -0400

Create table for the `json.encode` keyorder param

Diffstat:
Mferron/link.lua | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/ferron/link.lua b/ferron/link.lua @@ -1,4 +1,4 @@ --- +-- @TODO Make sure to always keep the alphanumerical order local json = require "dkjson" local path = require "path" local fileutils = require "ferron.utilities.file-utils" @@ -8,6 +8,7 @@ local link = {} function link.makeshorts() local links = {} + local links_keyorder = {} local links_db = Ferron.site.path .. Ferron.site.siteconfig.paths.data .. "/shortlinks.json" -- If `links_db` dosen't exists create it @@ -20,7 +21,11 @@ function link.makeshorts() if v.rellink ~= "" then counter = counter + 1 + table.insert(links_keyorder, v.rellink) + links[v.rellink] = fileutils.shorturlencode(counter) + + return fileutils.pushfilecontent(links_db, json.encode(links, {indent = true, keyorder = links_keyorder})) end end else @@ -28,12 +33,16 @@ function link.makeshorts() for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do if v.rellink ~= "" and links[v.rellink] == nil then + table.insert(links_keyorder, v.rellink) + links[v.rellink] = fileutils.shorturlencode(tableutils.length(links) + 1) + + return fileutils.pushfilecontent(links_db, json.encode(links, {indent = true, keyorder = links_keyorder})) end end end - return fileutils.pushfilecontent(links_db, json.encode(links, {indent = true})) + return end function link.makerewritemap()