summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbie <bie@blekksprut.net>2017-02-24 00:56:21 +0900
committerbie <bie@blekksprut.net>2017-02-24 00:56:21 +0900
commit1e9526a327f5768cbe334ba76b732c470de4d1ca (patch)
treeee0170ccbc0ae2e85723230166d288b93201933d
downloadmaker-1e9526a327f5768cbe334ba76b732c470de4d1ca.tar.xz
maker maker
-rwxr-xr-xmaker155
1 files changed, 155 insertions, 0 deletions
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("<!doctype html>\n")
+ print("<meta charset='utf-8'>\n")
+ if data.overskrift then
+ print("<title>%s · %s</title>\n", data.overskrift or "", TITLE)
+ else
+ print("<title>%s</title>\n", TITLE)
+ end
+ print("<link href='/radionova.css' rel='stylesheet'>\n")
+
+ print([[
+<header>
+ <h1>%s</h1>
+</header>
+]], TITLE)
+
+ print([[
+<nav>
+<ul>
+<li><a href='/'>Radio Nova</a>
+<li><a href='/'>Programmer</a>
+<li><a href='/'>Sendeplan</a>
+<li><a href='/'>Studentnyhetene</a>
+</ul>
+</nav>
+]])
+ print("<main>")
+end
+
+function footer(data)
+ print("</main>")
+ print [[
+<footer>
+ <div class=spiller>
+ <p class=spiller-program>0900 - 1000 : Skumma Kultur
+ <p class=spiller-naa>Spilles nå: blah blah blah
+ </div>
+</footer>
+]]
+end
+
+function html(text, data, simple)
+ if not simple then
+ header(data)
+ print "<section>"
+ print [[
+ <aside>
+ </aside>
+ ]]
+ end
+
+ print("<article>")
+ if simple then
+ if data.picto and #data.picto > 0 then
+ print('<p><img src="%s">', data.picto)
+ else
+ print('<p><img src="/article.jpg">')
+ 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>skrevet %s, av %s for %s", data.date, data.author, data.group)
+ print('<p class="lead">%s', data.lead or "")
+ corz.marxup(text)
+ end
+
+ print "</article>\n"
+
+ if not simple then
+ print "</section>"
+ 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)
+