Ver Fonte

Improve cmdoc pages; serverless pres pages.

scossu há 1 semana atrás
pai
commit
1f598f3f82

+ 2 - 2
doc/roadmap.md

@@ -65,14 +65,14 @@ usage and opportunities for expanding adoption in relevant areas.
   - ❏ Backup full environment (including config)
   - ❏ Restore whole archive from RDF & data folder
 - ⚒ Content model
-  -  Generate content model documentation (HTML)
+  -  Generate content model documentation (HTML)
   - ❏ Multilingual support
   - ⚒ Content model dump (CLI)
   - ❏ Local overrides
 - ⚒ Presentation
   - ⎊ Generate site for one collection only
   - ✓ Generate LL for submission
-  -  htmlgen option for local file or webserver URL generation
+  -  htmlgen option for local file or webserver URL generation
   - ✖︎ Generate RDF (multi) [addressed by dump archive RDF]
 - ❏ Front end
   - ✓ Mobile-friendly layout

+ 5 - 0
src/cmdoc.lua

@@ -18,6 +18,7 @@ local pp = require "pl.pretty"
 local pkar = require "pocket_archive"
 local logger = pkar.logger
 local model = require "pocket_archive.model"
+local pres = require "pocket_archive.presentation"
 
 
 -- HTML templates. Compile them only once.
@@ -67,6 +68,7 @@ M.generate_schema = function(id)
         site_title = pkar.config.pres_gen.title,
         schema = schema_pres,
         head_tpl = templates.head.data,
+        webroot = "..",
     })
     local ofh = assert(io.open(
         path.join(M.out_dir, "schema", id .. ".html"), "w"))
@@ -89,6 +91,7 @@ M.generate_index = function()
         site_title = pkar.config.pres_gen.title,
         types = types,
         head_tpl = templates.head.data,
+        webroot = ".",
     })
     local ofh = assert(io.open(path.join(M.out_dir, tpl.file), "w"))
     ofh:write(data)
@@ -100,6 +103,8 @@ end
 
 M.generate_doc = function()
     dir.makepath(path.join(M.out_dir, "schema"))
+    assert(dir.clonetree(pres.src_asset_dir, M.out_dir, dir.copyfile))
+
     for id in pairs(model.types) do assert(M.generate_schema(id)) end
     assert(M.generate_index())
 end

+ 11 - 12
src/presentation.lua

@@ -67,7 +67,6 @@ local M = {
     asset_dir = asset_dir,
     icon_dir = path.join(asset_dir, "icons"),
     media_dir = path.join(pkar.config.pres_gen.out_dir, "media"),
-    webroot = "",  -- TODO switch depending on local FS or webserver generation.
 }
 
 local MEDIA_WEB_PATH = M.media_dir:gsub(pkar.config.pres_gen.out_dir, "")
@@ -138,10 +137,10 @@ end
 
 --[[ Find closest available type icon to the given type.
 --]]
-local function get_icon_url(lineage)
+local function get_icon_url(lineage, webroot)
     for i = #lineage, 1, -1 do
         if path.isfile(path.join(M.icon_dir, lineage[i] .. ICON_EXT)) then
-            return M.webroot .. "/icons/" .. lineage[i] .. ICON_EXT
+            return webroot .. "/icons/" .. lineage[i] .. ICON_EXT
         end
     end
 end
@@ -192,7 +191,7 @@ local function generate_coll(s, mconf)
         end
         if child_label.data then child_label = child_label.data end
         table.insert(members, {
-            icon = get_icon_url(child_mconf.lineage),
+            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,
@@ -216,7 +215,7 @@ local function generate_coll(s, mconf)
     end
 
     out_html = templates.coll.data({
-        --webroot = M.webroot,
+        webroot = "../../..",
         site_title = pkar.config.pres_gen.title,
         title = (title or NT).data or "[No title]",
         description = (description or NT).data,
@@ -232,7 +231,7 @@ local function generate_coll(s, mconf)
             url = pref_rep_url,
             file = pref_rep_file,
         },
-        icon_url = get_icon_url(mconf.lineage),
+        icon_url = get_icon_url(mconf.lineage, "../../.."),
         --breadcrumbs = get_breadcrumbs(mconf),
         rdf_href = pkar.gen_pairtree("/res", s.data, ".ttl", true),
     })
@@ -350,7 +349,7 @@ local function generate_dres(s, mconf)
     end
 
     out_html = templates.dres.data({
-        --webroot = M.webroot,
+        webroot = "../../..",
         site_title = pkar.config.pres_gen.title,
         title = title or s.data,
         head_tpl = templates.head.data,
@@ -366,7 +365,7 @@ local function generate_dres(s, mconf)
             url = pref_rep_url,
             file = pref_rep_file,
         },
-        icon_url = get_icon_url(mconf.lineage),
+        icon_url = get_icon_url(mconf.lineage, "../../.."),
         breadcrumbs = get_breadcrumbs(mconf),
         rdf_href = pkar.gen_pairtree("/res", s.data, ".ttl", true),
         permalink = pkar.gen_pairtree("/res", s.data, ".html", true),
@@ -461,7 +460,7 @@ local function generate_ores(s, mconf)
     end
 
     out_html = templates.ores.data({
-        --webroot = M.webroot,
+        webroot = "../../..",
         site_title = pkar.config.pres_gen.title,
         fname = path.basename(techmd.source_path[1]),
         head_tpl = templates.head.data,
@@ -471,7 +470,7 @@ local function generate_ores(s, mconf)
         techmd = techmd,
         rel = rel,
         ls_next = ls_next,
-        icon_url = get_icon_url(mconf.lineage),
+        icon_url = get_icon_url(mconf.lineage, "../../.."),
         breadcrumbs = get_breadcrumbs(mconf),
         pres = pres,
         thumbnail = tn,
@@ -495,7 +494,7 @@ M.generate_search_idx = function(s, mconf)
         href = pkar.gen_pairtree("/res", s.data, ".html", true),
         content_type = mconf.id,
         type = mconf.lineage,
-        icon = get_icon_url(mconf.lineage),
+        icon = get_icon_url(mconf.lineage, "."),
     }
 
     local function format_value(pname, o)
@@ -724,7 +723,7 @@ M.generate_homepage = function()
     logger:debug(pp.write(idx_data))
 
     out_html = templates.idx.data({
-        webroot = M.webroot,
+        webroot = ".",
         site_title = pkar.config.pres_gen.title,
         head_tpl = templates.head.data,
         header_tpl = templates.header.data,

+ 5 - 4
src/util/watcher.lua

@@ -78,9 +78,10 @@ cli.program {
             logger:info("\n")
             if ev.name:find("pkar_submission.*%.csv") then
                 logger:info("Detected new submission file: ", ev.name)
-                -- TODO spawn subprocess
-                sub.deposit(plpath.join(args.path, ev.name), args.cleanup)
-                if args.gen_site then gen.generate_site() end
+                posix.popen(function()
+                    sub.deposit(plpath.join(args.path, ev.name), args.cleanup)
+                    if args.gen_site then pres.generate_site() end
+                end)
             end
         end)
 
@@ -88,7 +89,7 @@ cli.program {
           wd:poll()
         end
 
-        logfile:close()
+        --logfile:close()
         wd:close()
     end,
 }

+ 3 - 3
templates/cmdoc/head_common.html

@@ -1,8 +1,8 @@
 <meta charset="utf-8"/>
 <!-- Milligram CSS -->
-<link rel="stylesheet" href="/css/normalize.min.css">
-<link rel="stylesheet" href="/css/milligram.min.css">
-<link rel="stylesheet" href="/css/pkar.css">
+<link rel="stylesheet" href="<%= webroot %>/css/normalize.min.css">
+<link rel="stylesheet" href="<%= webroot %>/css/milligram.min.css">
+<link rel="stylesheet" href="<%= webroot %>/css/pkar.css">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 
 <title><%= title %>&emsp;&#x2741;&emsp;<%= site_title %></title>

+ 4 - 2
templates/cmdoc/index.html

@@ -1,7 +1,9 @@
 <!DOCTYPE html>
 <html>
     <head>
-        <%- head_tpl({site_title = site_title, title = "Content model documentation"}) %>
+        <%- head_tpl({
+            site_title = site_title, title = "Content model documentation",
+            webroot = webroot}) %>
     </head>
     <body>
         <main>
@@ -26,7 +28,7 @@
                 <ul>
                 <% for _, schema in ipairs(types) do %>
                     <li><a href="schema/<%= schema.id -%>.html">
-                        <%= schema.label %>
+                            <%= schema.label %> (<code><%= schema.id %></code>)
                     </a></li>
                 <% end %>
                 </ul>

+ 3 - 2
templates/cmdoc/schema.html

@@ -3,12 +3,13 @@
     <head>
         <%- head_tpl({
             site_title = site_title,
-            title = "Schema: " .. schema.attr.label,
+            title = "Schema: " .. schema.attr.id,
+            webroot = webroot,
         }) %>
     </head>
     <body>
         <main>
-            <h1 class="title">Schema: <%= schema.attr.label %></h1>
+            <h1 class="title">Schema: <code><%= schema.attr.id %></code></h1>
             <section id="schema_attr">
                 <h2>Attributes</h1>
                 <dl class="schema_md">

+ 8 - 7
templates/pres/coll.html

@@ -1,10 +1,11 @@
 <!DOCTYPE html>
 <html>
     <head>
-        <%- head_tpl({site_title = site_title, title = title}) %>
+        <%- head_tpl({site_title = site_title, title = title,
+            webroot = webroot}) %>
     </head>
     <body>
-        <%- header_tpl({site_title = site_title}) %>
+        <%- header_tpl({site_title = site_title, webroot = webroot}) %>
         <main>
             <h1>
                 <img class="title_icon" src="<%= icon_url %>" alt="Collection" />
@@ -13,13 +14,13 @@
             <div class="row">
                 <section id="head_img" class="column column-66">
                 <% if pref_rep then %>
-                    <img src="<%= pref_rep.file %>" alt="<%= title %>"/>
+                    <img src="<%= webroot -%><%= pref_rep.file %>" alt="<%= title %>"/>
                 <% end %>
                 </section>
                 <section class="column column-30 toolbox">
                     <h4>Tools</h4>
-                    <p>Unique ID: <a href="<%= permalink -%>"><%= uid -%></a></p>
-                    <p><a href="<%= rdf_href %>">Download RDF document</a></p>
+                    <p>Unique ID: <a href="<%= webroot -%><%= permalink -%>"><%= uid -%></a></p>
+                    <p><a href="<%= webroot -%><%= rdf_href %>">Download RDF document</a></p>
                     <p><a href="#">Download Laundry List [TODO]</a></p>
                 </section>
             </div>
@@ -34,9 +35,9 @@
                 <ul class="slideshow">
                 <% for _, el in ipairs(members) do %>
                     <li>
-                        <a href="<%= el.href %>">
+                        <a href="<%= webroot -%><%= el.href %>">
                         <% if el.tn then %>
-                            <img src="<%= el.tn %>" alt="<%= el.label %>" />
+                            <img src="<%= webroot -%><%= el.tn %>" alt="<%= el.label %>" />
                         <% end %>
                             <br/>
                             <img

+ 11 - 10
templates/pres/dres.html

@@ -1,10 +1,11 @@
 <!DOCTYPE html>
 <html>
     <head>
-        <%- head_tpl({site_title = site_title, title = title}) %>
+        <%- head_tpl({site_title = site_title, title = title,
+            webroot = webroot}) %>
     </head>
     <body>
-        <%- header_tpl({site_title = site_title}) %>
+        <%- header_tpl({site_title = site_title, webroot = webroot}) %>
         <main>
             <h1>
                 <img
@@ -15,15 +16,15 @@
             <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="<%= title %>"/>
+                    <a href="<%= webroot -%><%= pref_rep.url %>">
+                        <img src="<%= webroot -%><%= pref_rep.file %>" alt="<%= title %>"/>
                    </a>
                 <% end %>
                 </section>
                 <section class="column column-30 toolbox">
                     <h4>Tools</h4>
-                    <p>Unique ID: <a href="<%= permalink -%>"><%= uid -%></a></p>
-                    <p><a href="<%= rdf_href %>">Download RDF document</a></p>
+                    <p>Unique ID: <a href="<%= webroot -%><%= permalink -%>"><%= uid -%></a></p>
+                    <p><a href="<%= webroot -%><%= rdf_href %>">Download RDF document</a></p>
                     <p><a href="#">Download Laundry List [TODO]</a></p>
                 </section>
             </div>
@@ -37,7 +38,7 @@
                     <% end %>
                     <a
                         class="breadcrumb<%if i == #breadcrumbs then %> current<% end %>"
-                        href="../class/<%= cls -%>">
+                        href="<%= webroot -%>/class/<%= cls -%>">
                         <%= label -%>
                     </a>
                 <% end %>
@@ -71,7 +72,7 @@
                         <% else %><code><%= ol.uri %></code><% end %>
                     </dt>
                     <% for _, o in ipairs(ol) do %>
-                        <dd><a href="<%= o.href %>"><%= o.label %></a></dd>
+                        <dd><a href="<%= webroot -%><%= o.href %>"><%= o.label %></a></dd>
                     <% end %>
                 <% end %>
                 </dl>
@@ -84,9 +85,9 @@
                 <% for _, ll in ipairs(children) do %>
                 <li><%= ll[1].label %> (<%= #ll %> items)<ol>
                     <% for i, el in ipairs(ll) do %>
-                        <li><a href="<%= el.href %>">
+                        <li><a href="<%= webroot -%><%= el.href %>">
                         <% if el.tn then %>
-                            <img src="<%= el.tn %>" alt="<%= el.label %>" />
+                            <img src="<%= webroot -%><%= el.tn %>" alt="<%= el.label %>" />
                         <% else %>
                             <%= el.label %>
                         <% end %>

+ 3 - 3
templates/pres/head_common.html

@@ -1,8 +1,8 @@
 <meta charset="utf-8"/>
 <!-- Milligram CSS -->
-<link rel="stylesheet" href="/css/normalize.min.css">
-<link rel="stylesheet" href="/css/milligram.min.css">
-<link rel="stylesheet" href="/css/pkar.css">
+<link rel="stylesheet" href="<%= webroot -%>/css/normalize.min.css">
+<link rel="stylesheet" href="<%= webroot -%>/css/milligram.min.css">
+<link rel="stylesheet" href="<%= webroot -%>/css/pkar.css">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 
 <title><%= title %>&emsp;&#x2741;&emsp;<%= site_title %></title>

+ 4 - 4
templates/pres/header.html

@@ -1,16 +1,16 @@
 <header>
     <nav>
-        <a class="nav_title" href="/"><%= site_title %></a>
+        <a class="nav_title" href="<%= webroot -%>/index.html"><%= site_title %></a>
         <ul class="nav_menu">
-            <li><a href="/cats">Categories</a></li>
+            <li><a href="<%= webroot -%>/cats">Categories</a></li>
             <li>
-                <form id="search_bar" action="/" method="GET">
+                <form id="search_bar" action="<%= webroot -%>/index.html" method="GET">
                     <input
                         class="float-left" type="text" name="q" id="nav_qry_f"
                         placeholder="Quick search">
                     <input
                         id="nav_search_btn" class="button-primary" type="image"
-                        alt="Search" src="/icons/round-search.svg">
+                        alt="Search" src="<%= webroot -%>/icons/round-search.svg">
                 </form>
             </li>
         </ul>

+ 11 - 10
templates/pres/index.html

@@ -1,21 +1,22 @@
 <!DOCTYPE html>
 <html>
     <head>
-        <%- head_tpl({site_title = site_title, title = "Index"}) %>
+        <%- head_tpl({
+            site_title = site_title, title = "Index", webroot = webroot}) %>
         <!-- JS client-side search. -->
-        <script src="/js/fuse.min.js"></script>
-        <script src="/js/fuse_init.js"></script>
+        <script src="<%= webroot -%>/js/fuse.min.js"></script>
+        <script src="<%= webroot -%>/js/fuse_init.js"></script>
 
         <script>window.webroot = "<%= webroot -%>";</script>
-        <script src="/js/search.js" defer></script>
+        <script src="<%= webroot -%>/js/search.js" defer></script>
     </head>
     <body>
-        <%- header_tpl({site_title = site_title}) %>
+        <%- header_tpl({site_title = site_title, webroot = webroot}) %>
         <main>
             <h1 class="title"><%= site_title %></h1>
             <section id="search">
                 <h2>Search</h2>
-                <form action="/" method="GET">
+                <form action="<%= webroot -%>/index.html" method="GET">
                     <fieldset>
                         <label class="v_hidden" for="q">Search query</label>
                         <div class="float-left">
@@ -37,9 +38,9 @@
                 <ul class="slideshow">
                 <% for _, coll in ipairs(idx_data.collections) do %>
                     <li class="coll_link">
-                        <a href="<%= coll.href %>">
+                        <a href="<%= webroot -%><%= coll.href %>">
                             <%if coll.tn then %>
-                                <img src="<%= coll.tn %>" alt="<%= coll.title.data %>" />
+                                <img src="<%= webroot -%><%= coll.tn %>" alt="<%= coll.title.data %>" />
                                 <br/>
                             <% end %>
                             <%= coll.title.data %>
@@ -56,9 +57,9 @@
                 <ul class="slideshow">
                 <% for _, obj in ipairs(idx_data.objects) do %>
                     <li class="obj_link">
-                        <a href="<%= obj.href %>">
+                        <a href="<%= webroot -%><%= obj.href %>">
                             <%if obj.tn then %>
-                                <img src="<%= obj.tn %>" alt="<%= obj.title.data %>" />
+                                <img src="<%= webroot -%><%= obj.tn %>" alt="<%= obj.title.data %>" />
                                 <br/>
                             <% end %>
                             <%= obj.title.data %>

+ 7 - 6
templates/pres/ores.html

@@ -1,7 +1,8 @@
 <!DOCTYPE html>
 <html>
     <head>
-        <%- head_tpl({site_title = site_title, title = fname}) %>
+        <%- head_tpl({site_title = site_title, title = fname,
+            webroot = webroot}) %>
     </head>
     <body>
         <%- header_tpl({site_title = site_title}) %>
@@ -13,9 +14,9 @@
             <% if pres then %>
             <section id="res_pres">
                 <% if (mconf.gen or {}).presentation_type == "image" then %>
-                <img src="<%= pres -%>" />
+                <img src="<%= webroot -%><%= pres -%>" />
             <%else %>
-                <a href="<%= pres -%>" download="<%= fname -%>">
+                <a href="<%= webroot -%><%= pres -%>" download="<%= fname -%>">
                     Download file
                 </a>
             <% end %>
@@ -31,7 +32,7 @@
                     <% end %>
                     <a
                         class="breadcrumb<%if i == #breadcrumbs then %> current<% end %>"
-                        href="../class/<%= cls -%>">
+                        href="<%= webroot -%>class/<%= cls -%>">
                         <%= label -%>
                     </a>
                 <% end %>
@@ -39,7 +40,7 @@
             </section>
             <section class="res_md" id="res_techmd">
                 <h2>Metadata</h2>
-                <p><a href="<%= rdf_href %>">Download RDF document</a></p>
+                <p><a href="<%= webroot -%><%= rdf_href %>">Download RDF document</a></p>
                 <dl>
                 <% for p, ol in pairs(techmd) do %>
                     <dt>
@@ -66,7 +67,7 @@
                         <% else %><code><%= ol.uri %></code><% end %>
                     </dt>
                     <% for _, o in ipairs(ol) do %>
-                        <dd><a href="/res/<%= o.href %>"><%= o.label %></a></dd>
+                        <dd><a href="<%= webroot -%><%= o.href %>"><%= o.label %></a></dd>
                     <% end %>
                 <% end %>
                 </dl>