|
@@ -36,22 +36,17 @@ local idx_keys = {}
|
|
|
|
|
|
-- HTML templates. Compile them only once.
|
|
-- HTML templates. Compile them only once.
|
|
-- TODO Add override for user-maintained templates.
|
|
-- TODO Add override for user-maintained templates.
|
|
-local fh, idx_tpl, dres_tpl, ores_tpl
|
|
|
|
-fh = datafile.open("templates/index.html")
|
|
|
|
-idx_tpl = assert(etlua.compile(fh:read("a")))
|
|
|
|
-fh:close()
|
|
|
|
-
|
|
|
|
-fh = datafile.open("templates/dres.html")
|
|
|
|
-dres_tpl = assert(etlua.compile(fh:read("a")))
|
|
|
|
-fh:close()
|
|
|
|
-
|
|
|
|
-fh = datafile.open("templates/ores.html")
|
|
|
|
-ores_tpl = assert(etlua.compile(fh:read("a")))
|
|
|
|
-fh:close()
|
|
|
|
-
|
|
|
|
-fh = datafile.open("templates/header.html")
|
|
|
|
-header_tpl = assert(etlua.compile(fh:read("a")))
|
|
|
|
-fh:close()
|
|
|
|
|
|
+local templates = {
|
|
|
|
+ idx = {file = "templates/index.html"},
|
|
|
|
+ dres = {file = "templates/dres.html"},
|
|
|
|
+ ores = {file = "templates/ores.html"},
|
|
|
|
+ head = {file = "templates/head_common.html"},
|
|
|
|
+ header = {file = "templates/header.html"},
|
|
|
|
+}
|
|
|
|
+for _, tpl in pairs(templates) do
|
|
|
|
+ local fh = datafile.open(tpl.file)
|
|
|
|
+ tpl.data = assert(etlua.compile(fh:read("a")))
|
|
|
|
+end
|
|
|
|
|
|
|
|
|
|
-- HTML generator module.
|
|
-- HTML generator module.
|
|
@@ -59,6 +54,7 @@ local M = {
|
|
res_dir = plpath.join(pkar.config.htmlgen.out_dir, "res"),
|
|
res_dir = plpath.join(pkar.config.htmlgen.out_dir, "res"),
|
|
asset_dir = asset_dir,
|
|
asset_dir = asset_dir,
|
|
media_dir = plpath.join(pkar.config.htmlgen.out_dir, "media"),
|
|
media_dir = plpath.join(pkar.config.htmlgen.out_dir, "media"),
|
|
|
|
+ webroot = "", -- TODO switch depending on local FS or webserver generation.
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -129,7 +125,7 @@ local function generate_dres(s, mconf)
|
|
|
|
|
|
while child_s do
|
|
while child_s do
|
|
-- Loop trough all next nodes for each first child.
|
|
-- Loop trough all next nodes for each first child.
|
|
- require "debugger".assert(get_tn_url(child_s))
|
|
|
|
|
|
+ --require "debugger".assert(get_tn_url(child_s))
|
|
table.insert(ll, {
|
|
table.insert(ll, {
|
|
href = pkar.gen_pairtree(
|
|
href = pkar.gen_pairtree(
|
|
"/res", child_s.data, ".html", true),
|
|
"/res", child_s.data, ".html", true),
|
|
@@ -169,10 +165,12 @@ local function generate_dres(s, mconf)
|
|
logger:debug("Children:", pp.write(children))
|
|
logger:debug("Children:", pp.write(children))
|
|
logger:debug("Breadcrumbs:", pp.write(get_breadcrumbs(mconf)))
|
|
logger:debug("Breadcrumbs:", pp.write(get_breadcrumbs(mconf)))
|
|
|
|
|
|
- out_html = dres_tpl({
|
|
|
|
|
|
+ out_html = templates.dres.data({
|
|
|
|
+ webroot = M.webroot,
|
|
site_title = pkar.config.site.title or pkar.default_title,
|
|
site_title = pkar.config.site.title or pkar.default_title,
|
|
title = title or s.data,
|
|
title = title or s.data,
|
|
- header_tpl = header_tpl,
|
|
|
|
|
|
+ head_tpl = templates.head.data,
|
|
|
|
+ header_tpl = templates.header.data,
|
|
mconf = mconf,
|
|
mconf = mconf,
|
|
uri = s,
|
|
uri = s,
|
|
dmd = dmd,
|
|
dmd = dmd,
|
|
@@ -261,10 +259,12 @@ local function generate_ores(s, mconf)
|
|
logger:info("Thumbnail: ", tn)
|
|
logger:info("Thumbnail: ", tn)
|
|
end
|
|
end
|
|
|
|
|
|
- out_html = ores_tpl({
|
|
|
|
|
|
+ out_html = templates.ores.data({
|
|
|
|
+ webroot = M.webroot,
|
|
site_title = pkar.config.site.title or pkar.default_title,
|
|
site_title = pkar.config.site.title or pkar.default_title,
|
|
fname = plpath.basename(techmd["pas:sourcePath"][1]),
|
|
fname = plpath.basename(techmd["pas:sourcePath"][1]),
|
|
- header_tpl = header_tpl,
|
|
|
|
|
|
+ head_tpl = templates.head.data,
|
|
|
|
+ header_tpl = templates.header.data,
|
|
mconf = mconf,
|
|
mconf = mconf,
|
|
uri = s,
|
|
uri = s,
|
|
techmd = techmd,
|
|
techmd = techmd,
|
|
@@ -294,7 +294,12 @@ end
|
|
|
|
|
|
|
|
|
|
M.generate_res_idx = function(s, mconf)
|
|
M.generate_res_idx = function(s, mconf)
|
|
- local rrep = {id = nsm.denormalize_uri(s.data)}
|
|
|
|
|
|
+ local rrep = {
|
|
|
|
+ id = nsm.denormalize_uri(s.data),
|
|
|
|
+ tn = get_tn_url(s):gsub(M.media_dir, "/media/tn"),
|
|
|
|
+ href = pkar.gen_pairtree("/res", s.data, ".html", true),
|
|
|
|
+ }
|
|
|
|
+
|
|
local attrs = gr:connections(s, term.LINK_OUTBOUND)
|
|
local attrs = gr:connections(s, term.LINK_OUTBOUND)
|
|
|
|
|
|
local function format_value(fname, o)
|
|
local function format_value(fname, o)
|
|
@@ -414,9 +419,11 @@ M.generate_idx = function()
|
|
table.sort(obj_idx, function(a, b) return a.created < b.created end)
|
|
table.sort(obj_idx, function(a, b) return a.created < b.created end)
|
|
|
|
|
|
logger:debug(pp.write(obj_idx))
|
|
logger:debug(pp.write(obj_idx))
|
|
- out_html = idx_tpl({
|
|
|
|
|
|
+ out_html = templates.idx.data({
|
|
|
|
+ webroot = M.webroot,
|
|
title = pkar.config.site.title or pkar.default_title,
|
|
title = pkar.config.site.title or pkar.default_title,
|
|
- header_tpl = header_tpl,
|
|
|
|
|
|
+ head_tpl = templates.head.data,
|
|
|
|
+ header_tpl = templates.header.data,
|
|
nsm = nsm,
|
|
nsm = nsm,
|
|
obj_idx = obj_idx,
|
|
obj_idx = obj_idx,
|
|
})
|
|
})
|