@riboseinc/anafero-cli 0.0.54 → 0.0.56

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
@@ -313300,7 +313300,9 @@ var ResourceMetadataSchema = mutable3(Struct({
313300
313300
  // TODO: rich ProseMirror labels?
313301
313301
  labelInPlainText: String$2.pipe(nonEmptyString4()),
313302
313302
  // TODO: proper schema for ISO language IDs
313303
- primaryLanguageID: String$2.pipe(optional)
313303
+ primaryLanguageID: String$2.pipe(optional),
313304
+ /** License/copyright for the resource in question. */
313305
+ license: Any.pipe(optional)
313304
313306
  }));
313305
313307
  function gatherDescribedResourcesFromJsonifiedProseMirrorNode(jsonifiedNode, _accum) {
313306
313308
  const accumulator = _accum ?? /* @__PURE__ */ new Set();
@@ -317391,12 +317393,7 @@ var lunrLanguageSupport = {
317391
317393
  };
317392
317394
  var encoder = new TextEncoder();
317393
317395
  var decoder = new TextDecoder();
317394
- function* generateResourceAssets(resourceURI, relations, parentChain, directDescendants, resourceProps, expandVersionedPath, getDOMStub, inject, workspaceTitle, primaryLanguageID, generateContent) {
317395
- const generatedContent = generateContent(relations, resourceURI);
317396
- if (!generatedContent) {
317397
- console.warn("Resource has no content", resourceURI);
317398
- return;
317399
- }
317396
+ function* generateResourceAssets(resourceURI, relations, parentChain, directDescendants, resourceProps, expandVersionedPath, getDOMStub, inject, workspaceTitle, primaryLanguageID, generatedContent) {
317400
317397
  const generateNavLink = function generateNavLink2(path3, uri, meta) {
317401
317398
  return {
317402
317399
  path: expandVersionedPath(path3),
@@ -317549,7 +317546,7 @@ ${inject.head ?? ""}`;
317549
317546
  const rootMeta = reader.describeRoot();
317550
317547
  const maybePrimaryLanguageID = rootMeta.primaryLanguageID ?? "en";
317551
317548
  const maybeMainTitle = rootMeta.labelInPlainText ?? "Document";
317552
- const allLanguages = /* @__PURE__ */ new Set();
317549
+ const allLanguages = /* @__PURE__ */ new Set(["en"]);
317553
317550
  function getReverseResourceMap() {
317554
317551
  return Object.fromEntries(Object.entries(resourceMap).map(([k, v]) => [v, k]));
317555
317552
  }
@@ -317575,110 +317572,115 @@ ${inject.head ?? ""}`;
317575
317572
  throw new Error("Malformed resource URL while processing resources: hash fragment");
317576
317573
  }
317577
317574
  const [pathProgress] = pathSubtask(`${resourceURI.replaceAll("|", ":")}`, { state: "resolving relations" });
317578
- const relations = reader.resolve(resourceURI);
317579
- resourceMap[path3] = resourceURI;
317580
- resourceGraph.push([resourceURI, "isDefinedBy", `${path3}/resource.json`]);
317581
317575
  const resourceMeta = meta;
317582
- resourceDescriptions[resourceURI] = resourceMeta;
317583
- pathProgress({ state: "processing referenced files" });
317584
- for (const [, , o2] of relations) {
317585
- if (o2.startsWith("file:")) {
317586
- const filePath = o2.split("file:")[1];
317587
- const filename = o2.replaceAll("/", "_").replaceAll(":", "_");
317588
- if (!assetsToWrite[filename]) {
317576
+ const relations = reader.resolve(resourceURI);
317577
+ pathProgress({ state: "generating resource page content" });
317578
+ const content = function generateContent(graph, metadata, uri, cache4) {
317579
+ if (!cache4[uri]) {
317580
+ let content2;
317581
+ const maybeAdapter = findContentAdapter(uri);
317582
+ if (maybeAdapter) {
317589
317583
  try {
317590
- assetsToWrite[filename] = await fetchBlobAtThisVersion(filePath);
317591
- resourceGraph.push([
317592
- o2,
317593
- "isDownloadableAt",
317594
- filename
317595
- ]);
317596
- resourceMap[filename] = o2;
317597
- resourceDescriptions[o2] = {
317598
- labelInPlainText: filePath
317599
- };
317584
+ content2 = maybeAdapter[1].generateContent(graph) ?? null;
317600
317585
  } catch (e3) {
317601
- console.error("Failed to fetch asset", filePath);
317586
+ console.error(
317587
+ "Failed to generate resource content",
317588
+ path3,
317589
+ uri,
317590
+ graph.slice(0, 40).join("\n")
317591
+ );
317592
+ throw e3;
317593
+ }
317594
+ if (content2) {
317595
+ contentCache[uri] = {
317596
+ adapterID: maybeAdapter[0],
317597
+ content: { ...metadata, ...content2 }
317598
+ };
317599
+ if (metadata.primaryLanguageID) {
317600
+ allLanguages.add(metadata.primaryLanguageID);
317601
+ }
317602
+ const describedResourceIDs = gatherDescribedResourcesFromJsonifiedProseMirrorNode(content2.contentDoc);
317603
+ for (const inPageResourceID of describedResourceIDs) {
317604
+ if (reader.exists(inPageResourceID)) {
317605
+ const pathWithFragment = `${path3}#${encodeURIComponent(inPageResourceID)}`;
317606
+ resourceMap[pathWithFragment] = inPageResourceID;
317607
+ resourceGraph.push([inPageResourceID, "isDefinedBy", `${path3}/resource.json`]);
317608
+ resourceDescriptions[inPageResourceID] = reader.describe(inPageResourceID);
317609
+ } else {
317610
+ console.warn(
317611
+ "Subresource on page does not exist in the graph",
317612
+ path3,
317613
+ inPageResourceID
317614
+ );
317615
+ }
317616
+ }
317602
317617
  }
317618
+ } else {
317619
+ console.warn("No adapter found to render", uri);
317620
+ return null;
317603
317621
  }
317622
+ } else {
317623
+ console.debug("contentCache hit", uri);
317604
317624
  }
317605
- }
317625
+ return cache4[uri];
317626
+ }(relations, meta, resourceURI, contentCache);
317606
317627
  pathProgress({ state: "generating page content & assets" });
317607
- const resourceAssetGenerator = generateResourceAssets(
317608
- resourceURI,
317609
- relations,
317610
- parentChain,
317611
- directDescendants,
317612
- {
317613
- useDependency: getDependency,
317614
- selectedLayout: layouts[0],
317615
- getResourcePlainTitle: (uri) => resourceDescriptions[uri]?.labelInPlainText ?? uri,
317616
- onIntegrityViolation: console.warn,
317617
- reverseResource: (path4) => getReverseResourceMap()[path4],
317618
- uri: resourceURI,
317619
- // TODO: Consider slash-prepending the outcome of findURL,
317620
- // if it’s reliably not slash-prepended
317621
- locateResource: (uri) => expandVersionedPath(reader.findURL(uri))
317622
- },
317623
- expandVersionedPath,
317624
- getDOMStub,
317625
- { head: extraHead, tail: inject.tail, htmlAttrs: inject.htmlAttrs },
317626
- maybeMainTitle,
317627
- resourceMeta.primaryLanguageID ?? maybePrimaryLanguageID,
317628
- function generateContent(relations2, uri) {
317629
- if (!contentCache[uri]) {
317630
- let content;
317631
- const maybeAdapter = findContentAdapter(uri);
317632
- if (maybeAdapter) {
317628
+ if (content !== null) {
317629
+ resourceMap[path3] = resourceURI;
317630
+ resourceGraph.push([resourceURI, "isDefinedBy", `${path3}/resource.json`]);
317631
+ resourceDescriptions[resourceURI] = resourceMeta;
317632
+ pathProgress({ state: "processing resource assets" });
317633
+ for (const [, , o2] of relations) {
317634
+ if (o2.startsWith("file:")) {
317635
+ const filePath = o2.split("file:")[1];
317636
+ const filename = o2.replaceAll("/", "_").replaceAll(":", "_");
317637
+ if (!assetsToWrite[filename]) {
317633
317638
  try {
317634
- content = maybeAdapter[1].generateContent(
317635
- relations2
317636
- ) ?? null;
317639
+ assetsToWrite[filename] = await fetchBlobAtThisVersion(filePath);
317640
+ resourceGraph.push([
317641
+ o2,
317642
+ "isDownloadableAt",
317643
+ filename
317644
+ ]);
317645
+ resourceMap[filename] = o2;
317646
+ resourceDescriptions[o2] = {
317647
+ labelInPlainText: filePath
317648
+ };
317637
317649
  } catch (e3) {
317638
- console.error(
317639
- "Failed to generate resource content",
317640
- path3,
317641
- resourceMeta,
317642
- uri,
317643
- relations2.slice(0, 40).join("\n")
317644
- );
317645
- throw e3;
317650
+ console.error("Failed to fetch asset", filePath);
317646
317651
  }
317647
- const primaryLanguageID = resourceMeta.primaryLanguageID ?? maybePrimaryLanguageID;
317648
- contentCache[uri] = {
317649
- adapterID: maybeAdapter[0],
317650
- content: content ? { primaryLanguageID, ...content } : null
317651
- };
317652
- if (content) {
317653
- const describedResourceIDs = gatherDescribedResourcesFromJsonifiedProseMirrorNode(content.contentDoc);
317654
- for (const inPageResourceID of describedResourceIDs) {
317655
- if (reader.exists(inPageResourceID)) {
317656
- const pathWithFragment = `${path3}#${encodeURIComponent(inPageResourceID)}`;
317657
- resourceMap[pathWithFragment] = inPageResourceID;
317658
- resourceGraph.push([inPageResourceID, "isDefinedBy", `${path3}/resource.json`]);
317659
- resourceDescriptions[inPageResourceID] = reader.describe(inPageResourceID);
317660
- } else {
317661
- console.warn(
317662
- "Subresource on page does not exist in the graph",
317663
- path3,
317664
- inPageResourceID
317665
- );
317666
- }
317667
- }
317668
- }
317669
- } else {
317670
- console.warn("No adapter found to render", uri);
317671
- return null;
317672
317652
  }
317673
317653
  }
317674
- return contentCache[uri];
317675
317654
  }
317676
- );
317677
- for (const blobChunk of resourceAssetGenerator) {
317678
- yield Object.entries(blobChunk).map(([subpath, blob]) => {
317679
- const assetBlobPath = `/${path3}${subpath}`;
317680
- return { [assetBlobPath]: blob };
317681
- }).reduce((prev, curr) => ({ ...prev, ...curr }));
317655
+ const resourceAssetGenerator = generateResourceAssets(
317656
+ resourceURI,
317657
+ relations,
317658
+ parentChain,
317659
+ directDescendants,
317660
+ {
317661
+ useDependency: getDependency,
317662
+ selectedLayout: layouts[0],
317663
+ getResourcePlainTitle: (uri) => resourceDescriptions[uri]?.labelInPlainText ?? uri,
317664
+ onIntegrityViolation: console.warn,
317665
+ reverseResource: (path4) => getReverseResourceMap()[path4],
317666
+ uri: resourceURI,
317667
+ // TODO: Consider slash-prepending the outcome of findURL,
317668
+ // if it’s reliably not slash-prepended
317669
+ locateResource: (uri) => expandVersionedPath(reader.findURL(uri))
317670
+ },
317671
+ expandVersionedPath,
317672
+ getDOMStub,
317673
+ { head: extraHead, tail: inject.tail, htmlAttrs: inject.htmlAttrs },
317674
+ maybeMainTitle,
317675
+ resourceMeta.primaryLanguageID ?? maybePrimaryLanguageID,
317676
+ content
317677
+ );
317678
+ for (const blobChunk of resourceAssetGenerator) {
317679
+ yield Object.entries(blobChunk).map(([subpath, blob]) => {
317680
+ const assetBlobPath = `/${path3}${subpath}`;
317681
+ return { [assetBlobPath]: blob };
317682
+ }).reduce((prev, curr) => ({ ...prev, ...curr }));
317683
+ }
317682
317684
  }
317683
317685
  pathProgress(null);
317684
317686
  }
@@ -317693,53 +317695,64 @@ ${inject.head ?? ""}`;
317693
317695
  };
317694
317696
  const [indexProgress] = reportProgress("build search index");
317695
317697
  import_lunr.default.utils.warn = console.warn;
317698
+ const supportedLanguages = [...allLanguages].filter((lang) => lang === "en" || !!lunrLanguageSupport[lang]);
317699
+ console.debug(`Search index: primary language is \u201C${maybePrimaryLanguageID}\u201D, enabling ${supportedLanguages.join(", ")}`);
317700
+ const nonDefaultLanguages = supportedLanguages.filter((lang) => lang !== "en");
317701
+ if (supportedLanguages.length > 1) {
317702
+ for (const lang of nonDefaultLanguages) {
317703
+ lunrLanguageSupport[lang](import_lunr.default);
317704
+ }
317705
+ (0, import_lunr4.default)(import_lunr.default);
317706
+ }
317696
317707
  const lunrIndex = (0, import_lunr.default)(function() {
317697
- console.debug(`Search index: primary language is \u201C${maybePrimaryLanguageID}\u201D`);
317698
- const supportedLanguages = [...allLanguages].filter((lang) => !!lunrLanguageSupport[lang]);
317699
- const supportedNonDefaultLanguages = supportedLanguages.filter((lang) => lang !== "en");
317700
317708
  if (supportedLanguages.length > 1) {
317701
- (0, import_lunr4.default)(import_lunr.default);
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]);
317709
+ this.use(import_lunr.default.multiLanguage(...["en", ...nonDefaultLanguages]));
317710
+ console.debug(
317711
+ "Search index: enabling multi-language Lunr mode & mixed tokenizer",
317712
+ supportedLanguages.join(", ")
317713
+ );
317714
+ const lunrTokenizer = import_lunr.default.tokenizer;
317715
+ this.tokenizer = function(x2) {
317716
+ const baseLunrTokens = lunrTokenizer(x2);
317717
+ const tokens = [...baseLunrTokens];
317718
+ for (const lang of nonDefaultLanguages) {
317719
+ const tokenizer = import_lunr.default[lang].tokenizer;
317720
+ if (tokenizer) {
317721
+ const langTokens = tokenizer(x2);
317722
+ tokens.push(...langTokens.filter(
317723
+ (t3) => !baseLunrTokens.find((bt) => bt.toString() === t3.toString())
317724
+ ));
317725
+ } else {
317726
+ }
317710
317727
  }
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
- }
317728
+ return tokens;
317729
+ };
317730
+ const lunrStopWordFilter = import_lunr.default.stopWordFilter;
317731
+ this.stopWordFilter = function(token) {
317732
+ return lunrStopWordFilter(token) && !nonDefaultLanguages.map(
317733
+ (lang) => !!this[lang].stopWordFilter(token)
317734
+ ).includes(false) ? token : void 0;
317735
+ };
317722
317736
  }
317723
317737
  this.ref("name");
317724
317738
  this.field("body");
317725
317739
  let done12 = 0;
317726
317740
  const total = Object.keys(contentCache).length + Object.keys(resourceDescriptions).length;
317741
+ console.debug("Index pipeline functions during", this.pipeline._stack.map((f3) => f3.label));
317742
+ console.debug("Index search pipeline functions during", this.searchPipeline._stack.map((f3) => f3.label));
317727
317743
  for (const [uri, content] of Object.entries(contentCache)) {
317728
317744
  done12 += 1;
317729
317745
  indexProgress({ state: `adding entry for ${uri}`, total, done: done12 });
317730
- const label = content?.content?.labelInPlainText?.normalize("NFKD").replace(/\p{Diacritic}/gu, "");
317746
+ const label = content?.content?.labelInPlainText?.normalize("NFKD").replace(/\p{Diacritic}/gu, "").trim();
317731
317747
  if (label) {
317732
317748
  const entry = {
317733
317749
  name: uri,
317734
317750
  body: label
317735
317751
  };
317736
- this.add(entry);
317752
+ this.add(entry, { boost: 5 });
317737
317753
  } else {
317738
317754
  console.warn("No label for", uri);
317739
317755
  }
317740
- if (label?.includes("echelle")) {
317741
- console.debug("Entry", uri, label);
317742
- }
317743
317756
  }
317744
317757
  for (const [uri] of Object.entries(resourceDescriptions)) {
317745
317758
  done12 += 1;
@@ -317749,9 +317762,6 @@ ${inject.head ?? ""}`;
317749
317762
  ([s2, p3, o2]) => p3 === "hasPart" && (s2 === ROOT_SUBJECT || s2 === uri) && !o2.startsWith("data:") && (!isURIString(o2) || !reader.exists(o2))
317750
317763
  );
317751
317764
  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
- }
317755
317765
  if (body) {
317756
317766
  const entry = {
317757
317767
  name: uri,
@@ -317762,6 +317772,8 @@ ${inject.head ?? ""}`;
317762
317772
  }
317763
317773
  }
317764
317774
  });
317775
+ console.debug("Index pipeline functions after", lunrIndex.pipeline._stack.map((f3) => f3.label));
317776
+ console.debug("Index search pipeline functions after", lunrIndex.searchPipeline?._stack?.map((f3) => f3.label));
317765
317777
  indexProgress(null);
317766
317778
  yield { "/search-index.json": encoder.encode(JSON.stringify(lunrIndex, null, 4)) };
317767
317779
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@riboseinc/anafero-cli",
3
3
  "type": "module",
4
- "version": "0.0.54",
4
+ "version": "0.0.56",
5
5
  "packageManager": "yarn@4.5.0",
6
6
  "bin": {
7
7
  "build-site": "build-site.mjs"