From 05c51adb090fa096eb229c9cc4f1c519fcda6a01 Mon Sep 17 00:00:00 2001 From: bie Date: Thu, 29 Jun 2017 15:48:02 +0200 Subject: wew wew --- .gitignore | 2 + maker | 155 ++++++++++++++----------------------------------- nova/article.html | 35 +++++++++++ nova/index.html | 7 +++ nova/layout.html | 49 ++++++++++++++++ templates/article.html | 9 +++ templates/index.html | 10 ++++ templates/layout.html | 18 ++++++ 8 files changed, 174 insertions(+), 111 deletions(-) create mode 100644 nova/article.html create mode 100644 nova/index.html create mode 100644 nova/layout.html create mode 100644 templates/article.html create mode 100644 templates/index.html create mode 100644 templates/layout.html diff --git a/.gitignore b/.gitignore index b25c15b..7f0df81 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +artikler/ +config.lua *~ 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("\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 -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("
") - 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) diff --git a/nova/article.html b/nova/article.html new file mode 100644 index 0000000..6e82369 --- /dev/null +++ b/nova/article.html @@ -0,0 +1,35 @@ +
+

+ +

{{title}}

+ +
+ + +
+ {{#lead}} +

{{lead}} + {{/lead}} + {{&text}} +

+
+
+ diff --git a/nova/index.html b/nova/index.html new file mode 100644 index 0000000..97ef595 --- /dev/null +++ b/nova/index.html @@ -0,0 +1,7 @@ +{{#articles}} +
+

+

{{title}}

+
+{{/articles}} + diff --git a/nova/layout.html b/nova/layout.html new file mode 100644 index 0000000..e9b5c83 --- /dev/null +++ b/nova/layout.html @@ -0,0 +1,49 @@ + + +{{site.title}} + + + + + + + + + + + + + + + + +
+

+ +
+
+ + +
+ +
+{{&_}} +
+ + + diff --git a/templates/article.html b/templates/article.html new file mode 100644 index 0000000..d8b5b4b --- /dev/null +++ b/templates/article.html @@ -0,0 +1,9 @@ +
+

{{title}}

+

posted {{date}} by {{author}} + {{#lead}} +

{{lead}} + {{/lead}} + {{&text}} +

+ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..4695387 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,10 @@ +{{#articles}} +
+

{{title}}

+

posted {{date}} by {{author}} + {{#lead}} +

{{lead}} + {{/lead}} +

+{{/articles}} + diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..7937763 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,18 @@ + + +{{site.title}} + + + + +
+

{{site.title}}

+
+ +
+{{&_}} +
+ + + -- cgit v1.0