@canopy-iiif/app 0.6.28 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build/assets.js +30 -0
- package/lib/build/build.js +128 -0
- package/lib/{dev.js → build/dev.js} +494 -205
- package/lib/build/facets.js +19 -0
- package/lib/{iiif.js → build/iiif.js} +242 -384
- package/lib/build/log.js +31 -0
- package/lib/{mdx.js → build/mdx.js} +13 -10
- package/lib/build/pages.js +141 -0
- package/lib/build/runtimes.js +58 -0
- package/lib/build/search-index.js +42 -0
- package/lib/build/search-workflow.js +61 -0
- package/lib/build/search.js +219 -0
- package/lib/build/styles.js +141 -0
- package/lib/{thumbnail.js → iiif/thumbnail.js} +0 -1
- package/lib/index.js +2 -3
- package/lib/{search.js → search/search.js} +8 -8
- package/package.json +2 -1
- package/lib/build.js +0 -762
- package/lib/components/IIIFCard.js +0 -102
- package/lib/log.js +0 -64
- package/lib/runtime/command-entry.jsx +0 -44
- /package/lib/{devtoast.config.json → build/devtoast.config.json} +0 -0
- /package/lib/{devtoast.css → build/devtoast.css} +0 -0
- /package/lib/{search-app.jsx → search/search-app.jsx} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { fs, fsp, path, ASSETS_DIR, OUT_DIR, ensureDirSync } = require('../common');
|
|
2
|
+
const { logLine } = require('./log');
|
|
3
|
+
|
|
4
|
+
async function copyAssets() {
|
|
5
|
+
try {
|
|
6
|
+
if (!fs.existsSync(ASSETS_DIR)) return;
|
|
7
|
+
} catch (_) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
async function walk(dir) {
|
|
11
|
+
const entries = await fsp.readdir(dir, { withFileTypes: true });
|
|
12
|
+
for (const e of entries) {
|
|
13
|
+
const src = path.join(dir, e.name);
|
|
14
|
+
const rel = path.relative(ASSETS_DIR, src);
|
|
15
|
+
const dest = path.join(OUT_DIR, rel);
|
|
16
|
+
if (e.isDirectory()) { ensureDirSync(dest); await walk(src); }
|
|
17
|
+
else if (e.isFile()) {
|
|
18
|
+
ensureDirSync(path.dirname(dest));
|
|
19
|
+
await fsp.copyFile(src, dest);
|
|
20
|
+
try { logLine(`• Asset ${path.relative(process.cwd(), dest)}`, 'cyan', { dim: true }); } catch (_) {}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
try { logLine('• Copying assets...', 'blue', { bright: true }); } catch (_) {}
|
|
25
|
+
await walk(ASSETS_DIR);
|
|
26
|
+
try { logLine('✓ Assets copied', 'green'); } catch (_) {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = { copyAssets };
|
|
30
|
+
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const {
|
|
2
|
+
fs,
|
|
3
|
+
path,
|
|
4
|
+
CONTENT_DIR,
|
|
5
|
+
OUT_DIR,
|
|
6
|
+
ensureDirSync,
|
|
7
|
+
cleanDir,
|
|
8
|
+
} = require("../common");
|
|
9
|
+
const mdx = require("./mdx");
|
|
10
|
+
const iiif = require("./iiif");
|
|
11
|
+
const pages = require("./pages");
|
|
12
|
+
const searchBuild = require("./search");
|
|
13
|
+
const { buildSearchIndex } = require("./search-index");
|
|
14
|
+
const runtimes = require("./runtimes");
|
|
15
|
+
const {
|
|
16
|
+
ensureSearchInitialized,
|
|
17
|
+
finalizeSearch,
|
|
18
|
+
} = require("./search-workflow");
|
|
19
|
+
const { ensureStyles } = require("./styles");
|
|
20
|
+
const { copyAssets } = require("./assets");
|
|
21
|
+
const { logLine } = require("./log");
|
|
22
|
+
|
|
23
|
+
// hold records between builds if skipping IIIF
|
|
24
|
+
let iiifRecordsCache = [];
|
|
25
|
+
let pageRecords = [];
|
|
26
|
+
|
|
27
|
+
async function build(options = {}) {
|
|
28
|
+
const skipIiif = !!(options?.skipIiif || process.env.CANOPY_SKIP_IIIF === '1' || process.env.CANOPY_SKIP_IIIF === 'true');
|
|
29
|
+
if (!fs.existsSync(CONTENT_DIR)) {
|
|
30
|
+
console.error("No content directory found at", CONTENT_DIR);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Clean and prepare output directory
|
|
36
|
+
*/
|
|
37
|
+
logLine("\nClean and prepare directories", "magenta", {
|
|
38
|
+
bright: true,
|
|
39
|
+
underscore: true,
|
|
40
|
+
});
|
|
41
|
+
logLine("• Reset MDX cache", "blue", { dim: true });
|
|
42
|
+
mdx?.resetMdxCaches();
|
|
43
|
+
if (!skipIiif) {
|
|
44
|
+
await cleanDir(OUT_DIR);
|
|
45
|
+
logLine(`• Cleaned output directory`, "blue", { dim: true });
|
|
46
|
+
} else {
|
|
47
|
+
logLine("• Retaining cache (skipping IIIF rebuild)", "blue", { dim: true });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Build IIIF Collection content from configured source(s).
|
|
52
|
+
* This includes building IIIF manifests for works and collections,
|
|
53
|
+
* as well as collecting search records for works.
|
|
54
|
+
*/
|
|
55
|
+
logLine("\nBuild IIIF Collection content", "magenta", {
|
|
56
|
+
bright: true,
|
|
57
|
+
underscore: true,
|
|
58
|
+
});
|
|
59
|
+
let iiifRecords = [];
|
|
60
|
+
if (!skipIiif) {
|
|
61
|
+
const CONFIG = await iiif.loadConfig();
|
|
62
|
+
const results = await iiif.buildIiifCollectionPages(CONFIG);
|
|
63
|
+
iiifRecords = results?.iiifRecords;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Build contextual MDX content from the content directory.
|
|
68
|
+
* This includes collecting page metadata for sitemap and search index,
|
|
69
|
+
* as well as building all MDX pages to HTML.
|
|
70
|
+
*/
|
|
71
|
+
logLine("\nBuild contextual content from Markdown pages", "magenta", {
|
|
72
|
+
bright: true,
|
|
73
|
+
underscore: true,
|
|
74
|
+
});
|
|
75
|
+
pageRecords = await searchBuild.collectMdxPageRecords();
|
|
76
|
+
await pages.buildContentTree(CONTENT_DIR, pageRecords);
|
|
77
|
+
logLine("✓ MDX pages built", "green");
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Build search index from IIIF and MDX records, then build or update
|
|
81
|
+
* the search.html page and search runtime bundle.
|
|
82
|
+
* This is done after all content is built so that the index is comprehensive.
|
|
83
|
+
*/
|
|
84
|
+
logLine("\nCreate search indices", "magenta", {
|
|
85
|
+
bright: true,
|
|
86
|
+
underscore: true,
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
await ensureSearchInitialized();
|
|
90
|
+
const combined = await buildSearchIndex(iiifRecords, pageRecords);
|
|
91
|
+
await finalizeSearch(combined);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
logLine("✗ Search index creation failed", "red", { bright: true });
|
|
94
|
+
logLine(" " + String(e), "red");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Prepare client runtimes (e.g. search) by bundling with esbuild.
|
|
99
|
+
* This is done early so that MDX content can reference runtime assets if needed.
|
|
100
|
+
*/
|
|
101
|
+
logLine("\nPrepare client runtimes and stylesheets", "magenta", {
|
|
102
|
+
bright: true,
|
|
103
|
+
underscore: true,
|
|
104
|
+
});
|
|
105
|
+
if (!process.env.CANOPY_SKIP_STYLES) {
|
|
106
|
+
await ensureStyles();
|
|
107
|
+
logLine("✓ Wrote styles.css", "cyan");
|
|
108
|
+
}
|
|
109
|
+
await runtimes.prepareAllRuntimes();
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Copy static assets from the assets directory to the output directory.
|
|
113
|
+
*/
|
|
114
|
+
logLine("\nCopy static assets", "magenta", {
|
|
115
|
+
bright: true,
|
|
116
|
+
underscore: true,
|
|
117
|
+
});
|
|
118
|
+
await copyAssets();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
module.exports = { build };
|
|
122
|
+
|
|
123
|
+
if (require.main === module) {
|
|
124
|
+
build().catch((e) => {
|
|
125
|
+
console.error(e);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
});
|
|
128
|
+
}
|