Browse Source

Collection template (CSS WIP).

scossu 5 days ago
parent
commit
f27c411578
5 changed files with 149 additions and 26 deletions
  1. 93 8
      src/generator.lua
  2. 0 12
      src/submission.lua
  3. 3 2
      templates/assets/css/pkar.css
  4. 49 0
      templates/coll.html
  5. 4 4
      templates/index.html

+ 93 - 8
src/generator.lua

@@ -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.

+ 0 - 12
src/submission.lua

@@ -35,7 +35,6 @@ local pkar = require "pocket_archive"
 local model = require "pocket_archive.model"
 local mc = require "pocket_archive.monocypher"
 local repo = require "pocket_archive.repo"
-local transformers = require "pocket_archive.transformers"
 
 local logger = pkar.logger
 local dbg = require "debugger"
@@ -117,17 +116,6 @@ M.generate_sip = function(src_path)
                 else sip[i][k] = {v} end
                 ::cont1::
             end
-
-            --[[
-            -- Generate thumbnail for files.
-            local rsrc_path = path.join(
-                    sip.root_path, sip[i].source_path)
-            if path.isfile(rsrc_path) then
-                --require "debugger"()
-                sip[i].thumbnail = generate_thumbnail(
-                        sip[i], sip.root_path, tn_dir)
-            end
-            --]]
         else
             -- Continuation of values from a previous row.
             if i < 1 then

+ 3 - 2
templates/assets/css/pkar.css

@@ -96,9 +96,10 @@ header nav {
 
 .slideshow li {
     list-style-type: none;
-    display: block;
-    margin: .4rem auto;
+    display: inline-block;
+    margin: 1rem 2rem;
     text-align: center;
+    vertical-align: top;
 }
 
 .slideshow a {

+ 49 - 0
templates/coll.html

@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <%- head_tpl({site_title = site_title, title = title}) %>
+    </head>
+    <body>
+        <%- header_tpl({site_title = site_title}) %>
+        <main>
+            <h1>
+                <img class="title_icon" src="<%= icon_url %>" alt="Collection" />
+                <%= title %>
+            </h1>
+            <div class="row">
+                <section id="head_img" class="column column-66">
+                    <% if pref_rep then %>
+                        <a href="<%= pref_rep.url %>">
+                            <img src="<%= pref_rep.file %>" alt="[TODO]"/>
+                       </a>
+                   <% end %>
+                </section>
+                <section class="column column-30 toolbox">
+                    <h4>Tools</h4>
+                    <p><a href="<%= rdf_href %>">Download RDF document</a></p>
+                    <p><a href="#">Download Laundry List [TODO]</a></p>
+                </section>
+            </div>
+            <% if #members > 0 then %>
+            <section id="res_children">
+                <h2>Members</h2>
+                <ul>
+                <% for _, el in ipairs(members) do %>
+                    <li>
+                        <a href="<%= el.href %>">
+                        <% if el.tn then %>
+                            <img src="<%= el.tn %>" alt="<%= el.label %>" />
+                        <% end %>
+                            <img class="text_icon" href="<%= el.icon %>" />
+                            <%= el.label %>
+                        </a>
+                    </li>
+                <%end %>
+                </ul>
+            </section>
+            <% end %>
+        </main>
+        <footer></footer>
+    </body>
+</html>
+

+ 4 - 4
templates/index.html

@@ -34,9 +34,9 @@
             </section>
             <section id="coll_list">
                 <h2>Recent collections</h2>
-                <ul class="row slideshow">
+                <ul class="slideshow">
                 <% for _, coll in ipairs(idx_data.collections) do %>
-                    <li class="column coll_link">
+                    <li class="coll_link">
                         <a href="<%= coll.href %>">
                             <%if coll.tn then %>
                                 <img src="<%= coll.tn %>" alt="<%= coll.title.data %>" />
@@ -53,9 +53,9 @@
             </section>
             <section id="obj_list">
                 <h2>Recent artifacts</h2>
-                <ul class="row slideshow">
+                <ul class="slideshow">
                 <% for _, obj in ipairs(idx_data.objects) do %>
-                    <li class="column obj_link">
+                    <li class="obj_link">
                         <a href="<%= obj.href %>">
                             <%if obj.tn then %>
                                 <img src="<%= obj.tn %>" alt="<%= obj.title.data %>" />