@riboseinc/anafero-cli 0.0.53 → 0.0.54

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/build-site.mjs CHANGED
@@ -316974,6 +316974,15 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
316974
316974
  const canonicalURIs = {};
316975
316975
  const originalURIs = {};
316976
316976
  const contentAdapters = {};
316977
+ function getAdapter(canonicalURI) {
316978
+ const adapter3 = contentAdapters[canonicalURI];
316979
+ if (adapter3) {
316980
+ return adapter3;
316981
+ } else {
316982
+ console.error("Resource does not have associated content adapter on record", canonicalURI);
316983
+ throw new Error("Resource does not have associated content adapter on record");
316984
+ }
316985
+ }
316977
316986
  const resourceReaders = {};
316978
316987
  let totalPathCount = 0;
316979
316988
  let totalRelationCount = 0;
@@ -316982,15 +316991,15 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
316982
316991
  const [relationsProgress] = reportProgress("read resources");
316983
316992
  await processRelations(entryPointURI, relationsProgress);
316984
316993
  relationsProgress(null);
316985
- const [hierarchyProgress] = reportProgress("prepare site structure");
316986
- processHierarchy(
316994
+ const [pageProgress] = reportProgress("prepare page structure");
316995
+ processPage(
316987
316996
  canonicalURIs[entryPointURI] ?? entryPointURI,
316988
316997
  "",
316989
- function reportHierarchyProgress(state) {
316990
- hierarchyProgress({ state });
316998
+ function reportPageProgress(state) {
316999
+ pageProgress({ state });
316991
317000
  }
316992
317001
  );
316993
- hierarchyProgress(null);
317002
+ pageProgress(null);
316994
317003
  }
316995
317004
  await process14();
316996
317005
  async function processRelations(entryPointURI2, onProgress, _seenEntryPoints) {
@@ -317080,7 +317089,6 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
317080
317089
  } else {
317081
317090
  }
317082
317091
  } else {
317083
- console.debug("URI relation is seen again", relation.target);
317084
317092
  }
317085
317093
  }
317086
317094
  }
@@ -317159,14 +317167,38 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
317159
317167
  return false;
317160
317168
  }
317161
317169
  }
317170
+ function describeResource(resourceURI) {
317171
+ if (!cache3.has(`metadata/${resourceURI}`)) {
317172
+ const graph = getResourceGraph(resourceURI);
317173
+ const contentAdapter = getAdapter(resourceURI);
317174
+ const meta = contentAdapter.describe(graph);
317175
+ const path3 = cache3.get(`path-for/${resourceURI}`);
317176
+ if (!meta.primaryLanguageID && !path3.includes("#")) {
317177
+ if (cache3.has(`${path3}/parents`)) {
317178
+ const parentResourcePaths = cache3.get(`${path3}/parents`);
317179
+ for (const p3 of parentResourcePaths) {
317180
+ const parentURI = cache3.get(p3);
317181
+ const parentMeta = describeResource(parentURI);
317182
+ if (parentMeta.primaryLanguageID) {
317183
+ meta.primaryLanguageID = parentMeta.primaryLanguageID;
317184
+ break;
317185
+ }
317186
+ console.warn("describeResource: no language, and no parents with language, for", path3);
317187
+ }
317188
+ } else {
317189
+ console.warn("describeResource: no language, and no parents, for", path3);
317190
+ }
317191
+ }
317192
+ cache3.set({
317193
+ [`metadata/${resourceURI}`]: meta
317194
+ });
317195
+ }
317196
+ return cache3.get(`metadata/${resourceURI}`);
317197
+ }
317162
317198
  function getResourceGraph(resourceURI) {
317163
317199
  if (!cache3.has(`graphs/${resourceURI}`)) {
317164
317200
  cache3.add(`graphs/${resourceURI}`, []);
317165
- const contentAdapter = contentAdapters[resourceURI];
317166
- if (!contentAdapter) {
317167
- console.error("Resource does not have associated content adapter on record", resourceURI);
317168
- throw new Error("Resource does not have associated content adapter on record");
317169
- }
317201
+ const contentAdapter = getAdapter(resourceURI);
317170
317202
  const queue = [resourceURI];
317171
317203
  while (queue.length > 0) {
317172
317204
  const currentResource = queue.pop();
@@ -317193,7 +317225,7 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
317193
317225
  }
317194
317226
  return cache3.list(`graphs/${resourceURI}`);
317195
317227
  }
317196
- function processResourceContents(contentAdapter, resourceURI, containingResourcePath, _seen) {
317228
+ function processFragment(contentAdapter, resourceURI, containingResourcePath, _seen) {
317197
317229
  contentAdapters[resourceURI] = contentAdapter;
317198
317230
  const seen = _seen ?? /* @__PURE__ */ new Set();
317199
317231
  cache3.set({
@@ -317207,12 +317239,12 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
317207
317239
  continue;
317208
317240
  } else {
317209
317241
  seen.add(key);
317210
- processResourceContents(contentAdapter, rel.target, containingResourcePath, seen);
317242
+ processFragment(contentAdapter, rel.target, containingResourcePath, seen);
317211
317243
  }
317212
317244
  }
317213
317245
  }
317214
317246
  }
317215
- function processHierarchy(resourceURI, pathPrefix, onProgress) {
317247
+ function processPage(resourceURI, pathPrefix, onProgress, meta) {
317216
317248
  const canonicalURI = canonicalURIs[resourceURI] ?? resourceURI;
317217
317249
  const contentAdapter = findContentAdapter(canonicalURI);
317218
317250
  contentAdapters[canonicalURI] = contentAdapter;
@@ -317244,9 +317276,9 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
317244
317276
  throw new Error("Generated path component is not valid");
317245
317277
  }
317246
317278
  const newPath = pathPrefix ? `${pathPrefix}/${maybePathComponent}` : maybePathComponent;
317247
- processHierarchy(rel.target, newPath, onProgress);
317279
+ processPage(rel.target, newPath, onProgress, meta);
317248
317280
  } else if (isURIString(rel.target)) {
317249
- processResourceContents(contentAdapter, rel.target, pathPrefix);
317281
+ processFragment(contentAdapter, rel.target, pathPrefix);
317250
317282
  }
317251
317283
  }
317252
317284
  }
@@ -317264,13 +317296,14 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
317264
317296
  yield {
317265
317297
  path: path3,
317266
317298
  resourceURI,
317299
+ meta: describeResource(resourceURI),
317267
317300
  directDescendants: cache3.has(`${path3}/direct-descendants`) ? cache3.list(`${path3}/direct-descendants`).map((path4) => {
317268
317301
  const res = getCachedResourceURIForPath(path4);
317269
- return [`/${path4}`, res, getResourceGraph(res)];
317302
+ return [`/${path4}`, res, describeResource(res)];
317270
317303
  }) : [],
317271
317304
  parentChain: path3 !== "" ? cache3.list(`${path3}/parents`).map((path4) => {
317272
317305
  const res = getCachedResourceURIForPath(path4);
317273
- return [`/${path4}`, res, getResourceGraph(res)];
317306
+ return [`/${path4}`, res, describeResource(res)];
317274
317307
  }) : []
317275
317308
  };
317276
317309
  }
@@ -317304,6 +317337,12 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
317304
317337
  throw new Error("Unable to find URL for resource");
317305
317338
  }
317306
317339
  },
317340
+ describe: function describe(resourceURI) {
317341
+ return describeResource(resourceURI);
317342
+ },
317343
+ describeRoot: function describeRoot() {
317344
+ return describeResource(cache3.get(""));
317345
+ },
317307
317346
  resolve: function resolveGraph(resourceURI) {
317308
317347
  return getResourceGraph(resourceURI);
317309
317348
  }
@@ -317352,21 +317391,21 @@ var lunrLanguageSupport = {
317352
317391
  };
317353
317392
  var encoder = new TextEncoder();
317354
317393
  var decoder = new TextDecoder();
317355
- function* generateResourceAssets(resourceURI, relations, parentChain, directDescendants, resourceProps, expandVersionedPath, getDOMStub, inject, workspaceTitle, primaryLanguageID, describe, generateContent) {
317394
+ function* generateResourceAssets(resourceURI, relations, parentChain, directDescendants, resourceProps, expandVersionedPath, getDOMStub, inject, workspaceTitle, primaryLanguageID, generateContent) {
317356
317395
  const generatedContent = generateContent(relations, resourceURI);
317357
317396
  if (!generatedContent) {
317358
317397
  console.warn("Resource has no content", resourceURI);
317359
317398
  return;
317360
317399
  }
317361
- const generateNavLink = function generateNavLink2(path3, uri, graph) {
317400
+ const generateNavLink = function generateNavLink2(path3, uri, meta) {
317362
317401
  return {
317363
317402
  path: expandVersionedPath(path3),
317364
- plainTitle: describe(graph, uri)?.labelInPlainText ?? uri
317403
+ plainTitle: meta?.labelInPlainText ?? uri
317365
317404
  };
317366
317405
  };
317367
317406
  const resourceNav = {
317368
- breadcrumbs: parentChain.map(([path3, uri, graph]) => generateNavLink(path3, uri, graph)),
317369
- children: directDescendants.map(([path3, uri, graph]) => generateNavLink(path3, uri, graph))
317407
+ breadcrumbs: parentChain.map(([path3, uri, meta]) => generateNavLink(path3, uri, meta)),
317408
+ children: directDescendants.map(([path3, uri, meta]) => generateNavLink(path3, uri, meta))
317370
317409
  };
317371
317410
  yield {
317372
317411
  "/resource.json": encoder.encode(JSON.stringify(relations, null, 4)),
@@ -317507,8 +317546,10 @@ ${inject.head ?? ""}`;
317507
317546
  const resourceDescriptions = {};
317508
317547
  const contentCache = {};
317509
317548
  const assetsToWrite = {};
317510
- let maybePrimaryLanguageID = void 0;
317511
- let maybeMainTitle = void 0;
317549
+ const rootMeta = reader.describeRoot();
317550
+ const maybePrimaryLanguageID = rootMeta.primaryLanguageID ?? "en";
317551
+ const maybeMainTitle = rootMeta.labelInPlainText ?? "Document";
317552
+ const allLanguages = /* @__PURE__ */ new Set();
317512
317553
  function getReverseResourceMap() {
317513
317554
  return Object.fromEntries(Object.entries(resourceMap).map(([k, v]) => [v, k]));
317514
317555
  }
@@ -317522,14 +317563,7 @@ ${inject.head ?? ""}`;
317522
317563
  let done11 = 0;
317523
317564
  const [allPathProgress, pathSubtask] = reportProgress("build page content", { total: totalPaths, done: done11 });
317524
317565
  const hierarchicalResources = reader.generatePaths();
317525
- for (const { path: path3, resourceURI, parentChain, directDescendants } of hierarchicalResources) {
317526
- let contentAdapter;
317527
- try {
317528
- contentAdapter = findContentAdapter(resourceURI)?.[1];
317529
- } catch (e3) {
317530
- console.error("Unable to find content adapter for resource", resourceURI, e3);
317531
- continue;
317532
- }
317566
+ for (const { path: path3, resourceURI, meta, parentChain, directDescendants } of hierarchicalResources) {
317533
317567
  done11 += 1;
317534
317568
  allPathProgress({ total: totalPaths, done: done11 });
317535
317569
  if (path3.startsWith("/")) {
@@ -317544,23 +317578,7 @@ ${inject.head ?? ""}`;
317544
317578
  const relations = reader.resolve(resourceURI);
317545
317579
  resourceMap[path3] = resourceURI;
317546
317580
  resourceGraph.push([resourceURI, "isDefinedBy", `${path3}/resource.json`]);
317547
- const resourceMeta = contentAdapter.describe(relations);
317548
- if (path3 === "" && !maybeMainTitle) {
317549
- maybeMainTitle = resourceMeta.labelInPlainText ?? "Workspace";
317550
- }
317551
- if (!maybePrimaryLanguageID) {
317552
- if (resourceMeta.primaryLanguageID) {
317553
- console.debug(
317554
- "Setting primary language ID:",
317555
- resourceMeta.primaryLanguageID,
317556
- "based on resource",
317557
- resourceURI
317558
- );
317559
- maybePrimaryLanguageID = resourceMeta.primaryLanguageID;
317560
- }
317561
- } else if (!resourceMeta.primaryLanguageID) {
317562
- resourceMeta.primaryLanguageID = maybePrimaryLanguageID;
317563
- }
317581
+ const resourceMeta = meta;
317564
317582
  resourceDescriptions[resourceURI] = resourceMeta;
317565
317583
  pathProgress({ state: "processing referenced files" });
317566
317584
  for (const [, , o2] of relations) {
@@ -317605,12 +317623,8 @@ ${inject.head ?? ""}`;
317605
317623
  expandVersionedPath,
317606
317624
  getDOMStub,
317607
317625
  { head: extraHead, tail: inject.tail, htmlAttrs: inject.htmlAttrs },
317608
- maybeMainTitle ?? "Workspace",
317609
- resourceMeta.primaryLanguageID ?? maybePrimaryLanguageID ?? "en",
317610
- function describe(relations2, uri) {
317611
- const maybeAdapter = findContentAdapter(uri);
317612
- return maybeAdapter ? maybeAdapter[1].describe(relations2) : null;
317613
- },
317626
+ maybeMainTitle,
317627
+ resourceMeta.primaryLanguageID ?? maybePrimaryLanguageID,
317614
317628
  function generateContent(relations2, uri) {
317615
317629
  if (!contentCache[uri]) {
317616
317630
  let content;
@@ -317630,9 +317644,10 @@ ${inject.head ?? ""}`;
317630
317644
  );
317631
317645
  throw e3;
317632
317646
  }
317647
+ const primaryLanguageID = resourceMeta.primaryLanguageID ?? maybePrimaryLanguageID;
317633
317648
  contentCache[uri] = {
317634
317649
  adapterID: maybeAdapter[0],
317635
- content: content ? { primaryLanguageID: maybePrimaryLanguageID, ...content } : null
317650
+ content: content ? { primaryLanguageID, ...content } : null
317636
317651
  };
317637
317652
  if (content) {
317638
317653
  const describedResourceIDs = gatherDescribedResourcesFromJsonifiedProseMirrorNode(content.contentDoc);
@@ -317641,10 +317656,7 @@ ${inject.head ?? ""}`;
317641
317656
  const pathWithFragment = `${path3}#${encodeURIComponent(inPageResourceID)}`;
317642
317657
  resourceMap[pathWithFragment] = inPageResourceID;
317643
317658
  resourceGraph.push([inPageResourceID, "isDefinedBy", `${path3}/resource.json`]);
317644
- resourceDescriptions[inPageResourceID] = {
317645
- primaryLanguageID: maybePrimaryLanguageID,
317646
- ...maybeAdapter[1].describe(relativeGraph(relations2, inPageResourceID))
317647
- };
317659
+ resourceDescriptions[inPageResourceID] = reader.describe(inPageResourceID);
317648
317660
  } else {
317649
317661
  console.warn(
317650
317662
  "Subresource on page does not exist in the graph",
@@ -317683,14 +317695,30 @@ ${inject.head ?? ""}`;
317683
317695
  import_lunr.default.utils.warn = console.warn;
317684
317696
  const lunrIndex = (0, import_lunr.default)(function() {
317685
317697
  console.debug(`Search index: primary language is \u201C${maybePrimaryLanguageID}\u201D`);
317686
- if (maybePrimaryLanguageID && maybePrimaryLanguageID !== "en" && lunrLanguageSupport[maybePrimaryLanguageID]) {
317687
- console.debug("Search index: enabling multi-language Lunr mode & mixed tokenizer");
317688
- lunrLanguageSupport[maybePrimaryLanguageID](import_lunr.default);
317698
+ const supportedLanguages = [...allLanguages].filter((lang) => !!lunrLanguageSupport[lang]);
317699
+ const supportedNonDefaultLanguages = supportedLanguages.filter((lang) => lang !== "en");
317700
+ if (supportedLanguages.length > 1) {
317689
317701
  (0, import_lunr4.default)(import_lunr.default);
317690
- this.use(import_lunr.default.multiLanguage("en", maybePrimaryLanguageID));
317691
- this.tokenizer = function(x2) {
317692
- return import_lunr.default.tokenizer(x2).concat(import_lunr.default[maybePrimaryLanguageID].tokenizer(x2));
317693
- };
317702
+ }
317703
+ if (maybePrimaryLanguageID) {
317704
+ if (supportedLanguages.length > 1) {
317705
+ for (const lang of supportedNonDefaultLanguages) {
317706
+ lunrLanguageSupport[lang](import_lunr.default);
317707
+ }
317708
+ for (const lang of supportedNonDefaultLanguages) {
317709
+ this.use(import_lunr.default[lang]);
317710
+ }
317711
+ console.debug(
317712
+ "Search index: enabling multi-language Lunr mode & mixed tokenizer",
317713
+ supportedLanguages.join(", ")
317714
+ );
317715
+ this.use(import_lunr.default.multiLanguage(...supportedLanguages));
317716
+ this.tokenizer = function(x2) {
317717
+ return import_lunr.default.tokenizer(x2).concat(...supportedNonDefaultLanguages.map((lang) => import_lunr.default[lang].tokenizer(x2)));
317718
+ };
317719
+ } else if (maybePrimaryLanguageID !== "en") {
317720
+ this.use(import_lunr.default[maybePrimaryLanguageID]);
317721
+ }
317694
317722
  }
317695
317723
  this.ref("name");
317696
317724
  this.field("body");
@@ -317699,7 +317727,7 @@ ${inject.head ?? ""}`;
317699
317727
  for (const [uri, content] of Object.entries(contentCache)) {
317700
317728
  done12 += 1;
317701
317729
  indexProgress({ state: `adding entry for ${uri}`, total, done: done12 });
317702
- const label = content?.content?.labelInPlainText;
317730
+ const label = content?.content?.labelInPlainText?.normalize("NFKD").replace(/\p{Diacritic}/gu, "");
317703
317731
  if (label) {
317704
317732
  const entry = {
317705
317733
  name: uri,
@@ -317709,20 +317737,21 @@ ${inject.head ?? ""}`;
317709
317737
  } else {
317710
317738
  console.warn("No label for", uri);
317711
317739
  }
317740
+ if (label?.includes("echelle")) {
317741
+ console.debug("Entry", uri, label);
317742
+ }
317712
317743
  }
317713
- for (const [uri, desc] of Object.entries(resourceDescriptions)) {
317744
+ for (const [uri] of Object.entries(resourceDescriptions)) {
317714
317745
  done12 += 1;
317715
317746
  indexProgress({ state: "adding entries for subresources", total, done: done12 });
317716
- const lang = desc.primaryLanguageID;
317717
- if (lang && lang !== maybePrimaryLanguageID && lang !== "en" && import_lunr.default.hasOwnProperty(lang)) {
317718
- console.warn("Resource language is different from primary language, this may not work");
317719
- this.use(import_lunr.default.multiLanguage("en", lang));
317720
- }
317721
317747
  const rels = reader.resolve(uri);
317722
317748
  const relationsExcludingReferences = rels.filter(
317723
317749
  ([s2, p3, o2]) => p3 === "hasPart" && (s2 === ROOT_SUBJECT || s2 === uri) && !o2.startsWith("data:") && (!isURIString(o2) || !reader.exists(o2))
317724
317750
  );
317725
- const body = relationsExcludingReferences.map(([s2, p3, o2]) => o2).join("").trim();
317751
+ const body = relationsExcludingReferences.map(([, , o2]) => o2).join("").trim().normalize("NFKD").replace(/\p{Diacritic}/gu, "").trim();
317752
+ if (body.includes("echelle")) {
317753
+ console.debug("Subresource", uri, body);
317754
+ }
317726
317755
  if (body) {
317727
317756
  const entry = {
317728
317757
  name: uri,
@@ -317837,9 +317866,6 @@ async function* generateStaticSiteAssets(versions, currentVersionID, opts) {
317837
317866
  versionProgress(null);
317838
317867
  }
317839
317868
  }
317840
- function relativeGraph(relations, subj) {
317841
- return relations.filter(([s2]) => s2 !== ROOT_SUBJECT).map(([s2, p3, o2]) => [s2 === subj ? ROOT_SUBJECT : s2, p3, o2]);
317842
- }
317843
317869
 
317844
317870
  // dependencies.mts
317845
317871
  init_cjs_shim();
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@riboseinc/anafero-cli",
3
3
  "type": "module",
4
- "version": "0.0.53",
4
+ "version": "0.0.54",
5
5
  "packageManager": "yarn@4.5.0",
6
6
  "bin": {
7
7
  "build-site": "build-site.mjs"
8
8
  },
9
9
  "scripts": {
10
- "cbp": "yarn clean-all; yarn compile; yarn build-generator-builder && yarn build-generator -- --debug && sed 's#^import devtools#//import devtools#' build-site.mjs > ._tmp && mv ._tmp build-site.mjs && npm pack",
11
- "bp": "rm -f riboseinc-anafero-*.tgz; yarn build-generator -- --debug && npm pack",
10
+ "cbp": "yarn clean-all; yarn compile; yarn build-generator-builder && yarn build-generator -- --debug && sed 's#^import devtools#//import devtools#' build-site.mjs > ._tmp && mv ._tmp build-site.mjs && npm pack && mv *.tgz dist/",
11
+ "bp": "rm -f dist/riboseinc-anafero-*.tgz; yarn build-generator -- --debug && npm pack",
12
12
  "build-generator-builder": "yarn esbuild build-generator.mts --log-level=debug --packages=external --platform=node --target=node18 --minify=false --bundle --format=esm --outfile=build-generator.mjs",
13
13
  "build-generator": "yarn node build-generator.mjs --",
14
- "clean-all": "rm -f riboseinc-anafero-*.tgz build-generator.mjs build-site.mjs bootstrap.js *.css",
14
+ "clean-all": "find compiled -name 'README.rst' -prune -o -delete; rm -f dist/riboseinc-anafero-*.tgz build-generator.mjs build-site.mjs bootstrap.js *.css",
15
15
  "compile": "tsc --outdir compiled"
16
16
  },
17
17
  "dependencies": {
package/tsconfig.json CHANGED
@@ -18,9 +18,6 @@
18
18
  "exactOptionalPropertyTypes": true,
19
19
  "skipLibCheck": true,
20
20
 
21
- "allowImportingTsExtensions": true, // XXX
22
- "noEmit": true, // XXX
23
-
24
21
  "isolatedModules": true,
25
22
  "esModuleInterop": true,
26
23
 
Binary file