@cloudhal/astro-renderer 0.5.0 → 0.6.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 +24 -0
- package/dist/src/cloudflare-entry.d.ts +3 -2
- package/dist/src/cloudflare-entry.js +3 -2
- package/dist/src/collection-feed-middleware.d.ts +5 -0
- package/dist/src/collection-feed-middleware.js +22 -0
- package/dist/src/collection-feed-route.d.ts +21 -0
- package/dist/src/collection-feed-route.js +92 -0
- package/dist/src/collection-feeds.d.ts +40 -0
- package/dist/src/collection-feeds.js +87 -0
- package/dist/src/components/ContentList.astro +26 -9
- package/dist/src/entry-query.d.ts +85 -0
- package/dist/src/entry-query.js +227 -0
- package/dist/src/entry-views.d.ts +36 -0
- package/dist/src/entry-views.js +73 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +7 -0
- package/dist/src/integration.js +30 -19
- package/dist/src/live-source.d.ts +53 -0
- package/dist/src/live-source.js +318 -0
- package/dist/src/locales.js +4 -3
- package/dist/src/preview.d.ts +16 -1
- package/dist/src/preview.js +89 -14
- package/dist/src/routing.d.ts +1 -1
- package/dist/src/routing.js +13 -3
- package/dist/src/seo.d.ts +4 -1
- package/dist/src/seo.js +9 -0
- package/dist/src/source.d.ts +30 -46
- package/dist/src/source.js +89 -239
- package/dist/src/structured-data.d.ts +35 -0
- package/dist/src/structured-data.js +88 -0
- package/package.json +27 -6
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-0042 §2 in `<head>`: an entry whose collection has a JSON-LD preset (`Event`, `JobPosting`,
|
|
3
|
+
* `Product`, `Recipe`) describes itself with it instead of the generic `BlogPosting` that
|
|
4
|
+
* `entryHead` emits. `entryHead` itself never changes, so a theme copy from before RFC-0042 keeps
|
|
5
|
+
* today's output; a theme opts in with one `withStructuredData` call after `entryHead`.
|
|
6
|
+
*
|
|
7
|
+
* The document is built by core-ts's pure `structuredDataFor` from typed values (resolved, so a
|
|
8
|
+
* translation reads its original's non-localized ones), capped at 32 KB, and rendered through
|
|
9
|
+
* `jsonLdText` by `SeoHead.astro` like every other JSON-LD block. An entry missing a required value
|
|
10
|
+
* keeps its `BlogPosting`; the `BreadcrumbList` always stays.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { entryPath } from "@cloudhal/core-ts";
|
|
14
|
+
import { resolveFields } from "@cloudhal/core-ts/fields";
|
|
15
|
+
import {
|
|
16
|
+
absoluteHttpUrl,
|
|
17
|
+
|
|
18
|
+
structuredDataFor,
|
|
19
|
+
} from "@cloudhal/core-ts/structured-data";
|
|
20
|
+
import { loadAssetIndex, socialImageUrl } from "./media.js";
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/** The asset index to resolve image fields, the cover image and the site logo with. */
|
|
35
|
+
async function assetsFor(
|
|
36
|
+
source ,
|
|
37
|
+
media ,
|
|
38
|
+
) {
|
|
39
|
+
return media?.assets ?? (await loadAssetIndex(source));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The preset document of an entry and why it has none (`issues`): no preset, a required value
|
|
44
|
+
* missing, or over the cap. What `withStructuredData` emits, and what previews and checks show.
|
|
45
|
+
*/
|
|
46
|
+
export async function entryStructuredData(
|
|
47
|
+
source ,
|
|
48
|
+
entry ,
|
|
49
|
+
options ,
|
|
50
|
+
) {
|
|
51
|
+
const site = await source.site();
|
|
52
|
+
if (!site.collections?.[entry.collection]?.structuredData) return { issues: [] };
|
|
53
|
+
const group = entry.translation?.group;
|
|
54
|
+
const original =
|
|
55
|
+
group && group !== entry.id && source.entryById ? await source.entryById(group) : undefined;
|
|
56
|
+
const resolved = resolveFields(site, entry, original);
|
|
57
|
+
const assets = await assetsFor(source, options.media);
|
|
58
|
+
const { origin } = options;
|
|
59
|
+
return structuredDataFor(site, resolved, entry, {
|
|
60
|
+
origin,
|
|
61
|
+
entryUrl: `${origin}${entryPath(site, entry)}`,
|
|
62
|
+
imageUrl: (image) => {
|
|
63
|
+
const asset = image.assetId ? assets.get(image.assetId) : undefined;
|
|
64
|
+
if (asset) return asset.kind === "image" ? socialImageUrl(origin, asset) : undefined;
|
|
65
|
+
return image.src ? absoluteHttpUrl(image.src, origin) : undefined;
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const isBlogPosting = (doc ) => (doc )["@type"] === "BlogPosting";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* `head` with the entry's preset document in place of the `BlogPosting` (RFC-0042 §2), when its
|
|
74
|
+
* collection has a preset and the entry has every required value; otherwise `head` unchanged.
|
|
75
|
+
* The `BreadcrumbList` stays; the `BlogPosting`'s `commentCount` does not move to the preset.
|
|
76
|
+
*/
|
|
77
|
+
export async function withStructuredData(
|
|
78
|
+
head ,
|
|
79
|
+
source ,
|
|
80
|
+
entry ,
|
|
81
|
+
options ,
|
|
82
|
+
) {
|
|
83
|
+
const at = head.jsonLd.findIndex(isBlogPosting);
|
|
84
|
+
if (at < 0) return head;
|
|
85
|
+
const { doc } = await entryStructuredData(source, entry, options);
|
|
86
|
+
if (!doc) return head;
|
|
87
|
+
return { ...head, jsonLd: head.jsonLd.map((d, i) => (i === at ? doc : d)) };
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudhal/astro-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./dist/src/source.d.ts",
|
|
23
23
|
"default": "./dist/src/source.js"
|
|
24
24
|
},
|
|
25
|
+
"./queries": {
|
|
26
|
+
"types": "./dist/src/entry-query.d.ts",
|
|
27
|
+
"default": "./dist/src/entry-query.js"
|
|
28
|
+
},
|
|
25
29
|
"./fields": {
|
|
26
30
|
"types": "./dist/src/fields.d.ts",
|
|
27
31
|
"default": "./dist/src/fields.js"
|
|
@@ -42,6 +46,18 @@
|
|
|
42
46
|
"types": "./dist/src/feeds.d.ts",
|
|
43
47
|
"default": "./dist/src/feeds.js"
|
|
44
48
|
},
|
|
49
|
+
"./collection-feeds": {
|
|
50
|
+
"types": "./dist/src/collection-feeds.d.ts",
|
|
51
|
+
"default": "./dist/src/collection-feeds.js"
|
|
52
|
+
},
|
|
53
|
+
"./collection-feed-route": {
|
|
54
|
+
"types": "./dist/src/collection-feed-route.d.ts",
|
|
55
|
+
"default": "./dist/src/collection-feed-route.js"
|
|
56
|
+
},
|
|
57
|
+
"./collection-feed-middleware": {
|
|
58
|
+
"types": "./dist/src/collection-feed-middleware.d.ts",
|
|
59
|
+
"default": "./dist/src/collection-feed-middleware.js"
|
|
60
|
+
},
|
|
45
61
|
"./taxonomy": {
|
|
46
62
|
"types": "./dist/src/taxonomy.d.ts",
|
|
47
63
|
"default": "./dist/src/taxonomy.js"
|
|
@@ -85,6 +101,10 @@
|
|
|
85
101
|
"types": "./dist/src/preview.d.ts",
|
|
86
102
|
"default": "./dist/src/preview.js"
|
|
87
103
|
},
|
|
104
|
+
"./structured-data": {
|
|
105
|
+
"types": "./dist/src/structured-data.d.ts",
|
|
106
|
+
"default": "./dist/src/structured-data.js"
|
|
107
|
+
},
|
|
88
108
|
"./resolver": {
|
|
89
109
|
"types": "./dist/src/resolver.d.ts",
|
|
90
110
|
"default": "./dist/src/resolver.js"
|
|
@@ -183,14 +203,14 @@
|
|
|
183
203
|
"README.md"
|
|
184
204
|
],
|
|
185
205
|
"dependencies": {
|
|
186
|
-
"@cloudhal/core-contracts": "0.
|
|
187
|
-
"@cloudhal/core-ts": "0.
|
|
188
|
-
"@cloudhal/storage": "0.
|
|
206
|
+
"@cloudhal/core-contracts": "0.6.0",
|
|
207
|
+
"@cloudhal/core-ts": "0.6.0",
|
|
208
|
+
"@cloudhal/storage": "0.6.0",
|
|
189
209
|
"marked": "^18.1.0",
|
|
190
210
|
"parse5": "8.0.1",
|
|
191
|
-
"@cloudhal/analytics": "0.
|
|
211
|
+
"@cloudhal/analytics": "0.6.0",
|
|
192
212
|
"vite": "^8.3.3",
|
|
193
|
-
"@cloudhal/comments": "0.
|
|
213
|
+
"@cloudhal/comments": "0.6.0"
|
|
194
214
|
},
|
|
195
215
|
"peerDependencies": {
|
|
196
216
|
"astro": "^7.3.0",
|
|
@@ -221,6 +241,7 @@
|
|
|
221
241
|
"scripts": {
|
|
222
242
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
223
243
|
"test": "vitest run",
|
|
244
|
+
"bench:lists": "vitest run -c bench/vitest.config.ts",
|
|
224
245
|
"check": "pnpm typecheck && pnpm test"
|
|
225
246
|
}
|
|
226
247
|
}
|