|
@@ -1,3 +1,13 @@
|
|
|
+--[[--
|
|
|
+Presentation generator module.
|
|
|
+
|
|
|
+This module contains all functions to generate HTML pages and all other assets
|
|
|
+required to run a static site from an archive.
|
|
|
+
|
|
|
+@module pocket_archive.presentation
|
|
|
+]]
|
|
|
+
|
|
|
+
|
|
|
local csv = require "ftcsv"
|
|
|
local datafile = require "datafile"
|
|
|
local dir = require "pl.dir"
|
|
@@ -19,8 +29,6 @@ local repo = require "pocket_archive.repo"
|
|
|
local get_single_v = repo.get_single_v
|
|
|
local transformers = require "pocket_archive.transformers"
|
|
|
|
|
|
-local dbg = require "debugger"
|
|
|
-
|
|
|
|
|
|
-- "nil" table - for missing key fallback in chaining.
|
|
|
local NT = {}
|
|
@@ -28,7 +36,8 @@ local NT = {}
|
|
|
-- Extension for type-based icon files.
|
|
|
local ICON_EXT = ".svg"
|
|
|
|
|
|
-local asset_dir = pkar.config.htmlgen.out_dir
|
|
|
+local src_asset_dir = datafile.path("templates/pres/assets")
|
|
|
+local asset_dir = pkar.config.pres_gen.out_dir
|
|
|
local index_path = path.join(asset_dir, "js", "fuse_index.json")
|
|
|
local keys_path = path.join(asset_dir, "js", "fuse_keys.json")
|
|
|
local idx_ignore = {first = true, next = true}
|
|
@@ -46,23 +55,24 @@ local templates = {
|
|
|
header = {file = "header.html"},
|
|
|
}
|
|
|
for _, tpl in pairs(templates) do
|
|
|
- local fh = datafile.open(path.join("templates", tpl.file))
|
|
|
+ local fh = datafile.open(path.join("templates", "pres", tpl.file))
|
|
|
tpl.data = assert(etlua.compile(fh:read("a")))
|
|
|
end
|
|
|
|
|
|
|
|
|
--- HTML generator module.
|
|
|
+-- Presentation generator module.
|
|
|
local M = {
|
|
|
- res_dir = path.join(pkar.config.htmlgen.out_dir, "res"),
|
|
|
+ res_dir = path.join(pkar.config.pres_gen.out_dir, "res"),
|
|
|
+ src_asset_dir = src_asset_dir,
|
|
|
asset_dir = asset_dir,
|
|
|
icon_dir = path.join(asset_dir, "icons"),
|
|
|
- media_dir = path.join(pkar.config.htmlgen.out_dir, "media"),
|
|
|
+ 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.htmlgen.out_dir, "")
|
|
|
+local MEDIA_WEB_PATH = M.media_dir:gsub(pkar.config.pres_gen.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, "")
|
|
|
+local TN_WEB_PATH = TN_FS_PATH:gsub(pkar.config.pres_gen.out_dir, "")
|
|
|
|
|
|
|
|
|
-- Get model configuration from subject URI.
|
|
@@ -207,7 +217,7 @@ local function generate_coll(s, mconf)
|
|
|
|
|
|
out_html = templates.coll.data({
|
|
|
--webroot = M.webroot,
|
|
|
- site_title = pkar.config.site.title,
|
|
|
+ site_title = pkar.config.pres_gen.title,
|
|
|
title = (title or NT).data or "[No title]",
|
|
|
description = (description or NT).data,
|
|
|
body = body,
|
|
@@ -341,7 +351,7 @@ local function generate_dres(s, mconf)
|
|
|
|
|
|
out_html = templates.dres.data({
|
|
|
--webroot = M.webroot,
|
|
|
- site_title = pkar.config.site.title,
|
|
|
+ site_title = pkar.config.pres_gen.title,
|
|
|
title = title or s.data,
|
|
|
head_tpl = templates.head.data,
|
|
|
header_tpl = templates.header.data,
|
|
@@ -434,7 +444,7 @@ local function generate_ores(s, mconf)
|
|
|
dest = path.join(dest_dir, dest_fname)
|
|
|
assert(transformers[pres_conf.fn](
|
|
|
res_path[1], dest, table.unpack(pres_conf or NT)))
|
|
|
- local pres = dest:gsub(pkar.config.htmlgen.out_dir, "")
|
|
|
+ local pres = dest:gsub(pkar.config.pres_gen.out_dir, "")
|
|
|
logger:debug("Presentation file: ", pres)
|
|
|
|
|
|
-- Thumbnail.
|
|
@@ -452,7 +462,7 @@ local function generate_ores(s, mconf)
|
|
|
|
|
|
out_html = templates.ores.data({
|
|
|
--webroot = M.webroot,
|
|
|
- site_title = pkar.config.site.title,
|
|
|
+ site_title = pkar.config.pres_gen.title,
|
|
|
fname = path.basename(techmd.source_path[1]),
|
|
|
head_tpl = templates.head.data,
|
|
|
header_tpl = templates.header.data,
|
|
@@ -679,7 +689,7 @@ M.generate_homepage = function()
|
|
|
)
|
|
|
local i = 1
|
|
|
for s in s_ts:iter() do
|
|
|
- if i > (pkar.config.htmlgen.max_homepage_items or 10) then break end
|
|
|
+ if i > (pkar.config.pres_gen.max_homepage_items or 10) then break end
|
|
|
|
|
|
table.insert(idx_data.objects, {
|
|
|
href = pkar.gen_pairtree("/res", s.data, ".html", true),
|
|
@@ -715,14 +725,14 @@ M.generate_homepage = function()
|
|
|
|
|
|
out_html = templates.idx.data({
|
|
|
webroot = M.webroot,
|
|
|
- site_title = pkar.config.site.title,
|
|
|
+ site_title = pkar.config.pres_gen.title,
|
|
|
head_tpl = templates.head.data,
|
|
|
header_tpl = templates.header.data,
|
|
|
nsm = nsm,
|
|
|
idx_data = idx_data,
|
|
|
})
|
|
|
|
|
|
- local idx_path = path.join(pkar.config.htmlgen.out_dir, "index.html")
|
|
|
+ local idx_path = path.join(pkar.config.pres_gen.out_dir, "index.html")
|
|
|
local ofh = assert(io.open(idx_path, "w"))
|
|
|
|
|
|
logger:debug("Writing info at ", idx_path)
|
|
@@ -737,9 +747,9 @@ M.reset_site = function()
|
|
|
-- Reset target folders.
|
|
|
-- TODO for larger sites, a selective update should be implemented by
|
|
|
-- comparing RDF resource timestamps with HTML page timestamps. Post-MVP.
|
|
|
- if path.isdir(pkar.config.htmlgen.out_dir) then
|
|
|
+ if path.isdir(pkar.config.pres_gen.out_dir) then
|
|
|
logger:warn("Removing existing web site.")
|
|
|
- dir.rmtree(pkar.config.htmlgen.out_dir)
|
|
|
+ dir.rmtree(pkar.config.pres_gen.out_dir)
|
|
|
end
|
|
|
|
|
|
-- Recreate asset dir.
|
|
@@ -750,9 +760,10 @@ M.reset_site = function()
|
|
|
dir.makepath(M.asset_dir)
|
|
|
|
|
|
-- Copy static assets.
|
|
|
- logger:info("Copying templates dir " .. datafile.path("templates/assets") .. " to " .. M.asset_dir)
|
|
|
+ logger:info(
|
|
|
+ "Copying templates dir " .. M.src_asset_dir .. " to " .. M.asset_dir)
|
|
|
assert(dir.clonetree(
|
|
|
- datafile.path("templates/assets"),
|
|
|
+ M.src_asset_dir,
|
|
|
M.asset_dir, dir.copyfile)
|
|
|
)
|
|
|
end
|