From 1e9526a327f5768cbe334ba76b732c470de4d1ca Mon Sep 17 00:00:00 2001 From: bie Date: Fri, 24 Feb 2017 00:56:21 +0900 Subject: maker maker --- maker | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 maker diff --git a/maker b/maker new file mode 100755 index 0000000..4ff298e --- /dev/null +++ b/maker @@ -0,0 +1,155 @@ +#!/usr/bin/env lua + +TITLE = "radionova" +INPUT = "/srv/www/tears/artikler" +OUTPUT = "/srv/www/" + +os.setlocale("no_NO") + +lfs = require "lfs" +posix = require "posix" +require "corz" + +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 "", TITLE) + else + print("%s\n", TITLE) + end + print("\n") + + print([[ +
+

%s

+
+]], TITLE) + + print([[ + +]]) + print("
") +end + +function footer(data) + print("
") + print [[ + +]] +end + +function html(text, data, simple) + if not simple then + header(data) + print "
" + print [[ + + ]] + end + + print("
") + if simple then + if data.picto and #data.picto > 0 then + print('

', data.picto) + else + print('

') + 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("

skrevet %s, av %s for %s", data.date, data.author, data.group) + print('

%s', data.lead or "") + corz.marxup(text) + end + + print "

\n" + + if not simple then + print "
" + footer(data) + end +end + +root = INPUT +finder = ("find %s -readable -not -iname '*~' -type f | sort -n"):format(root) +files = {} +for file in io.popen(finder):read("*a"):gmatch("[^\n]+") do + table.insert(files, file) +end + +-- alle tingene +for n, file in ipairs(files) do + url = file:match(root .. "/(.+)%..*") + dir = OUTPUT .. posix.dirname(url) + out = OUTPUT .. url .. ".html" + if not posix.stat(out) or posix.stat(file).mtime > posix.stat(out).mtime then + if not posix.stat(dir) then + os.execute("mkdir -p " .. dir) + end + io.output(out) + text, data = lup(file) + html(text, data) + end + io.output(io.stdout) +end + +-- forside +out = OUTPUT .. "index.html" +io.output(out) +header({}) +for n=1,8 do + if files[n] then + text, data = lup(files[n]) + data.path = posix.basename(files[n]):gsub(".txt$", ".html") + html(text, data, true) + end +end +footer({}) +io.output(io.stdout) + -- cgit v1.0