@uniweb/core 1.4.6 → 1.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/src/uniweb.js +1 -1
- package/src/website.js +48 -1
package/package.json
CHANGED
package/src/uniweb.js
CHANGED
|
@@ -28,7 +28,7 @@ export default class Uniweb {
|
|
|
28
28
|
* sites never pass this option.
|
|
29
29
|
*/
|
|
30
30
|
constructor({ content = {}, foundation = null, extensions = [], defaultFetcher = null, transport = null, dev = false } = {}) {
|
|
31
|
-
this.activeWebsite = new Website({ content, foundation, extensions, defaultFetcher, transport, dev })
|
|
31
|
+
this.activeWebsite = new Website({ content, foundation, extensions, defaultFetcher, transport, dev, uniweb: this })
|
|
32
32
|
|
|
33
33
|
this.foundation = foundation
|
|
34
34
|
this.foundationConfig = {}
|
package/src/website.js
CHANGED
|
@@ -54,7 +54,7 @@ const SERVICE_RESOLVERS = {
|
|
|
54
54
|
* swaps reassemble the dispatcher but preserve the DataStore and state so the
|
|
55
55
|
* editor's live-edit path doesn't wipe either between keystrokes.
|
|
56
56
|
*
|
|
57
|
-
* new Website({ content, foundation?, extensions?, defaultFetcher?, dev? })
|
|
57
|
+
* new Website({ content, foundation?, extensions?, defaultFetcher?, dev?, uniweb? })
|
|
58
58
|
*/
|
|
59
59
|
export default class Website {
|
|
60
60
|
constructor({
|
|
@@ -64,6 +64,7 @@ export default class Website {
|
|
|
64
64
|
defaultFetcher = null,
|
|
65
65
|
transport = null,
|
|
66
66
|
dev = false,
|
|
67
|
+
uniweb = null,
|
|
67
68
|
} = {}) {
|
|
68
69
|
|
|
69
70
|
// ─── Foundation / dispatcher state (not re-derived on rebuild) ───
|
|
@@ -74,6 +75,8 @@ export default class Website {
|
|
|
74
75
|
// rebuild() reassembles the dispatcher with the same override in place.
|
|
75
76
|
this._transport = transport
|
|
76
77
|
this._dev = dev
|
|
78
|
+
// The Uniweb that made this Website, if one did — what `makeCurrent` points the global at.
|
|
79
|
+
this._uniweb = uniweb
|
|
77
80
|
|
|
78
81
|
this.dataStore = new DataStore()
|
|
79
82
|
this.fetcher = new FetcherDispatcher({
|
|
@@ -248,6 +251,37 @@ export default class Website {
|
|
|
248
251
|
})
|
|
249
252
|
}
|
|
250
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Forget the answers this Website holds, and the parametric pages made from them.
|
|
256
|
+
*
|
|
257
|
+
* ⭐ For a caller that renders many pages or requests on one Website, so that each render
|
|
258
|
+
* starts from the answers its own page carries (`render(target, { fetchedData })` in
|
|
259
|
+
* `@uniweb/runtime/ssr`). ⛔ Emptying the store alone is not enough: a parametric page takes
|
|
260
|
+
* its title, description and not-found state from the store when it is first made, and is
|
|
261
|
+
* then kept by route (`_pageFor`), so it would go on showing what an earlier request found.
|
|
262
|
+
* The store is emptied in place, so every dispatcher built on it sees the same.
|
|
263
|
+
*/
|
|
264
|
+
forgetData() {
|
|
265
|
+
this.dataStore.clear()
|
|
266
|
+
this._dynamicPageCache.clear()
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Point `globalThis.uniweb` at the Uniweb that made this Website.
|
|
271
|
+
*
|
|
272
|
+
* ⭐ Code that reaches the site through the global reads THAT, not the Website it was handed:
|
|
273
|
+
* a block resolving its component (`Block#initComponent`, kept on the block), the props
|
|
274
|
+
* pipeline, this class's own foundation config, and kit in every foundation
|
|
275
|
+
* (`getUniweb().activeWebsite`). Every `createUniweb` points the global at the newest instance,
|
|
276
|
+
* so a caller holding several in one process (a host serving many sites, publishes or locales)
|
|
277
|
+
* must point it back before it uses another. The render door and the data step do
|
|
278
|
+
* (`@uniweb/runtime/ssr`). A Website built without a Uniweb has none to point at, and leaves
|
|
279
|
+
* the global as it is.
|
|
280
|
+
*/
|
|
281
|
+
makeCurrent() {
|
|
282
|
+
if (this._uniweb) globalThis.uniweb = this._uniweb
|
|
283
|
+
}
|
|
284
|
+
|
|
251
285
|
/**
|
|
252
286
|
* Rebuild in place. Content-only rebuilds preserve the dispatcher and all
|
|
253
287
|
* state (site and per-page). Passing `foundation` or `extensions` reassembles
|
|
@@ -1052,6 +1086,19 @@ export default class Website {
|
|
|
1052
1086
|
return alternates
|
|
1053
1087
|
}
|
|
1054
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* The pages of the content this Website was built from, as the content states them, in its
|
|
1091
|
+
* order — for a rule written over site content to read the pages the build read. The runtime
|
|
1092
|
+
* links each page's markdown this way (`pageMarkdownUrls` in `@uniweb/projections`), whose rules
|
|
1093
|
+
* read fields a Page does not keep, such as a container's `hasContent: false`. The not-found
|
|
1094
|
+
* page is not among them.
|
|
1095
|
+
*
|
|
1096
|
+
* @returns {Object[]}
|
|
1097
|
+
*/
|
|
1098
|
+
getContentPages() {
|
|
1099
|
+
return [...this._pageOfData.keys()]
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1055
1102
|
/**
|
|
1056
1103
|
* Show the page in another locale.
|
|
1057
1104
|
*
|