@phis/ui 0.4.7 → 0.4.8
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/package.json +1 -1
- package/server-helpers/search-index.js +25 -14
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import { resolvePhiCmsAreaRuntimeModuleScope } from "../components/cms/phi-cms-r
|
|
|
12
12
|
import { canPhiViewerAccess } from "../types/access";
|
|
13
13
|
import { resolvePhiCmsLookup } from "./cms-lookup";
|
|
14
14
|
import { resolveActivePresetModuleKeys } from "./cms-request";
|
|
15
|
+
import { runWithPhiRequestRuntime } from "./request-runtime";
|
|
15
16
|
import { loadPhiSiteRequestContext } from "./runtime";
|
|
16
17
|
import { joinPhiSearchText } from "./search-text";
|
|
17
18
|
/**
|
|
@@ -41,7 +42,7 @@ const PHI_SEARCH_INDEX_DEBOUNCE_MS = 2_000;
|
|
|
41
42
|
* What the extraction is, named in the fingerprint: a change in how documents are built reindexes every
|
|
42
43
|
* Site on its next start, which the published revisions alone would not do.
|
|
43
44
|
*/
|
|
44
|
-
const PHI_SEARCH_INDEX_FORMAT =
|
|
45
|
+
const PHI_SEARCH_INDEX_FORMAT = 2;
|
|
45
46
|
const REGISTRY_KEY = Symbol.for("phis-ui.search-index");
|
|
46
47
|
function readRegistry() {
|
|
47
48
|
const holder = globalThis;
|
|
@@ -276,20 +277,30 @@ async function readDocument({ bridge, area, locale, context, path, loadPlugin, }
|
|
|
276
277
|
return null;
|
|
277
278
|
if (!canPhiViewerAccess(resolved.runtime.viewer, page.accessPolicy))
|
|
278
279
|
return null;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
280
|
+
/*
|
|
281
|
+
* The Widgets answer inside a request scope of their own. `searchText` is given the runtime, but the
|
|
282
|
+
* shared server helpers a Widget reaches for -- the translation of its texts first of all -- read the
|
|
283
|
+
* request runtime from the scope, and the indexer runs where no request is: at start-up, or on a
|
|
284
|
+
* timer after a publish. Without this scope every Widget that translates fails and a Page is indexed
|
|
285
|
+
* by title and description alone, which is what the first production index was.
|
|
286
|
+
*/
|
|
287
|
+
const lines = await runWithPhiRequestRuntime(resolved.runtime, async () => {
|
|
288
|
+
const collected = [];
|
|
289
|
+
for (const widget of resolved.page.contentWidgets) {
|
|
290
|
+
const plugin = await loadPlugin(widget.widgetType);
|
|
291
|
+
if (!plugin?.searchText)
|
|
292
|
+
continue;
|
|
293
|
+
try {
|
|
294
|
+
const config = plugin.parseConfig(widget.config);
|
|
295
|
+
collected.push(...await plugin.searchText({ widget, config, runtime: resolved.runtime }));
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
// One Widget that cannot say its words costs the Page those words, not the Page.
|
|
299
|
+
console.error(`[phis-ui] The search index could not read the Widget "${widget.widgetType}" on ${area}:${path}.`, error);
|
|
300
|
+
}
|
|
291
301
|
}
|
|
292
|
-
|
|
302
|
+
return collected;
|
|
303
|
+
});
|
|
293
304
|
return {
|
|
294
305
|
path: page.path,
|
|
295
306
|
title: resolved.runtime.page?.title ?? "",
|