Ver código fonte

Add collection to index.

scossu 2 semanas atrás
pai
commit
064d11b4d6
3 arquivos alterados com 53 adições e 9 exclusões
  1. 2 2
      README.md
  2. 32 6
      src/generator.lua
  3. 19 1
      templates/index.html

+ 2 - 2
README.md

@@ -237,9 +237,9 @@ functional and available for use by the intended audience.
   - ✓ Generate RDF (single resource)
 - ⚒ Front end
   - ✓ JS search engine
-  -  Add collections to index page
+  -  Add collections to index page
   - ⚒ Basic styling
-      -  Default type icons
+      -  Default type icons
 - ⎊ QA
   - ⎊ ~50 resource data set
 

+ 32 - 6
src/generator.lua

@@ -475,9 +475,9 @@ end
 
 
 M.generate_idx = function()
-    local obj_idx = {}
+    local idx_data = {objects = {}, collections = {}}
     -- Get all subject of type: Artifact.
-    s_ts = repo.gr:term_set(
+    local s_ts = repo.gr:term_set(
         pkar.RDF_TYPE, triple.POS_P,
         term.new_iriref_ns("pas:Artifact"), triple.POS_O
     )
@@ -492,11 +492,37 @@ M.generate_idx = function()
             submitted = submitted.data,
             tn = get_tn_url(s),
         }
-        table.insert(obj_idx, obj)
+        table.insert(idx_data.objects, obj)
     end
-    table.sort(obj_idx, function(a, b) return a.submitted < b.submitted end)
+    table.sort(
+        idx_data.objects, function(a, b)
+            return a.submitted < b.submitted end
+    )
+
+    s_ts = repo.gr:term_set(
+        pkar.RDF_TYPE, triple.POS_P,
+        term.new_iriref_ns("pas:Collection"), triple.POS_O
+    )
+    for _, s in pairs(s_ts) do
+        local title, submitted
+        _, title = next(repo.gr:attr(s, pkar.DC_TITLE_P))
+        _, submitted = next(repo.gr:attr(s, pkar.SUBMITTED_P))
+
+        local coll = {
+            href = pkar.gen_pairtree("/res", s.data, ".html", true),
+            title = title,
+            submitted = submitted.data,
+            tn = get_tn_url(s),
+        }
+        table.insert(idx_data.collections, coll)
+    end
+    table.sort(
+        idx_data.collections, function(a, b)
+            return a.submitted < b.submitted end
+    )
+
+    logger:debug(pp.write(idx_data))
 
-    logger:debug(pp.write(obj_idx))
     out_html = templates.idx.data({
         webroot = M.webroot,
         title = pkar.config.site.title or pkar.default_title,
@@ -504,7 +530,7 @@ M.generate_idx = function()
         head_tpl = templates.head.data,
         header_tpl = templates.header.data,
         nsm = nsm,
-        obj_idx = obj_idx,
+        idx_data = idx_data,
     })
 
     local idx_path = path.join(pkar.config.htmlgen.out_dir, "index.html")

+ 19 - 1
templates/index.html

@@ -32,10 +32,28 @@
                 <h2>Search results</h2>
                 <ul id="result_list"></ul>
             </section>
+            <section id="coll_list">
+                <h2>Recent collections</h2>
+                <ul>
+                <% for _, coll in ipairs(idx_data.collections) do %>
+                    <li class="coll_link">
+                        <a href="<%= coll.href %>">
+                            <%if coll.tn then %>
+                                <img src="<%= coll.tn %>" alt="<%= coll.title.data %>" />
+                            <% end %>
+                            <%= coll.title.data %>
+                            <%if coll.title.lang then %>
+                                <span class="langtag"><%= coll.title.lang %></span>
+                            <% end %>
+                        </a>
+                    </li>
+                <% end %>
+                </ul>
+            </section>
             <section id="obj_list">
                 <h2>Recent artifacts</h2>
                 <ul>
-                <% for _, obj in ipairs(obj_idx) do %>
+                <% for _, obj in ipairs(idx_data.objects) do %>
                     <li class="obj_link">
                         <a href="<%= obj.href %>">
                             <%if obj.tn then %>