@canopy-iiif/app 0.9.1 → 0.9.3

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/mdx.js CHANGED
@@ -11,6 +11,42 @@ const {
11
11
  ensureDirSync,
12
12
  withBase,
13
13
  } = require("../common");
14
+
15
+ const EXTRA_REMARK_PLUGINS = (() => {
16
+ try {
17
+ const absPath = path.resolve(process.cwd(), "packages/helpers/docs/remark-code-meta.js");
18
+ if (fs.existsSync(absPath)) {
19
+ const plugin = require(absPath);
20
+ if (typeof plugin === "function") return [plugin];
21
+ }
22
+ } catch (_) {}
23
+ return [];
24
+ })();
25
+
26
+ function buildCompileOptions(overrides = {}) {
27
+ const base = {
28
+ jsx: false,
29
+ development: false,
30
+ providerImportSource: "@mdx-js/react",
31
+ jsxImportSource: "react",
32
+ format: "mdx",
33
+ };
34
+ const remarkPlugins = [];
35
+ if (overrides && Array.isArray(overrides.remarkPlugins)) {
36
+ remarkPlugins.push(...overrides.remarkPlugins);
37
+ }
38
+ if (EXTRA_REMARK_PLUGINS.length) {
39
+ remarkPlugins.push(...EXTRA_REMARK_PLUGINS);
40
+ }
41
+ if (remarkPlugins.length) {
42
+ base.remarkPlugins = remarkPlugins;
43
+ }
44
+ if (overrides && typeof overrides === "object") {
45
+ const { remarkPlugins: _omit, ...rest } = overrides;
46
+ Object.assign(base, rest);
47
+ }
48
+ return base;
49
+ }
14
50
  const yaml = require("js-yaml");
15
51
  const { getPageContext } = require("../page-context");
16
52
 
@@ -183,6 +219,23 @@ function extractHeadings(mdxSource) {
183
219
  return headings;
184
220
  }
185
221
 
222
+ function extractPlainText(mdxSource) {
223
+ let { content } = parseFrontmatter(String(mdxSource || ''));
224
+ if (!content) return '';
225
+ content = content.replace(/```[\s\S]*?```/g, ' ');
226
+ content = content.replace(/`{1,3}([^`]+)`{1,3}/g, '$1');
227
+ content = content.replace(/!\[[^\]]*\]\([^)]*\)/g, ' ');
228
+ content = content.replace(/\[[^\]]*\]\([^)]*\)/g, '$1');
229
+ content = content.replace(/<[^>]+>/g, ' ');
230
+ content = content.replace(/\{#([^}]+)\}/g, ' ');
231
+ content = content.replace(/\{\/[A-Za-z0-9_.-]+\}/g, ' ');
232
+ content = content.replace(/\{[^{}]*\}/g, ' ');
233
+ content = content.replace(/[#>*~_\-]+/g, ' ');
234
+ content = content.replace(/\n+/g, ' ');
235
+ content = content.replace(/\s+/g, ' ').trim();
236
+ return content;
237
+ }
238
+
186
239
  function extractTitle(mdxSource) {
187
240
  const { data, content } = parseFrontmatter(String(mdxSource || ""));
188
241
  if (data && typeof data.title === "string" && data.title.trim()) {
@@ -238,15 +291,7 @@ async function loadAppWrapper() {
238
291
  const { compile } = await import("@mdx-js/mdx");
239
292
  const raw = await fsp.readFile(appPath, "utf8");
240
293
  const { content: source } = parseFrontmatter(raw);
241
- let code = String(
242
- await compile(source, {
243
- jsx: false,
244
- development: false,
245
- providerImportSource: "@mdx-js/react",
246
- jsxImportSource: "react",
247
- format: "mdx",
248
- })
249
- );
294
+ let code = String(await compile(source, buildCompileOptions()));
250
295
  // MDX v3 default export (MDXContent) does not forward external children.
251
296
  // When present, expose the underlying layout function as __MDXLayout for wrapping.
252
297
  if (
@@ -290,13 +335,7 @@ async function compileMdxFile(filePath, outPath, Layout, extraProps = {}) {
290
335
  const { compile } = await import("@mdx-js/mdx");
291
336
  const raw = await fsp.readFile(filePath, "utf8");
292
337
  const { content: source } = parseFrontmatter(raw);
293
- const compiled = await compile(source, {
294
- jsx: false,
295
- development: false,
296
- providerImportSource: "@mdx-js/react",
297
- jsxImportSource: "react",
298
- format: "mdx",
299
- });
338
+ const compiled = await compile(source, buildCompileOptions());
300
339
  const code = String(compiled);
301
340
  ensureDirSync(CACHE_DIR);
302
341
  const relCacheName =
@@ -432,13 +471,7 @@ async function compileMdxToComponent(filePath) {
432
471
  const { compile } = await import("@mdx-js/mdx");
433
472
  const raw = await fsp.readFile(filePath, "utf8");
434
473
  const { content: source } = parseFrontmatter(raw);
435
- const compiled = await compile(source, {
436
- jsx: false,
437
- development: false,
438
- providerImportSource: "@mdx-js/react",
439
- jsxImportSource: "react",
440
- format: "mdx",
441
- });
474
+ const compiled = await compile(source, buildCompileOptions());
442
475
  const code = String(compiled);
443
476
  ensureDirSync(CACHE_DIR);
444
477
  const relCacheName =
@@ -934,6 +967,7 @@ async function ensureHeroRuntime() {
934
967
  module.exports = {
935
968
  extractTitle,
936
969
  extractHeadings,
970
+ extractPlainText,
937
971
  isReservedFile,
938
972
  parseFrontmatter,
939
973
  compileMdxFile,
@@ -6,11 +6,16 @@ function pagesToRecords(pageRecords) {
6
6
  const list = Array.isArray(pageRecords) ? pageRecords : [];
7
7
  return list
8
8
  .filter((p) => p && p.href && p.searchInclude)
9
- .map((p) => ({
10
- title: p.title || p.href,
11
- href: rootRelativeHref(p.href),
12
- type: p.searchType || 'page',
13
- }));
9
+ .map((p) => {
10
+ const summary = typeof p.searchSummary === 'string' ? p.searchSummary.trim() : '';
11
+ const record = {
12
+ title: p.title || p.href,
13
+ href: rootRelativeHref(p.href),
14
+ type: p.searchType || 'page',
15
+ };
16
+ if (summary) record.summaryValue = summary;
17
+ return record;
18
+ });
14
19
  }
15
20
 
16
21
  function maybeMockRecords() {
@@ -184,6 +184,8 @@ async function collectMdxPageRecords() {
184
184
  const rel = path.relative(CONTENT_DIR, p).replace(/\.mdx$/i, '.html');
185
185
  if (base !== 'sitemap.mdx') {
186
186
  const href = rootRelativeHref(rel.split(path.sep).join('/'));
187
+ const plainText = mdx.extractPlainText(src);
188
+ const summary = plainText || '';
187
189
  const underSearch = /^search\//i.test(href) || href.toLowerCase() === 'search.html';
188
190
  let include = !underSearch;
189
191
  let resolvedType = null;
@@ -201,7 +203,13 @@ async function collectMdxPageRecords() {
201
203
  resolvedType = 'page';
202
204
  }
203
205
  const trimmedType = resolvedType && String(resolvedType).trim();
204
- pages.push({ title, href, searchInclude: include && !!trimmedType, searchType: trimmedType || undefined });
206
+ pages.push({
207
+ title,
208
+ href,
209
+ searchInclude: include && !!trimmedType,
210
+ searchType: trimmedType || undefined,
211
+ searchSummary: summary,
212
+ });
205
213
  }
206
214
  }
207
215
  }
@@ -231,8 +231,7 @@ function sanitizeRecordForIndex(r) {
231
231
  ''
232
232
  ).trim();
233
233
  if (summaryVal) {
234
- const clipped = summaryVal.length > 1000 ? summaryVal.slice(0, 1000) + '…' : summaryVal;
235
- out.summary = clipped;
234
+ out.summary = summaryVal;
236
235
  }
237
236
  return out;
238
237
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",
@@ -19,9 +19,11 @@
19
19
  "./head": "./lib/head.js",
20
20
  "./orchestrator": {
21
21
  "types": "./types/orchestrator.d.ts",
22
+ "import": "./lib/orchestrator.js",
22
23
  "require": "./lib/orchestrator.js",
23
24
  "default": "./lib/orchestrator.js"
24
- }
25
+ },
26
+ "./docs-legacy-compat": "./docs-legacy-compat.mjs"
25
27
  },
26
28
  "files": [
27
29
  "lib/**",