From 8df4f368a73a3b39a152bf864ab03c409179e5ec Mon Sep 17 00:00:00 2001 From: bie Date: Mon, 31 Jul 2017 06:01:04 +0200 Subject: ehhh --- maker | 155 +++++++++++++++++++----------------------------------------------- 1 file changed, 44 insertions(+), 111 deletions(-) diff --git a/maker b/maker index 4b7033c..b8b9ba6 100755 --- a/maker +++ b/maker @@ -2,136 +2,69 @@ lfs = require "lfs" posix = require "posix" +lustache = require "lustache" + +require "lupin" require "corz" config = {} dofile 'config.lua' -function lup(file) - local raw, data = "", {} - local stat = posix.stat(file) - io.input(file) - data.group = posix.getgroup(stat.gid).name - data.author = posix.getpasswd(stat.uid).name - data.overskrift = io.read('*l') - for line in io.lines() do - if line:match("^#") then - local key, value = line:match("^#%s*(.-):%s*(.+)") - if key and value then data[key] = value end - else - raw = raw .. line .. "\n" - end - end - if data.published then - data.date = os.date("%A %d. %B %Y, kl. %H.%M", data.published) - else - y, m, d = file:match(root .. "/(.*)/(.*)/(.*)/(.*)") - data.date = ("%s/%s/%s"):format(y, m, d) - end - return raw, data -end - -function print(...) - io.write(string.format(...)) -end - -function header(data) - print("\n") - print("\n") - if data.overskrift then - print("%s ยท %s\n", data.overskrift or "", config.title) - else - print("%s\n", config.title) - end - if config.css then - print("\n", config.css) - end - - print("") - print("") - - print([[ -
-

%s

-
-]], config.title) - - if config.nav then - print(config.nav) - end - print("
") +posix.setenv("MARXUP_HEADER", "3"); +lupin.loadblueprints(config.blueprints) + +function build(path, id, data) + local layout = io.open(config.templates .. "/layout.html"):read("*a") + local template = io.open(config.templates .. "/" .. id .. ".html"):read("*a") + data._ = lustache:render(template, data) + io.output(path) + io.write(lustache:render(layout, data)) + io.output() end -function footer(data) - print("
") - if config.footer then - print(config.footer) - end +local finder = "find %s -readable -not -iname '*~' -type f | sort -rn" +local files = {} +for file in io.popen(finder:format(config.src)):read("*a"):gmatch("[^\n]+") do + table.insert(files, file) end -function preview(text, data) - article(text, data) -end +for n, src in ipairs(files) do + local url = src:match(config.src .. "/(.+)%..*") + local dir = config.www .. "/" .. posix.dirname(url) + local path = config.www .. "/" .. url .. ".html" -function article(text, data) - print("
") - if simple then - if data.picto and #data.picto > 0 then - print('

', data.picto) - end - if data.path then - print("

%s

", data.date, data.path, data.overskrift or "") - else - print("

%s

", data.overskrift or "") - end - else - print("

%s

", data.overskrift or "") - print("

posted %s, by %s", data.date, data.author) - print('

%s', data.lead or "") - corz.marxup(text, io.output()) + local stale = false + if not posix.stat(path) or posix.stat(src).mtime > posix.stat(path).mtime then + stale = true end - - print "

\n" - -end - -root = config.input -finder = ("find %s -readable -not -iname '*~' -type f | sort -rn"):format(root) -files = {} -for file in io.popen(finder):read("*a"):gmatch("[^\n]+") do - table.insert(files, file) -end - -for n, file in ipairs(files) do - url = file:match(root .. "/(.+)%..*") - dir = config.output .. posix.dirname(url) - out = config.output .. url .. ".html" - if not posix.stat(out) or posix.stat(file).mtime > posix.stat(out).mtime then + if true or stale then -- if stale then if not posix.stat(dir) then os.execute("mkdir -p " .. dir) end - io.output(out) - text, data = lup(file) - header(data) - article(text, data) - footer(data) + local data = lupin.transform(src, "later", false, "full") + data.path = posix.dirname(src):gsub("^" .. config.src, "") + data.site = config + + build(path, "article", data) end - io.output(io.stdout) end -posix.setenv("MARXUP_HEADER", "3"); - --- forside -out = config.output .. "index.html" -io.output(out) -header({}) +local path = config.www .. "/" .. "index.html" +local page = {} +page.site = config +page.articles = {} for n=1,8 do if files[n] then - text, data = lup(files[n]) - data.path = posix.basename(files[n]):gsub(".txt$", ".html") - preview(text, data) + local data + local data = lupin.transform(files[n], "later", false, "full") + local slug = posix.basename(files[n]):gsub(".txt$", "") + data.path = posix.dirname(files[n]):gsub("^" .. config.src, "") + data.url = config.base .. "/" .. data.path .. "/" .. slug + if config.extension then + data.url = data.url .. config.extension + end + table.insert(page.articles, data) end end -footer({}) -io.output(io.stdout) +build(path, "index", page) -- cgit v1.0