From 9f249b3e2af30444dbfbd42396824df3724af68f Mon Sep 17 00:00:00 2001 From: bie Date: Mon, 20 Mar 2017 07:58:32 +0000 Subject: =?UTF-8?q?config-fil=20og=20s=C3=A5nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + config.def.lua | 16 +++++++++++ maker | 88 +++++++++++++++++++++++----------------------------------- 3 files changed, 52 insertions(+), 53 deletions(-) create mode 100644 .gitignore create mode 100644 config.def.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/config.def.lua b/config.def.lua new file mode 100644 index 0000000..c4f2d80 --- /dev/null +++ b/config.def.lua @@ -0,0 +1,16 @@ +config.title = "~maker~" +config.input = "/srv/artikler" +config.output = "/srv/www" + +config.css = "/maker.css" + +config.nav = [[ + +]] + +config.footer = [[ + +]] + diff --git a/maker b/maker index 4ff298e..4b7033c 100755 --- a/maker +++ b/maker @@ -1,15 +1,12 @@ #!/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" +config = {} +dofile 'config.lua' + function lup(file) local raw, data = "", {} local stat = posix.stat(file) @@ -42,59 +39,45 @@ function header(data) print("\n") print("\n") if data.overskrift then - print("%s · %s\n", data.overskrift or "", TITLE) + print("%s · %s\n", data.overskrift or "", config.title) else - print("%s\n", TITLE) + print("%s\n", config.title) end - print("\n") + if config.css then + print("\n", config.css) + end + + print("") + print("") print([[

%s

-]], TITLE) +]], config.title) - print([[ - -]]) + if config.nav then + print(config.nav) + end print("
") end function footer(data) print("
") - print [[ - -]] + if config.footer then + print(config.footer) + end end -function html(text, data, simple) - if not simple then - header(data) - print "
" - print [[ - - ]] - end +function preview(text, data) + article(text, data) +end +function article(text, data) 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 "") @@ -103,51 +86,50 @@ function html(text, data, simple) end else print("

%s

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

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

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

%s', data.lead or "") - corz.marxup(text) + corz.marxup(text, io.output()) 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) +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 --- alle tingene for n, file in ipairs(files) do url = file:match(root .. "/(.+)%..*") - dir = OUTPUT .. posix.dirname(url) - out = OUTPUT .. url .. ".html" + 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 not posix.stat(dir) then os.execute("mkdir -p " .. dir) end io.output(out) text, data = lup(file) - html(text, data) + header(data) + article(text, data) + footer(data) end io.output(io.stdout) end +posix.setenv("MARXUP_HEADER", "3"); + -- forside -out = OUTPUT .. "index.html" +out = config.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) + preview(text, data) end end footer({}) -- cgit v1.0