@cloudhal/astro-renderer 0.9.0 → 0.10.0
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/README.md +1 -1
- package/dist/src/astro-env.d.ts +2 -1
- package/dist/src/cloudflare-entry.js +8 -2
- package/dist/src/comments-middleware.js +5 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/integration.d.ts +14 -0
- package/dist/src/integration.js +24 -1
- package/dist/src/runtime-workerd.d.ts +3 -3
- package/dist/src/runtime-workerd.js +3 -3
- package/dist/src/runtime.d.ts +4 -2
- package/dist/src/runtime.js +14 -5
- package/dist/src/site-dispatch.d.ts +10 -0
- package/dist/src/site-dispatch.js +13 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ Guide: [`docs/guides/structured-data.md`](../../docs/guides/structured-data.md).
|
|
|
70
70
|
Derived gates: `unlist` keeps an entry's page (200), comments and menu links but leaves `entries()`, `allEntries()`, `entriesByFilter`/`entriesByTerm` (archives, related), feeds, the sitemap and search; `hide` is a 404 like an expired `availability`. Both sources apply them, the gate index caps the edge cache at every derived instant and at every value instant of date/datetime list fields (for `now` conditions), and previews ignore them with an "Ended on …" notice. The site Worker's `GET /__cloudhal/features` answers `{ "gates": 2 }`; writers refuse `expiry` until it does.
|
|
71
71
|
|
|
72
72
|
### References and repeaters (RFC-0045, rollout step 3)
|
|
73
|
-
Additive
|
|
73
|
+
Additive. Sites define the two types since rollout step 7, wherever the site Worker reports `fields: 2` (Node always). `entryFields` (and `source.entryFields`) resolve a `reference` to cards of the targets the page's *view* shows (gates applied at its instant; draft, archived, embargoed and hidden targets resolve to nothing and leave no id, title or empty item) and a `repeater` to its items. `EntryFields.astro` draws both, so old theme copies show them with no change of their own (`theme-v0.8.0` in the compat test).
|
|
74
74
|
|
|
75
75
|
| Export | Signature |
|
|
76
76
|
|---|---|
|
package/dist/src/astro-env.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ declare module "virtual:cloudhal/analytics-client" {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
declare module "virtual:cloudhal/config" {
|
|
13
|
-
|
|
13
|
+
/** No `dataDir` on the `cloudflare` target (`virtualConfig`). */
|
|
14
|
+
const config: import("./integration.js").VirtualCloudhalConfig;
|
|
14
15
|
export default config;
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -76,7 +76,13 @@ import { EMBED_HEADER, withEmbedFrames } from "./embed-client.js";
|
|
|
76
76
|
import { hostRedirect, } from "./host-redirect.js";
|
|
77
77
|
import { PREVIEW_PARAM } from "./resolver.js";
|
|
78
78
|
import { SearchLimiter, searchCost } from "./search-limit.js";
|
|
79
|
-
import {
|
|
79
|
+
import {
|
|
80
|
+
|
|
81
|
+
SiteDispatch,
|
|
82
|
+
singleSiteId,
|
|
83
|
+
unknownHost,
|
|
84
|
+
withNoindex,
|
|
85
|
+
} from "./site-dispatch.js";
|
|
80
86
|
import {
|
|
81
87
|
errorPage,
|
|
82
88
|
HEALTH_PATH,
|
|
@@ -174,7 +180,7 @@ const statusHook = themeStatusHook(loadTheme, (m, e) => console.error(m, e));
|
|
|
174
180
|
/** One per isolate: which site a request is for (RFC-0034 §4). */
|
|
175
181
|
function siteDispatch(env , siteIdFromBuild ) {
|
|
176
182
|
dispatch ??= new SiteDispatch({
|
|
177
|
-
siteId:
|
|
183
|
+
siteId: singleSiteId(env, siteIdFromBuild),
|
|
178
184
|
siteIds: env.CLOUDHAL_SITE_IDS,
|
|
179
185
|
sql: () => new D1Driver(env.DB ),
|
|
180
186
|
});
|
|
@@ -19,7 +19,11 @@ const handler = createNodeComments({
|
|
|
19
19
|
// the same local store, site row and published snapshots analytics read
|
|
20
20
|
backend: analyticsBackend(config.siteId, config) ,
|
|
21
21
|
client: config.comments?.available === false ? null : client,
|
|
22
|
-
|
|
22
|
+
// `cloudhal dev` only (a Node target), where the integration always passes dataDir.
|
|
23
|
+
secret: () => {
|
|
24
|
+
if (!config.dataDir) throw new Error("the comments middleware needs the renderer's dataDir");
|
|
25
|
+
return localCommentsKey(config.dataDir);
|
|
26
|
+
},
|
|
23
27
|
onError: (m, e) => console.warn(`cloudhal: ${m}`, e),
|
|
24
28
|
});
|
|
25
29
|
|
package/dist/src/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export * from "./collection-feeds.js";
|
|
|
12
12
|
export * from "./entry-query.js";
|
|
13
13
|
export * from "./fields.js";
|
|
14
14
|
export * from "./gates.js";
|
|
15
|
-
export { type CloudhalRendererConfig, cloudhal } from "./integration.js";
|
|
15
|
+
export { type CloudhalRendererConfig, cloudhal, type VirtualCloudhalConfig, } from "./integration.js";
|
|
16
16
|
export { renderBody, renderEntryArticle, renderMarkdown, safeHref } from "./markdown.js";
|
|
17
17
|
export * from "./navigation.js";
|
|
18
18
|
export * from "./preview.js";
|
package/dist/src/index.js
CHANGED
|
@@ -12,7 +12,11 @@ export * from "./collection-feeds.js";
|
|
|
12
12
|
export * from "./entry-query.js";
|
|
13
13
|
export * from "./fields.js";
|
|
14
14
|
export * from "./gates.js";
|
|
15
|
-
export {
|
|
15
|
+
export {
|
|
16
|
+
|
|
17
|
+
cloudhal,
|
|
18
|
+
|
|
19
|
+
} from "./integration.js";
|
|
16
20
|
export { renderBody, renderEntryArticle, renderMarkdown, safeHref } from "./markdown.js";
|
|
17
21
|
export * from "./navigation.js";
|
|
18
22
|
export * from "./preview.js";
|
|
@@ -52,4 +52,18 @@ export interface CloudhalRendererConfig {
|
|
|
52
52
|
*/
|
|
53
53
|
readonly commentsScript?: string;
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* The type of `virtual:cloudhal/config`: the integration's config, with `dataDir` absent on the
|
|
57
|
+
* `cloudflare` target (`virtualConfig`). Theme code that reads `dataDir` must handle that.
|
|
58
|
+
*/
|
|
59
|
+
export type VirtualCloudhalConfig = Omit<CloudhalRendererConfig, "dataDir"> & {
|
|
60
|
+
readonly dataDir?: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* What pages see as `virtual:cloudhal/config`. On the `cloudflare` target there is no `dataDir`:
|
|
64
|
+
* the Site Worker reads D1 and R2 through its bindings (`runtime-workerd.ts` ignores the field),
|
|
65
|
+
* and the resolved value is the build machine's absolute path, which a release bundle built in CI
|
|
66
|
+
* would otherwise carry to every deployment (RFC-0046 §11b, #239).
|
|
67
|
+
*/
|
|
68
|
+
export declare function virtualConfig(resolved: CloudhalRendererConfig, cloudflare: boolean): VirtualCloudhalConfig;
|
|
55
69
|
export declare function cloudhal(config: CloudhalRendererConfig): AstroIntegration;
|
package/dist/src/integration.js
CHANGED
|
@@ -72,6 +72,29 @@ const THEME_HOOKS_ID = "virtual:cloudhal/theme-hooks";
|
|
|
72
72
|
const RESOLVED_THEME_HOOKS_ID = `\0${THEME_HOOKS_ID}`;
|
|
73
73
|
const THEME_MODULE = "src/theme.ts";
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* The type of `virtual:cloudhal/config`: the integration's config, with `dataDir` absent on the
|
|
77
|
+
* `cloudflare` target (`virtualConfig`). Theme code that reads `dataDir` must handle that.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* What pages see as `virtual:cloudhal/config`. On the `cloudflare` target there is no `dataDir`:
|
|
85
|
+
* the Site Worker reads D1 and R2 through its bindings (`runtime-workerd.ts` ignores the field),
|
|
86
|
+
* and the resolved value is the build machine's absolute path, which a release bundle built in CI
|
|
87
|
+
* would otherwise carry to every deployment (RFC-0046 §11b, #239).
|
|
88
|
+
*/
|
|
89
|
+
export function virtualConfig(
|
|
90
|
+
resolved ,
|
|
91
|
+
cloudflare ,
|
|
92
|
+
) {
|
|
93
|
+
if (!cloudflare) return resolved;
|
|
94
|
+
const { dataDir: _buildMachinePath, ...rest } = resolved;
|
|
95
|
+
return rest;
|
|
96
|
+
}
|
|
97
|
+
|
|
75
98
|
/** The virtual modules: the project config, and in dev the built analytics and comments clients. */
|
|
76
99
|
function configPlugin(modules ) {
|
|
77
100
|
const ids = {
|
|
@@ -182,7 +205,7 @@ export function cloudhal(config ) {
|
|
|
182
205
|
vite: {
|
|
183
206
|
plugins: [
|
|
184
207
|
configPlugin({
|
|
185
|
-
config: resolved,
|
|
208
|
+
config: virtualConfig(resolved, cloudflare),
|
|
186
209
|
client: cloudflare ? null : (client ?? null),
|
|
187
210
|
comments: cloudflare ? null : (comments ?? null),
|
|
188
211
|
}),
|
|
@@ -12,7 +12,7 @@ import { SqlCommentStore } from "@cloudhal/comments/sql";
|
|
|
12
12
|
import type { Site } from "@cloudhal/core-contracts";
|
|
13
13
|
import { type AiSearchEnv, SiteGraphStore } from "@cloudhal/core-ts";
|
|
14
14
|
import type { SqlDriver } from "@cloudhal/storage";
|
|
15
|
-
import type { CloudhalRendererConfig } from "./integration.js";
|
|
15
|
+
import type { CloudhalRendererConfig, VirtualCloudhalConfig } from "./integration.js";
|
|
16
16
|
import type { PeerEdition } from "./locales.js";
|
|
17
17
|
import type { GraphSource } from "./source.js";
|
|
18
18
|
/** RFC-0029 §3: `AI_SEARCH`, `SEARCH_BUCKET` and `CLOUDHAL_SEARCH_*` turn on semantic search. */
|
|
@@ -91,7 +91,7 @@ export { CACHE_TAG_PREFIX } from "./cache-tags.js";
|
|
|
91
91
|
* counts: their published snapshot is read, never their drafts. A site without a hostname is
|
|
92
92
|
* left out (there is no address to point to).
|
|
93
93
|
*/
|
|
94
|
-
export declare function peerEditions(config:
|
|
94
|
+
export declare function peerEditions(config: VirtualCloudhalConfig, node: {
|
|
95
95
|
id: string;
|
|
96
96
|
translation?: {
|
|
97
97
|
group: string;
|
|
@@ -110,7 +110,7 @@ export declare function commentsBackend(config: Partial<CloudhalRendererConfig>)
|
|
|
110
110
|
* Resolves the source for this request and sets caching/preview headers on the response.
|
|
111
111
|
* Returns `undefined` when the site has never been published (the page should answer 503).
|
|
112
112
|
*/
|
|
113
|
-
export declare function getSource(config:
|
|
113
|
+
export declare function getSource(config: VirtualCloudhalConfig, astro?: AstroLike): Promise<GraphSource | undefined>;
|
|
114
114
|
/**
|
|
115
115
|
* The media route (RFC-0004 §7.1), answered by the Site Worker entry before Astro: the asset comes
|
|
116
116
|
* from the published snapshot, or from the preview target behind a valid token (invariant 15).
|
|
@@ -20,7 +20,7 @@ import { D1Driver } from "@cloudhal/storage/d1";
|
|
|
20
20
|
import { R2BlobStore } from "@cloudhal/storage/r2";
|
|
21
21
|
import { siteCacheTag } from "./cache-tags.js";
|
|
22
22
|
import { usableCommentsKey } from "./comments.js";
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
|
|
25
25
|
import { matchMediaRoute, serveMediaRequest } from "./media-route.js";
|
|
26
26
|
import { PREVIEW_PARAM, SiteResolver } from "./resolver.js";
|
|
@@ -263,7 +263,7 @@ export { CACHE_TAG_PREFIX } from "./cache-tags.js";
|
|
|
263
263
|
* left out (there is no address to point to).
|
|
264
264
|
*/
|
|
265
265
|
export async function peerEditions(
|
|
266
|
-
config
|
|
266
|
+
config ,
|
|
267
267
|
node ,
|
|
268
268
|
) {
|
|
269
269
|
const siteId = siteOf(config.siteId);
|
|
@@ -314,7 +314,7 @@ export async function commentsBackend(
|
|
|
314
314
|
* Returns `undefined` when the site has never been published (the page should answer 503).
|
|
315
315
|
*/
|
|
316
316
|
export async function getSource(
|
|
317
|
-
config
|
|
317
|
+
config ,
|
|
318
318
|
astro ,
|
|
319
319
|
) {
|
|
320
320
|
if (!astro) throw new Error("on Cloudflare, pass the Astro global: getSource(config, Astro)");
|
package/dist/src/runtime.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { SqlCommentStore } from "@cloudhal/comments/sql";
|
|
|
2
2
|
import type { Site } from "@cloudhal/core-contracts";
|
|
3
3
|
import type { SiteGraphStore } from "@cloudhal/core-ts";
|
|
4
4
|
import type { SqlDriver } from "@cloudhal/storage";
|
|
5
|
-
import type { CloudhalRendererConfig } from "./integration.js";
|
|
5
|
+
import type { CloudhalRendererConfig, VirtualCloudhalConfig } from "./integration.js";
|
|
6
6
|
import type { PeerEdition } from "./locales.js";
|
|
7
7
|
import { type GraphSource } from "./source.js";
|
|
8
8
|
/**
|
|
@@ -10,7 +10,9 @@ import { type GraphSource } from "./source.js";
|
|
|
10
10
|
* selector. `CLOUDHAL_SOURCE=live | snapshot:<id>` overrides the integration config (used by
|
|
11
11
|
* `cloudhal build`); a later build in the same process with another selector gets a new source.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
/** On Node targets the integration always passes `dataDir`; only the `cloudflare` target omits it. */
|
|
14
|
+
export declare function nodeDataDir(config: Pick<VirtualCloudhalConfig, "dataDir">): string;
|
|
15
|
+
export declare function getSource(config: VirtualCloudhalConfig,
|
|
14
16
|
/** Ignored on Node (one source per process); the `workerd` build resolves per request. */
|
|
15
17
|
_astro?: {
|
|
16
18
|
request: Request;
|
package/dist/src/runtime.js
CHANGED
|
@@ -3,7 +3,7 @@ import { SqlCommentStore } from "@cloudhal/comments/sql";
|
|
|
3
3
|
|
|
4
4
|
import { openLocalStore } from "@cloudhal/core-ts/local";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
|
|
8
8
|
import { matchMediaRoute, serveMediaRequest } from "./media-route.js";
|
|
9
9
|
import { SiteResolver } from "./resolver.js";
|
|
@@ -16,13 +16,22 @@ let cached ;
|
|
|
16
16
|
* selector. `CLOUDHAL_SOURCE=live | snapshot:<id>` overrides the integration config (used by
|
|
17
17
|
* `cloudhal build`); a later build in the same process with another selector gets a new source.
|
|
18
18
|
*/
|
|
19
|
+
/** On Node targets the integration always passes `dataDir`; only the `cloudflare` target omits it. */
|
|
20
|
+
export function nodeDataDir(config ) {
|
|
21
|
+
if (!config.dataDir)
|
|
22
|
+
throw new Error(
|
|
23
|
+
"the renderer config has no dataDir: Node targets read the local store from it",
|
|
24
|
+
);
|
|
25
|
+
return config.dataDir;
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
export function getSource(
|
|
20
|
-
config
|
|
29
|
+
config ,
|
|
21
30
|
/** Ignored on Node (one source per process); the `workerd` build resolves per request. */
|
|
22
31
|
_astro ,
|
|
23
32
|
) {
|
|
24
33
|
const selector = process.env.CLOUDHAL_SOURCE ?? config.source ?? "live";
|
|
25
|
-
const key = `${config
|
|
34
|
+
const key = `${nodeDataDir(config)}\n${config.siteId}\n${selector}`;
|
|
26
35
|
if (cached?.key !== key) cached = { key, source: open(config, selector) };
|
|
27
36
|
return cached.source;
|
|
28
37
|
}
|
|
@@ -35,9 +44,9 @@ function localStore(dataDir ) {
|
|
|
35
44
|
return local.store;
|
|
36
45
|
}
|
|
37
46
|
|
|
38
|
-
function open(config
|
|
47
|
+
function open(config , selector ) {
|
|
39
48
|
return (async () => {
|
|
40
|
-
const { store } = await localStore(config
|
|
49
|
+
const { store } = await localStore(nodeDataDir(config));
|
|
41
50
|
if (selector === "live") return new LiveSource(store, config.siteId);
|
|
42
51
|
if (selector.startsWith("snapshot:"))
|
|
43
52
|
return SnapshotSource.open(store, selector.slice("snapshot:".length));
|
|
@@ -7,6 +7,16 @@
|
|
|
7
7
|
* something to check. Any other host is unknown: a short-cached 404, never another site.
|
|
8
8
|
*/
|
|
9
9
|
import type { SqlDriver } from "@cloudhal/storage";
|
|
10
|
+
/**
|
|
11
|
+
* The single site a Site Worker serves: its `CLOUDHAL_SITE_ID` var first, so a deployment can
|
|
12
|
+
* serve a site other than the one its bundle was built for (RFC-0046 §11b: `deploy --release`
|
|
13
|
+
* installs a bundle built with another site id); else, unless `CLOUDHAL_SITE_IDS` makes it
|
|
14
|
+
* multi-site, the build's.
|
|
15
|
+
*/
|
|
16
|
+
export declare function singleSiteId(env: {
|
|
17
|
+
readonly CLOUDHAL_SITE_ID?: string;
|
|
18
|
+
readonly CLOUDHAL_SITE_IDS?: string;
|
|
19
|
+
}, siteIdFromBuild: string | undefined): string | undefined;
|
|
10
20
|
export type SiteChoice = {
|
|
11
21
|
readonly kind: "site";
|
|
12
22
|
readonly siteId: string | undefined;
|
|
@@ -9,6 +9,19 @@
|
|
|
9
9
|
|
|
10
10
|
import { parseSiteIds, SiteHostMap } from "./site-hosts.js";
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The single site a Site Worker serves: its `CLOUDHAL_SITE_ID` var first, so a deployment can
|
|
14
|
+
* serve a site other than the one its bundle was built for (RFC-0046 §11b: `deploy --release`
|
|
15
|
+
* installs a bundle built with another site id); else, unless `CLOUDHAL_SITE_IDS` makes it
|
|
16
|
+
* multi-site, the build's.
|
|
17
|
+
*/
|
|
18
|
+
export function singleSiteId(
|
|
19
|
+
env ,
|
|
20
|
+
siteIdFromBuild ,
|
|
21
|
+
) {
|
|
22
|
+
return env.CLOUDHAL_SITE_ID ?? (env.CLOUDHAL_SITE_IDS ? undefined : siteIdFromBuild);
|
|
23
|
+
}
|
|
24
|
+
|
|
12
25
|
|
|
13
26
|
|
|
14
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudhal/astro-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Render a Cloudhal Site Graph with Astro: data sources (live/snapshot), section components and the cloudhal() integration",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://cloudhal.dev",
|
|
@@ -223,14 +223,14 @@
|
|
|
223
223
|
"README.md"
|
|
224
224
|
],
|
|
225
225
|
"dependencies": {
|
|
226
|
-
"@cloudhal/core-contracts": "0.
|
|
227
|
-
"@cloudhal/core-ts": "0.
|
|
228
|
-
"@cloudhal/storage": "0.
|
|
226
|
+
"@cloudhal/core-contracts": "0.10.0",
|
|
227
|
+
"@cloudhal/core-ts": "0.10.0",
|
|
228
|
+
"@cloudhal/storage": "0.10.0",
|
|
229
229
|
"marked": "^18.1.1",
|
|
230
230
|
"parse5": "8.1.0",
|
|
231
|
-
"@cloudhal/analytics": "0.
|
|
231
|
+
"@cloudhal/analytics": "0.10.0",
|
|
232
232
|
"vite": "^8.3.5",
|
|
233
|
-
"@cloudhal/comments": "0.
|
|
233
|
+
"@cloudhal/comments": "0.10.0"
|
|
234
234
|
},
|
|
235
235
|
"peerDependencies": {
|
|
236
236
|
"astro": "^7.4.0",
|