@cloudhal/astro-renderer 0.5.0 → 0.6.1
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/csp-middleware.d.ts +5 -0
- package/dist/src/csp-middleware.js +33 -0
- package/dist/src/csp.d.ts +6 -0
- package/dist/src/csp.js +15 -0
- 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 +47 -28
- 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 +31 -6
package/dist/src/source.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Asset, ContentEntry, Menu, Page, Redirect, Site, Snapshot, Taxonomy, Term } from "@cloudhal/core-contracts";
|
|
2
2
|
import type { RedirectMatch, SearchKind, SearchResults, SiteGraphStore } from "@cloudhal/core-ts";
|
|
3
|
+
import { type DerivedGate, type ResolvedFields } from "@cloudhal/core-ts/fields";
|
|
4
|
+
import { type FieldEntryQuery, type FieldEntryResult } from "./entry-query.js";
|
|
3
5
|
import { type EntryFieldsOptions, type RenderedFields } from "./fields.js";
|
|
4
6
|
import { type Navigation, type NavigationOptions } from "./navigation.js";
|
|
7
|
+
export { LiveSource } from "./live-source.js";
|
|
5
8
|
/**
|
|
6
9
|
* What a renderer needs from a site, independent of whether it reads live nodes (dev) or a
|
|
7
10
|
* published snapshot (build/production).
|
|
@@ -11,10 +14,22 @@ export interface GraphSource {
|
|
|
11
14
|
site(): Promise<Site>;
|
|
12
15
|
pages(): Promise<Page[]>;
|
|
13
16
|
pageByPath(path: string, locale?: string): Promise<Page | undefined>;
|
|
17
|
+
/** Listed entries of a collection, newest first (RFC-0042: unlisted ones left out). */
|
|
14
18
|
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
19
|
+
/** An entry with a public URL by slug: listed, or unlisted past its collection's expiry. */
|
|
15
20
|
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
16
|
-
/** Every
|
|
21
|
+
/** Every listed entry of a locale, newest first, across collections (feeds, sitemaps). */
|
|
17
22
|
allEntries(locale?: string): Promise<ContentEntry[]>;
|
|
23
|
+
/**
|
|
24
|
+
* RFC-0042 §3: every entry of a locale with a public URL, newest first — `allEntries` plus the
|
|
25
|
+
* unlisted ones (routes, static builds, language alternates). Optional for older sources.
|
|
26
|
+
*/
|
|
27
|
+
routableEntries?(locale?: string): Promise<ContentEntry[]>;
|
|
28
|
+
/**
|
|
29
|
+
* RFC-0042 §4: a collection filtered and ordered by its list fields, paged (`queryEntries`).
|
|
30
|
+
* Optional for older sources; the standalone `queryEntries(source, q)` works with any.
|
|
31
|
+
*/
|
|
32
|
+
queryEntries?(q: FieldEntryQuery): Promise<FieldEntryResult>;
|
|
18
33
|
/**
|
|
19
34
|
* A visible entry by id, any locale (reader comments name the entry by id, RFC-0007 §6.2).
|
|
20
35
|
* Optional for sources that predate comments.
|
|
@@ -98,55 +113,20 @@ export interface SourceSearchOptions {
|
|
|
98
113
|
/** RFC-0029: only these kinds (default: all). */
|
|
99
114
|
kinds?: readonly SearchKind[];
|
|
100
115
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Reads the current nodes on every call. Drafts are included so authors can preview them in dev,
|
|
103
|
-
* and so are gated nodes (a preview shows embargoed and expired content, RFC-0008 §7.3). Without
|
|
104
|
-
* drafts it serves what the public would see: published nodes whose gates are open at `now`.
|
|
105
|
-
*/
|
|
106
|
-
export declare class LiveSource implements GraphSource {
|
|
107
|
-
#private;
|
|
108
|
-
readonly mode = "live";
|
|
109
|
-
constructor(store: SiteGraphStore, siteId: string, options?: {
|
|
110
|
-
includeDrafts?: boolean;
|
|
111
|
-
now?: () => number;
|
|
112
|
-
});
|
|
113
|
-
nextGate(): Promise<number | undefined>;
|
|
114
|
-
site(): Promise<Site>;
|
|
115
|
-
pages(): Promise<Page[]>;
|
|
116
|
-
pageByPath(path: string, locale?: string): Promise<Page | undefined>;
|
|
117
|
-
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
118
|
-
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
119
|
-
allEntries(locale?: string): Promise<ContentEntry[]>;
|
|
120
|
-
search(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
121
|
-
entryById(id: string): Promise<ContentEntry | undefined>;
|
|
122
|
-
entryFields(entry: ContentEntry, options?: EntryFieldsOptions): Promise<RenderedFields>;
|
|
123
|
-
taxonomies(): Promise<Taxonomy[]>;
|
|
124
|
-
terms(key: string): Promise<Term[]>;
|
|
125
|
-
termBySlug(key: string, slug: string): Promise<Term | undefined>;
|
|
126
|
-
vocabulary(key?: string): Promise<Term[]>;
|
|
127
|
-
entriesByFilter(filter: string, options?: {
|
|
128
|
-
locale?: string;
|
|
129
|
-
limit?: number;
|
|
130
|
-
}): Promise<ContentEntry[]>;
|
|
131
|
-
entriesByTerm(key: string, slug: string, options?: {
|
|
132
|
-
locale?: string;
|
|
133
|
-
limit?: number;
|
|
134
|
-
descendants?: boolean;
|
|
135
|
-
}): Promise<ContentEntry[]>;
|
|
136
|
-
redirectFor(path: string, locale?: string): Promise<RedirectMatch | undefined>;
|
|
137
|
-
redirects(): Promise<Redirect[]>;
|
|
138
|
-
menu(key: string): Promise<Menu | undefined>;
|
|
139
|
-
navigation(key: string, locale?: string, options?: NavigationOptions): Promise<Navigation | undefined>;
|
|
140
|
-
assets(): Promise<Asset[]>;
|
|
141
|
-
asset(id: string): Promise<Asset | undefined>;
|
|
142
|
-
assetByPrefix(prefix16: string): Promise<Asset | undefined>;
|
|
143
|
-
}
|
|
144
116
|
/** Everything a snapshot shows before gates are applied; built once per snapshot and isolate. */
|
|
145
117
|
interface Loaded {
|
|
146
118
|
site: Site;
|
|
147
119
|
/** Published pages in `Site.pageIds` order and published entries, gates not yet applied. */
|
|
148
120
|
pages: Page[];
|
|
149
121
|
entries: ContentEntry[];
|
|
122
|
+
/** The same published entries (a view keeps them for originals; RFC-0042). */
|
|
123
|
+
published: ContentEntry[];
|
|
124
|
+
/** Published entries with a public URL (unlisted ones too); `entries` holds the listed. */
|
|
125
|
+
reachable: ContentEntry[];
|
|
126
|
+
/** Every published entry's derived gate (RFC-0042 §3), computed once per snapshot. */
|
|
127
|
+
derived: ReadonlyMap<string, DerivedGate>;
|
|
128
|
+
/** Resolved field values by entry id, filled as queries need them (the snapshot is immutable). */
|
|
129
|
+
resolved: Map<string, ResolvedFields>;
|
|
150
130
|
taxonomies: Taxonomy[];
|
|
151
131
|
terms: Term[];
|
|
152
132
|
redirects: Redirect[];
|
|
@@ -156,7 +136,8 @@ interface Loaded {
|
|
|
156
136
|
assetIndex: Map<string, Asset>;
|
|
157
137
|
/**
|
|
158
138
|
* The gate index (RFC-0008 §7.4): every instant at which a published page's or entry's gate
|
|
159
|
-
* changes
|
|
139
|
+
* changes — derived gates and list-field instants included (RFC-0042) — sorted. Empty for a
|
|
140
|
+
* site that schedules nothing — then nothing is filtered at all.
|
|
160
141
|
*/
|
|
161
142
|
gates: number[];
|
|
162
143
|
}
|
|
@@ -210,6 +191,10 @@ export declare class SnapshotSource implements GraphSource {
|
|
|
210
191
|
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
211
192
|
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
212
193
|
allEntries(locale?: string): Promise<ContentEntry[]>;
|
|
194
|
+
/** Every entry of a locale with a public URL, unlisted ones included (RFC-0042 §3). */
|
|
195
|
+
routableEntries(locale?: string): Promise<ContentEntry[]>;
|
|
196
|
+
/** RFC-0042 §4: a collection by its list fields, `now` at this view's instant. */
|
|
197
|
+
queryEntries(q: FieldEntryQuery): Promise<FieldEntryResult>;
|
|
213
198
|
search(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
214
199
|
/** A published entry of this snapshot by id (any locale), if its gates are open. */
|
|
215
200
|
entryById(id: string): Promise<ContentEntry | undefined>;
|
|
@@ -235,4 +220,3 @@ export declare class SnapshotSource implements GraphSource {
|
|
|
235
220
|
asset(id: string): Promise<Asset | undefined>;
|
|
236
221
|
assetByPrefix(prefix16: string): Promise<Asset | undefined>;
|
|
237
222
|
}
|
|
238
|
-
export {};
|
package/dist/src/source.js
CHANGED
|
@@ -11,20 +11,24 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
import { matchRedirect, redirectLocale
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
hasGates,
|
|
18
|
-
inheritedGate,
|
|
19
|
-
isAvailable,
|
|
20
|
-
nextInstant,
|
|
21
|
-
} from "@cloudhal/core-ts/availability";
|
|
14
|
+
import { matchRedirect, redirectLocale } from "@cloudhal/core-ts";
|
|
15
|
+
import { hasGates, inheritedGate, isAvailable, nextInstant } from "@cloudhal/core-ts/availability";
|
|
16
|
+
import { derivedGates, } from "@cloudhal/core-ts/fields";
|
|
22
17
|
import { matches } from "@cloudhal/core-ts/filter";
|
|
23
18
|
import { assetRefsOf } from "@cloudhal/core-ts/media";
|
|
19
|
+
import {
|
|
20
|
+
evaluateEntryQuery,
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
rememberList,
|
|
24
|
+
} from "./entry-query.js";
|
|
25
|
+
import { gateIndex, splitEntries } from "./entry-views.js";
|
|
24
26
|
import { entryFields, } from "./fields.js";
|
|
25
27
|
import { navigationFor } from "./navigation.js";
|
|
26
28
|
import { byNewest, byPosition, compile, shown, termFilter, visible } from "./source-helpers.js";
|
|
27
29
|
|
|
30
|
+
export { LiveSource } from "./live-source.js";
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* What a renderer needs from a site, independent of whether it reads live nodes (dev) or a
|
|
30
34
|
* published snapshot (build/production).
|
|
@@ -34,11 +38,23 @@ import { byNewest, byPosition, compile, shown, termFilter, visible } from "./sou
|
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
|
|
41
|
+
|
|
37
42
|
|
|
43
|
+
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
|
|
40
46
|
|
|
41
47
|
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
42
58
|
|
|
43
59
|
|
|
44
60
|
|
|
@@ -127,234 +143,20 @@ import { byNewest, byPosition, compile, shown, termFilter, visible } from "./sou
|
|
|
127
143
|
|
|
128
144
|
|
|
129
145
|
|
|
130
|
-
/**
|
|
131
|
-
* Reads the current nodes on every call. Drafts are included so authors can preview them in dev,
|
|
132
|
-
* and so are gated nodes (a preview shows embargoed and expired content, RFC-0008 §7.3). Without
|
|
133
|
-
* drafts it serves what the public would see: published nodes whose gates are open at `now`.
|
|
134
|
-
*/
|
|
135
|
-
export class LiveSource {
|
|
136
|
-
mode = "live";
|
|
137
|
-
#store ;
|
|
138
|
-
#siteId ;
|
|
139
|
-
#includeDrafts ;
|
|
140
|
-
#now ;
|
|
141
|
-
|
|
142
|
-
constructor(
|
|
143
|
-
store ,
|
|
144
|
-
siteId ,
|
|
145
|
-
options = {},
|
|
146
|
-
) {
|
|
147
|
-
this.#store = store;
|
|
148
|
-
this.#siteId = siteId;
|
|
149
|
-
this.#includeDrafts = options.includeDrafts ?? true;
|
|
150
|
-
this.#now = options.now ?? Date.now;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** Drafts and gated nodes, or what the public sees now. */
|
|
154
|
-
#visible (nodes ) {
|
|
155
|
-
if (this.#includeDrafts) return visible(nodes, true);
|
|
156
|
-
const now = this.#now();
|
|
157
|
-
return nodes.filter((n) => isAvailable(n, now));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async nextGate() {
|
|
161
|
-
if (this.#includeDrafts) return undefined;
|
|
162
|
-
const [pages, entries] = await Promise.all([
|
|
163
|
-
this.#store.listPages(this.#siteId),
|
|
164
|
-
this.#store.listContentEntries(this.#siteId),
|
|
165
|
-
]);
|
|
166
|
-
const published = [...pages, ...entries].filter((n) => n.status === "published");
|
|
167
|
-
return nextInstant(gateInstants(published), this.#now());
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async site() {
|
|
171
|
-
const site = await this.#store.getSite(this.#siteId);
|
|
172
|
-
if (!site) throw new Error(`site ${this.#siteId} not found`);
|
|
173
|
-
return site;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async pages() {
|
|
177
|
-
const site = await this.site();
|
|
178
|
-
const pages = this.#visible(await this.#store.listPages(this.#siteId));
|
|
179
|
-
const order = new Map(site.pageIds.map((id, i) => [id, i]));
|
|
180
|
-
return pages.sort((a, b) => (order.get(a.id) ?? 1e9) - (order.get(b.id) ?? 1e9));
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
async pageByPath(path , locale ) {
|
|
184
|
-
const loc = locale ?? (await this.site()).defaultLocale;
|
|
185
|
-
return (await this.pages()).find((p) => p.path === path && p.locale === loc);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async entries(collection , locale ) {
|
|
189
|
-
const loc = locale ?? (await this.site()).defaultLocale;
|
|
190
|
-
const all = this.#visible(await this.#store.listContentEntries(this.#siteId, collection));
|
|
191
|
-
return all.filter((e) => e.locale === loc).sort(byNewest);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async entryBySlug(
|
|
195
|
-
collection ,
|
|
196
|
-
slug ,
|
|
197
|
-
locale ,
|
|
198
|
-
) {
|
|
199
|
-
return (await this.entries(collection, locale)).find((e) => e.slug === slug);
|
|
200
|
-
}
|
|
201
|
-
async allEntries(locale ) {
|
|
202
|
-
const loc = locale ?? (await this.site()).defaultLocale;
|
|
203
|
-
return this.#visible(await this.#store.listContentEntries(this.#siteId))
|
|
204
|
-
.filter((e) => e.locale === loc)
|
|
205
|
-
.sort(byNewest);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async search(query , options = {}) {
|
|
209
|
-
const site = await this.site();
|
|
210
|
-
const locale = options.locale ?? site.defaultLocale;
|
|
211
|
-
// What this source shows decided visibility and gates already (drafts included).
|
|
212
|
-
const [entries, pages, taxonomies, terms] = await Promise.all([
|
|
213
|
-
this.allEntries(locale),
|
|
214
|
-
this.pages(),
|
|
215
|
-
this.taxonomies(),
|
|
216
|
-
this.vocabulary(),
|
|
217
|
-
]);
|
|
218
|
-
const rows = searchDocuments({
|
|
219
|
-
locales: [locale],
|
|
220
|
-
defaultLocale: site.defaultLocale,
|
|
221
|
-
site,
|
|
222
|
-
entries,
|
|
223
|
-
pages: pages.filter((p) => p.locale === locale),
|
|
224
|
-
taxonomies,
|
|
225
|
-
terms,
|
|
226
|
-
drafts: true,
|
|
227
|
-
}).map((r) => ({ ...r, gateFrom: undefined, gateUntil: undefined }));
|
|
228
|
-
return searchRows(rows, query, { ...options, locale, now: this.#now() });
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async entryById(id ) {
|
|
232
|
-
const entry = await this.#store.getContentEntry(id);
|
|
233
|
-
return entry && entry.siteId === this.#siteId && this.#visible([entry]).length
|
|
234
|
-
? entry
|
|
235
|
-
: undefined;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
entryFields(entry , options ) {
|
|
239
|
-
return entryFields(this, entry, options);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
taxonomies() {
|
|
243
|
-
return this.#store.listTaxonomies(this.#siteId);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async terms(key ) {
|
|
247
|
-
const loc = (await this.site()).defaultLocale;
|
|
248
|
-
return (await this.#store.listTerms(this.#siteId, { taxonomy: key }))
|
|
249
|
-
.filter((t) => shown(t, this.#includeDrafts))
|
|
250
|
-
.sort(byPosition(loc));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
async termBySlug(key , slug ) {
|
|
254
|
-
return (await this.terms(key)).find((t) => t.slug === slug);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
vocabulary(key ) {
|
|
258
|
-
return this.#store.listTerms(this.#siteId, key === undefined ? {} : { taxonomy: key });
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
async entriesByFilter(
|
|
262
|
-
filter ,
|
|
263
|
-
options = {},
|
|
264
|
-
) {
|
|
265
|
-
const loc = options.locale ?? (await this.site()).defaultLocale;
|
|
266
|
-
const [taxonomies, terms, entries] = await Promise.all([
|
|
267
|
-
this.#store.listTaxonomies(this.#siteId),
|
|
268
|
-
this.#store.listTerms(this.#siteId),
|
|
269
|
-
this.#store.listContentEntries(this.#siteId, { locale: loc }),
|
|
270
|
-
]);
|
|
271
|
-
const f = compile(filter, taxonomies, terms);
|
|
272
|
-
const out = this.#visible(entries)
|
|
273
|
-
.filter((e) => matches(f, e))
|
|
274
|
-
.sort(byNewest);
|
|
275
|
-
return options.limit === undefined ? out : out.slice(0, options.limit);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
entriesByTerm(
|
|
279
|
-
key ,
|
|
280
|
-
slug ,
|
|
281
|
-
options = {},
|
|
282
|
-
) {
|
|
283
|
-
return this.entriesByFilter(termFilter(key, slug, options.descendants === true), options);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
redirectFor(path , locale ) {
|
|
287
|
-
return this.#store.redirectFor(this.#siteId, path, locale);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
redirects() {
|
|
291
|
-
return this.#store.listRedirects(this.#siteId);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
menu(key ) {
|
|
295
|
-
return this.#store.getMenuByKey(this.#siteId, key);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
async navigation(
|
|
299
|
-
key ,
|
|
300
|
-
locale ,
|
|
301
|
-
options = {},
|
|
302
|
-
) {
|
|
303
|
-
const menu = await this.menu(key);
|
|
304
|
-
if (!menu) return undefined;
|
|
305
|
-
const site = await this.site();
|
|
306
|
-
const [pages, entries, taxonomies, terms] = await Promise.all([
|
|
307
|
-
this.#store.listPages(this.#siteId),
|
|
308
|
-
this.#store.listContentEntries(this.#siteId),
|
|
309
|
-
this.#store.listTaxonomies(this.#siteId),
|
|
310
|
-
this.#store.listTerms(this.#siteId),
|
|
311
|
-
]);
|
|
312
|
-
return navigationFor(
|
|
313
|
-
menu,
|
|
314
|
-
{
|
|
315
|
-
site,
|
|
316
|
-
// drafts: everything but archived (the lookup decides); public: what is available now
|
|
317
|
-
pages: this.#includeDrafts ? pages : this.#visible(pages),
|
|
318
|
-
entries: this.#includeDrafts ? entries : this.#visible(entries),
|
|
319
|
-
taxonomies,
|
|
320
|
-
terms,
|
|
321
|
-
includeDrafts: this.#includeDrafts,
|
|
322
|
-
...(options.collectionIndex ? { collectionIndex: options.collectionIndex } : {}),
|
|
323
|
-
},
|
|
324
|
-
locale ?? site.defaultLocale,
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
async assets() {
|
|
329
|
-
const out = [];
|
|
330
|
-
let cursor ;
|
|
331
|
-
do {
|
|
332
|
-
const page = await this.#store.listAssets(this.#siteId, {
|
|
333
|
-
limit: 200,
|
|
334
|
-
...(cursor ? { cursor } : {}),
|
|
335
|
-
});
|
|
336
|
-
out.push(...page.assets);
|
|
337
|
-
cursor = page.nextCursor;
|
|
338
|
-
} while (cursor);
|
|
339
|
-
return out;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
async asset(id ) {
|
|
343
|
-
const a = await this.#store.getAsset(id);
|
|
344
|
-
return a?.siteId === this.#siteId ? a : undefined;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
assetByPrefix(prefix16 ) {
|
|
348
|
-
return this.#store.getAssetByPrefix(this.#siteId, prefix16);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
146
|
/** Everything a snapshot shows before gates are applied; built once per snapshot and isolate. */
|
|
353
147
|
|
|
354
148
|
|
|
355
149
|
|
|
356
150
|
|
|
357
151
|
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
358
160
|
|
|
359
161
|
|
|
360
162
|
|
|
@@ -364,7 +166,8 @@ export class LiveSource {
|
|
|
364
166
|
|
|
365
167
|
|
|
366
168
|
|
|
367
|
-
|
|
169
|
+
|
|
170
|
+
|
|
368
171
|
|
|
369
172
|
|
|
370
173
|
|
|
@@ -373,7 +176,14 @@ export class LiveSource {
|
|
|
373
176
|
|
|
374
177
|
|
|
375
178
|
|
|
179
|
+
|
|
376
180
|
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
377
187
|
|
|
378
188
|
|
|
379
189
|
|
|
@@ -540,18 +350,23 @@ export class SnapshotSource {
|
|
|
540
350
|
(a, b) => (order.get(a.id) ?? 1e9) - (order.get(b.id) ?? 1e9),
|
|
541
351
|
);
|
|
542
352
|
const shownEntries = visible(entries, false);
|
|
353
|
+
const derived = derivedGates(site , shownEntries);
|
|
543
354
|
if (fetched) this.#shared.fetched = fetched;
|
|
544
355
|
return {
|
|
545
356
|
site: site ,
|
|
546
357
|
pages: shownPages,
|
|
547
358
|
entries: shownEntries,
|
|
359
|
+
published: shownEntries,
|
|
360
|
+
reachable: shownEntries,
|
|
361
|
+
derived,
|
|
362
|
+
resolved: new Map(),
|
|
548
363
|
taxonomies,
|
|
549
364
|
terms,
|
|
550
365
|
redirects,
|
|
551
366
|
menus,
|
|
552
367
|
assets,
|
|
553
368
|
assetIndex,
|
|
554
|
-
gates:
|
|
369
|
+
gates: gateIndex(site , shownPages, shownEntries, derived),
|
|
555
370
|
};
|
|
556
371
|
})();
|
|
557
372
|
this.#shared.loaded.catch(() => {
|
|
@@ -605,10 +420,12 @@ export class SnapshotSource {
|
|
|
605
420
|
hidden.size === 0
|
|
606
421
|
? loaded.assetIndex
|
|
607
422
|
: new Map([...loaded.assetIndex].filter(([, a]) => !hidden.has(a.id)));
|
|
423
|
+
const split = splitEntries(loaded.entries, now, loaded.derived);
|
|
608
424
|
return {
|
|
609
425
|
...loaded,
|
|
610
426
|
pages: loaded.pages.filter((p) => isAvailable(p, now)),
|
|
611
|
-
entries:
|
|
427
|
+
entries: split.listed,
|
|
428
|
+
reachable: split.reachable,
|
|
612
429
|
assets,
|
|
613
430
|
assetIndex,
|
|
614
431
|
};
|
|
@@ -634,7 +451,8 @@ export class SnapshotSource {
|
|
|
634
451
|
async entries(collection , locale ) {
|
|
635
452
|
const { site, entries } = await this.#current();
|
|
636
453
|
const loc = locale ?? site.defaultLocale;
|
|
637
|
-
|
|
454
|
+
const out = entries.filter((e) => e.collection === collection && e.locale === loc);
|
|
455
|
+
return rememberList(out.sort(byNewest), { source: this, locale: loc });
|
|
638
456
|
}
|
|
639
457
|
|
|
640
458
|
async entryBySlug(
|
|
@@ -642,14 +460,43 @@ export class SnapshotSource {
|
|
|
642
460
|
slug ,
|
|
643
461
|
locale ,
|
|
644
462
|
) {
|
|
645
|
-
|
|
463
|
+
const { site, reachable } = await this.#current();
|
|
464
|
+
const loc = locale ?? site.defaultLocale;
|
|
465
|
+
return reachable.find(
|
|
466
|
+
(e) => e.collection === collection && e.slug === slug && e.locale === loc,
|
|
467
|
+
);
|
|
646
468
|
}
|
|
469
|
+
|
|
647
470
|
async allEntries(locale ) {
|
|
648
471
|
const { site, entries } = await this.#current();
|
|
649
472
|
const loc = locale ?? site.defaultLocale;
|
|
650
473
|
return entries.filter((e) => e.locale === loc).sort(byNewest);
|
|
651
474
|
}
|
|
652
475
|
|
|
476
|
+
/** Every entry of a locale with a public URL, unlisted ones included (RFC-0042 §3). */
|
|
477
|
+
async routableEntries(locale ) {
|
|
478
|
+
const { site, reachable } = await this.#current();
|
|
479
|
+
const loc = locale ?? site.defaultLocale;
|
|
480
|
+
return reachable.filter((e) => e.locale === loc).sort(byNewest);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** RFC-0042 §4: a collection by its list fields, `now` at this view's instant. */
|
|
484
|
+
async queryEntries(q ) {
|
|
485
|
+
const view = await this.#current();
|
|
486
|
+
const loc = q.locale ?? view.site.defaultLocale;
|
|
487
|
+
const shownHere = q.includeExpired ? view.reachable : view.entries;
|
|
488
|
+
return evaluateEntryQuery({
|
|
489
|
+
site: view.site,
|
|
490
|
+
candidates: shownHere.filter((e) => e.collection === q.collection && e.locale === loc),
|
|
491
|
+
published: view.published,
|
|
492
|
+
taxonomies: view.taxonomies,
|
|
493
|
+
terms: view.terms,
|
|
494
|
+
query: q,
|
|
495
|
+
now: this.#clock?.() ?? Date.now(),
|
|
496
|
+
cache: view.resolved,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
|
|
653
500
|
async search(query , options = {}) {
|
|
654
501
|
const locale = options.locale ?? (await this.site()).defaultLocale;
|
|
655
502
|
return this.#store.search(this.#snapshot.siteId, query, {
|
|
@@ -662,7 +509,7 @@ export class SnapshotSource {
|
|
|
662
509
|
|
|
663
510
|
/** A published entry of this snapshot by id (any locale), if its gates are open. */
|
|
664
511
|
async entryById(id ) {
|
|
665
|
-
return (await this.#current()).
|
|
512
|
+
return (await this.#current()).reachable.find((e) => e.id === id);
|
|
666
513
|
}
|
|
667
514
|
|
|
668
515
|
entryFields(entry , options ) {
|
|
@@ -702,7 +549,10 @@ export class SnapshotSource {
|
|
|
702
549
|
const loc = options.locale ?? site.defaultLocale;
|
|
703
550
|
const f = compile(filter, taxonomies, terms);
|
|
704
551
|
const out = entries.filter((e) => e.locale === loc && matches(f, e)).sort(byNewest);
|
|
705
|
-
return options.limit === undefined ? out : out.slice(0, options.limit)
|
|
552
|
+
return rememberList(options.limit === undefined ? out : out.slice(0, options.limit), {
|
|
553
|
+
source: this,
|
|
554
|
+
locale: loc,
|
|
555
|
+
});
|
|
706
556
|
}
|
|
707
557
|
|
|
708
558
|
entriesByTerm(
|
|
@@ -741,7 +591,7 @@ export class SnapshotSource {
|
|
|
741
591
|
{
|
|
742
592
|
site: view.site,
|
|
743
593
|
pages: view.pages,
|
|
744
|
-
entries: view.
|
|
594
|
+
entries: view.reachable,
|
|
745
595
|
taxonomies: view.taxonomies,
|
|
746
596
|
terms: view.terms,
|
|
747
597
|
...(options.collectionIndex ? { collectionIndex: options.collectionIndex } : {}),
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
import type { ContentEntry } from "@cloudhal/core-contracts";
|
|
13
|
+
import { type StructuredDataResult } from "@cloudhal/core-ts/structured-data";
|
|
14
|
+
import { type MediaContext } from "./media.js";
|
|
15
|
+
import type { HeadMeta } from "./seo.js";
|
|
16
|
+
import type { GraphSource } from "./source.js";
|
|
17
|
+
export interface StructuredDataOptions {
|
|
18
|
+
/** The site's public origin (`siteOrigin`); every URL in the document is absolute on it. */
|
|
19
|
+
readonly origin: string;
|
|
20
|
+
/** The page's media context: its asset index is reused when given. */
|
|
21
|
+
readonly media?: MediaContext | undefined;
|
|
22
|
+
}
|
|
23
|
+
type StructuredDataSource = Pick<GraphSource, "site"> & Partial<Pick<GraphSource, "entryById" | "assets">>;
|
|
24
|
+
/**
|
|
25
|
+
* The preset document of an entry and why it has none (`issues`): no preset, a required value
|
|
26
|
+
* missing, or over the cap. What `withStructuredData` emits, and what previews and checks show.
|
|
27
|
+
*/
|
|
28
|
+
export declare function entryStructuredData(source: StructuredDataSource, entry: ContentEntry, options: StructuredDataOptions): Promise<StructuredDataResult>;
|
|
29
|
+
/**
|
|
30
|
+
* `head` with the entry's preset document in place of the `BlogPosting` (RFC-0042 §2), when its
|
|
31
|
+
* collection has a preset and the entry has every required value; otherwise `head` unchanged.
|
|
32
|
+
* The `BreadcrumbList` stays; the `BlogPosting`'s `commentCount` does not move to the preset.
|
|
33
|
+
*/
|
|
34
|
+
export declare function withStructuredData(head: HeadMeta, source: StructuredDataSource, entry: ContentEntry, options: StructuredDataOptions): Promise<HeadMeta>;
|
|
35
|
+
export {};
|