summaryrefslogtreecommitdiff
path: root/maker
diff options
context:
space:
mode:
Diffstat (limited to 'maker')
-rwxr-xr-xmaker155
1 files changed, 44 insertions, 111 deletions
diff --git a/maker b/maker
index 4b7033c..043975c 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("<!doctype html>\n")
- print("<meta charset='utf-8'>\n")
- if data.overskrift then
- print("<title>%s ยท %s</title>\n", data.overskrift or "", config.title)
- else
- print("<title>%s</title>\n", config.title)
- end
- if config.css then
- print("<link href='%s' rel='stylesheet'>\n", config.css)
- end
-
- print("<meta name='viewport' content='width=device-width'>")
- print("<meta name='viewport' content='initial-scale=1.0'>")
-
- print([[
-<header>
- <h1>%s</h1>
-</header>
-]], config.title)
-
- if config.nav then
- print(config.nav)
- end
- print("<main>")
+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("</main>")
- if config.footer then
- print(config.footer)
- end
+local finder = "find %s -perm /o+r -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("<article>")
- if simple then
- if data.picto and #data.picto > 0 then
- print('<p><img src="%s">', data.picto)
- end
- if data.path then
- print("<h2><a href='/%s/%s'>%s</a></h2>", data.date, data.path, data.overskrift or "")
- else
- print("<h2>%s</h2>", data.overskrift or "")
- end
- else
- print("<h2>%s</h2>", data.overskrift or "")
- print("<p>posted %s, by %s", data.date, data.author)
- print('<p class="lead">%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 "</article>\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)