hugo.soucy.cc

The personnal website source code of Hugo Soucy. Creates from an homebrewed static website generator (Ferron).
Log | Files | Refs

commit f2d153a788c9692213be1cbf4a428b06e0f66f11
parent ae51a890af5fd826e23e0f4f8939e70489ac302a
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Sat, 20 Jan 2018 13:23:22 -0500

Work on a ShortUrl function.

Diffstat:
Mtag.lua | 32++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/tag.lua b/tag.lua @@ -1,10 +1,37 @@ -- - local inspect = require("inspect") local json = require("dkjson") local lfs = require("lfs") local path = require("path") +function string:charAt(index) + return string.sub(self, index, index) +end + + +local ShortUrl = { + alphabet = "23456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ-_" +} + +--print(ShortUrl.alphabet:charAt(1)) + +function ShortUrl:encode(num) + local base = self.alphabet:len() + local str = "" + + + while num > 0 do + str = self.alphabet:charAt(num % base) .. str; + num = math.floor(num / base); + end + + print(str) + + return str +end + +ShortUrl:encode(117) + local function pullfilecontent(pathtofile) local file = assert(io.open(pathtofile, "r")) local content = file:read "*a" @@ -14,6 +41,7 @@ local function pullfilecontent(pathtofile) return content end + local function getpagetags() dofile("site.config.lua") @@ -47,4 +75,4 @@ end --return getpagetags -getpagetags() +--getpagetags()