|
@@ -39,14 +39,15 @@ local idx_keys
|
|
|
-- HTML templates. Compile them only once.
|
|
|
-- TODO Add override for user-maintained templates.
|
|
|
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"},
|
|
|
+ idx = {file = "index.html"},
|
|
|
+ coll = {file = "coll.html"},
|
|
|
+ dres = {file = "dres.html"},
|
|
|
+ ores = {file = "ores.html"},
|
|
|
+ head = {file = "head_common.html"},
|
|
|
+ header = {file = "header.html"},
|
|
|
}
|
|
|
for _, tpl in pairs(templates) do
|
|
|
- local fh = datafile.open(tpl.file)
|
|
|
+ local fh = datafile.open(path.join("templates", tpl.file))
|
|
|
tpl.data = assert(etlua.compile(fh:read("a")))
|
|
|
end
|
|
|
|
|
@@ -60,10 +61,20 @@ local M = {
|
|
|
webroot = "", -- TODO switch depending on local FS or webserver generation.
|
|
|
}
|
|
|
|
|
|
+local MEDIA_WEB_PATH = M.media_dir:gsub(pkar.config.htmlgen.out_dir, "")
|
|
|
local TN_FS_PATH = path.join(M.media_dir, "thumbnail")
|
|
|
local TN_WEB_PATH = TN_FS_PATH:gsub(pkar.config.htmlgen.out_dir, "")
|
|
|
|
|
|
|
|
|
+-- Get model configuration from subject URI.
|
|
|
+local function get_mconf(s)
|
|
|
+ local ctype
|
|
|
+ _, ctype = next(repo.gr:attr(s, model.id_to_uri.content_type))
|
|
|
+
|
|
|
+ return model.types[model.uri_to_id[nsm.denormalize_uri(ctype.data)]]
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
local function get_breadcrumbs(mconf)
|
|
|
-- Breadcrumbs, from top class to current class.
|
|
|
-- Also verify if it's a File subclass.
|
|
@@ -131,6 +142,78 @@ local function get_icon_url(lineage)
|
|
|
end
|
|
|
|
|
|
|
|
|
+local function generate_coll(s, mconf)
|
|
|
+ local pref_rep, pref_rep_url
|
|
|
+ _, pref_rep = next(repo.gr:attr(s, model.id_to_uri.pref_rep))
|
|
|
+ if pref_rep then
|
|
|
+ pref_rep_url = pkar.gen_pairtree("/res", pref_rep.data, ".html", true)
|
|
|
+ -- Collection page uses full size image, shrunk to size if necessary.
|
|
|
+ pref_rep_file = get_tn_url(pref_rep):gsub(TN_WEB_PATH, MEDIA_WEB_PATH)
|
|
|
+ end
|
|
|
+
|
|
|
+ local members = {}
|
|
|
+ local child_s
|
|
|
+ _, child_s = next(repo.gr:attr(s, model.id_to_uri.first))
|
|
|
+ --[[ FIXME this should check for the ref attribute of the proxy.
|
|
|
+ if not repo.gr:contains(triple.new(
|
|
|
+ s, model.id_to_uri.has_member, first
|
|
|
+ )) then
|
|
|
+ error(("first child %s is not a member of %s!")
|
|
|
+ :format(first.data, s.data)
|
|
|
+ )
|
|
|
+ end
|
|
|
+ --]]
|
|
|
+ local child_ref, child_label, child_mconf
|
|
|
+ while child_s do
|
|
|
+ _, child_ref = next(repo.gr:attr(child_s, model.id_to_uri.ref))
|
|
|
+ --if not child_ref then child_ref = child_s end
|
|
|
+ _, child_label = next(repo.gr:attr(child_s, model.id_to_uri.label))
|
|
|
+ if not child_label then
|
|
|
+ _, child_label = next(repo.gr:attr(child_ref, model.id_to_uri.label))
|
|
|
+ end
|
|
|
+ child_mconf = get_mconf(child_ref)
|
|
|
+ table.insert(members, {
|
|
|
+ icon = get_icon_url(child_mconf.lineage),
|
|
|
+ tn = get_tn_url(child_s),
|
|
|
+ href = pkar.gen_pairtree("/res", child_ref.data, ".html", true),
|
|
|
+ label = child_label.data,
|
|
|
+ })
|
|
|
+ _, child_s = next(repo.gr:attr(child_s, model.id_to_uri.next))
|
|
|
+ end
|
|
|
+
|
|
|
+ local title, description
|
|
|
+ _, title = next(repo.gr:attr(s, model.id_to_uri.label))
|
|
|
+ _, description = next(repo.gr:attr(s, model.id_to_uri.description))
|
|
|
+
|
|
|
+ out_html = templates.coll.data({
|
|
|
+ --webroot = M.webroot,
|
|
|
+ site_title = pkar.config.site.title or pkar.default_title,
|
|
|
+ title = title.data,
|
|
|
+ description = description.data,
|
|
|
+ head_tpl = templates.head.data,
|
|
|
+ header_tpl = templates.header.data,
|
|
|
+ mconf = mconf,
|
|
|
+ uri = s,
|
|
|
+ members = members,
|
|
|
+ tn_url = get_tn_url(s),
|
|
|
+ pref_rep = {
|
|
|
+ url = pref_rep_url,
|
|
|
+ file = pref_rep_file,
|
|
|
+ },
|
|
|
+ icon_url = get_icon_url(mconf.lineage),
|
|
|
+ --breadcrumbs = get_breadcrumbs(mconf),
|
|
|
+ rdf_href = pkar.gen_pairtree("/res", s.data, ".ttl", true),
|
|
|
+ })
|
|
|
+
|
|
|
+ local res_path = pkar.gen_pairtree(M.res_dir, s.data, ".html")
|
|
|
+ local ofh = assert(io.open(res_path, "w"))
|
|
|
+ ofh:write(out_html)
|
|
|
+ ofh:close()
|
|
|
+
|
|
|
+ return true
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
local function generate_dres(s, mconf)
|
|
|
local dmd = {}
|
|
|
local rel = {}
|
|
@@ -171,7 +254,8 @@ local function generate_dres(s, mconf)
|
|
|
|
|
|
while child_s do
|
|
|
-- Loop trough all next nodes for each first child.
|
|
|
- local _, ref = next(repo.gr:attr(child_s, model.id_to_uri.ref))
|
|
|
+ local ref
|
|
|
+ _, ref = next(repo.gr:attr(child_s, model.id_to_uri.ref))
|
|
|
--dbg()
|
|
|
table.insert(ll, {
|
|
|
href = pkar.gen_pairtree("/res", ref.data, ".html", true),
|
|
@@ -466,7 +550,8 @@ M.generate_resource = function(s)
|
|
|
ofh:close()
|
|
|
|
|
|
-- Generate HTML doc.
|
|
|
- if mconf.types.file then assert(generate_ores(s, mconf))
|
|
|
+ if mconf.types.collection then assert(generate_coll(s, mconf))
|
|
|
+ elseif mconf.types.file then assert(generate_ores(s, mconf))
|
|
|
else assert(generate_dres(s, mconf)) end
|
|
|
|
|
|
-- Generate JSON rep and append to search index.
|