@cloudhal/astro-renderer 0.4.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.
Files changed (38) hide show
  1. package/README.md +40 -1
  2. package/dist/src/cloudflare-entry.d.ts +3 -2
  3. package/dist/src/cloudflare-entry.js +3 -2
  4. package/dist/src/collection-feed-middleware.d.ts +5 -0
  5. package/dist/src/collection-feed-middleware.js +22 -0
  6. package/dist/src/collection-feed-route.d.ts +21 -0
  7. package/dist/src/collection-feed-route.js +92 -0
  8. package/dist/src/collection-feeds.d.ts +40 -0
  9. package/dist/src/collection-feeds.js +87 -0
  10. package/dist/src/components/ContentList.astro +26 -9
  11. package/dist/src/components/EntryFields.astro +43 -0
  12. package/dist/src/components/index.d.ts +1 -0
  13. package/dist/src/components/index.js +1 -0
  14. package/dist/src/entry-query.d.ts +85 -0
  15. package/dist/src/entry-query.js +227 -0
  16. package/dist/src/entry-views.d.ts +36 -0
  17. package/dist/src/entry-views.js +73 -0
  18. package/dist/src/fields.d.ts +77 -0
  19. package/dist/src/fields.js +201 -0
  20. package/dist/src/index.d.ts +6 -1
  21. package/dist/src/index.js +10 -1
  22. package/dist/src/integration.js +30 -19
  23. package/dist/src/live-source.d.ts +53 -0
  24. package/dist/src/live-source.js +318 -0
  25. package/dist/src/locales.js +4 -3
  26. package/dist/src/preview.d.ts +16 -1
  27. package/dist/src/preview.js +89 -14
  28. package/dist/src/routing.d.ts +1 -1
  29. package/dist/src/routing.js +13 -3
  30. package/dist/src/seo.d.ts +4 -1
  31. package/dist/src/seo.js +9 -0
  32. package/dist/src/source-helpers.d.ts +11 -0
  33. package/dist/src/source-helpers.js +48 -0
  34. package/dist/src/source.d.ts +40 -45
  35. package/dist/src/source.js +104 -283
  36. package/dist/src/structured-data.d.ts +35 -0
  37. package/dist/src/structured-data.js +88 -0
  38. package/package.json +31 -6
@@ -61,6 +61,26 @@ const RESOLVED_CLIENT_ID = `\0${CLIENT_ID}`;
61
61
  const COMMENTS_CLIENT_ID = "virtual:cloudhal/comments-client";
62
62
  const RESOLVED_COMMENTS_CLIENT_ID = `\0${COMMENTS_CLIENT_ID}`;
63
63
 
64
+ /** The virtual modules: the project config, and in dev the built analytics and comments clients. */
65
+ function configPlugin(modules ) {
66
+ const ids = {
67
+ [VIRTUAL_ID]: RESOLVED_ID,
68
+ [CLIENT_ID]: RESOLVED_CLIENT_ID,
69
+ [COMMENTS_CLIENT_ID]: RESOLVED_COMMENTS_CLIENT_ID,
70
+ };
71
+ const bodies = {
72
+ [RESOLVED_ID]: modules.config,
73
+ [RESOLVED_CLIENT_ID]: modules.client,
74
+ [RESOLVED_COMMENTS_CLIENT_ID]: modules.comments,
75
+ };
76
+ return {
77
+ name: "cloudhal-config",
78
+ resolveId: (id ) => (Object.hasOwn(ids, id) ? ids[id] : undefined),
79
+ load: (id ) =>
80
+ Object.hasOwn(bodies, id) ? `export default ${JSON.stringify(bodies[id])};` : undefined,
81
+ };
82
+ }
83
+
64
84
  export function cloudhal(config ) {
65
85
  let resolved = config;
66
86
  let client ;
@@ -120,28 +140,19 @@ export function cloudhal(config ) {
120
140
  order: "pre",
121
141
  });
122
142
  }
143
+ // RFC-0042 §5: a collection's feed where the theme's routes answer 404, on every target.
144
+ addMiddleware({
145
+ entrypoint: "@cloudhal/astro-renderer/collection-feed-middleware",
146
+ order: "pre",
147
+ });
123
148
  updateConfig({
124
149
  vite: {
125
150
  plugins: [
126
- {
127
- name: "cloudhal-config",
128
- resolveId: (id ) =>
129
- id === VIRTUAL_ID
130
- ? RESOLVED_ID
131
- : id === CLIENT_ID
132
- ? RESOLVED_CLIENT_ID
133
- : id === COMMENTS_CLIENT_ID
134
- ? RESOLVED_COMMENTS_CLIENT_ID
135
- : undefined,
136
- load: (id ) =>
137
- id === RESOLVED_ID
138
- ? `export default ${JSON.stringify(resolved)};`
139
- : id === RESOLVED_CLIENT_ID
140
- ? `export default ${JSON.stringify(cloudflare ? null : (client ?? null))};`
141
- : id === RESOLVED_COMMENTS_CLIENT_ID
142
- ? `export default ${JSON.stringify(cloudflare ? null : (comments ?? null))};`
143
- : undefined,
144
- },
151
+ configPlugin({
152
+ config: resolved,
153
+ client: cloudflare ? null : (client ?? null),
154
+ comments: cloudflare ? null : (comments ?? null),
155
+ }),
145
156
  ],
146
157
  // Native module must stay external in Node SSR; workerd never loads it.
147
158
  ...(cloudflare ? {} : { ssr: { external: ["better-sqlite3"] } }),
@@ -0,0 +1,53 @@
1
+ import type { Asset, ContentEntry, Menu, Page, Redirect, Site, Taxonomy, Term } from "@cloudhal/core-contracts";
2
+ import type { RedirectMatch, SearchResults, SiteGraphStore } from "@cloudhal/core-ts";
3
+ import { type FieldEntryQuery, type FieldEntryResult } from "./entry-query.js";
4
+ import { type EntryFieldsOptions, type RenderedFields } from "./fields.js";
5
+ import { type Navigation, type NavigationOptions } from "./navigation.js";
6
+ import type { GraphSource, SourceSearchOptions } from "./source.js";
7
+ /**
8
+ * Reads the current nodes on every call. Drafts are included so authors can preview them in dev,
9
+ * and so are gated nodes (a preview shows embargoed and expired content, RFC-0008 §7.3). Without
10
+ * drafts it serves what the public would see: published nodes whose gates are open at `now`.
11
+ */
12
+ export declare class LiveSource implements GraphSource {
13
+ #private;
14
+ readonly mode = "live";
15
+ constructor(store: SiteGraphStore, siteId: string, options?: {
16
+ includeDrafts?: boolean;
17
+ now?: () => number;
18
+ });
19
+ nextGate(): Promise<number | undefined>;
20
+ site(): Promise<Site>;
21
+ pages(): Promise<Page[]>;
22
+ pageByPath(path: string, locale?: string): Promise<Page | undefined>;
23
+ entries(collection: string, locale?: string): Promise<ContentEntry[]>;
24
+ entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
25
+ allEntries(locale?: string): Promise<ContentEntry[]>;
26
+ /** Every entry of a locale with a public URL, unlisted ones included (RFC-0042 §3). */
27
+ routableEntries(locale?: string): Promise<ContentEntry[]>;
28
+ /** RFC-0042 §4: a collection by its list fields (`queryEntries`). */
29
+ queryEntries(q: FieldEntryQuery): Promise<FieldEntryResult>;
30
+ search(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
31
+ entryById(id: string): Promise<ContentEntry | undefined>;
32
+ entryFields(entry: ContentEntry, options?: EntryFieldsOptions): Promise<RenderedFields>;
33
+ taxonomies(): Promise<Taxonomy[]>;
34
+ terms(key: string): Promise<Term[]>;
35
+ termBySlug(key: string, slug: string): Promise<Term | undefined>;
36
+ vocabulary(key?: string): Promise<Term[]>;
37
+ entriesByFilter(filter: string, options?: {
38
+ locale?: string;
39
+ limit?: number;
40
+ }): Promise<ContentEntry[]>;
41
+ entriesByTerm(key: string, slug: string, options?: {
42
+ locale?: string;
43
+ limit?: number;
44
+ descendants?: boolean;
45
+ }): Promise<ContentEntry[]>;
46
+ redirectFor(path: string, locale?: string): Promise<RedirectMatch | undefined>;
47
+ redirects(): Promise<Redirect[]>;
48
+ menu(key: string): Promise<Menu | undefined>;
49
+ navigation(key: string, locale?: string, options?: NavigationOptions): Promise<Navigation | undefined>;
50
+ assets(): Promise<Asset[]>;
51
+ asset(id: string): Promise<Asset | undefined>;
52
+ assetByPrefix(prefix16: string): Promise<Asset | undefined>;
53
+ }
@@ -0,0 +1,318 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+ import { searchDocuments, searchRows } from "@cloudhal/core-ts";
13
+ import { isAvailable, nextInstant } from "@cloudhal/core-ts/availability";
14
+ import { derivedGates, hasExpiryRules } from "@cloudhal/core-ts/fields";
15
+ import { matches } from "@cloudhal/core-ts/filter";
16
+ import {
17
+ evaluateEntryQuery,
18
+
19
+
20
+ rememberList,
21
+ } from "./entry-query.js";
22
+ import { gateIndex, splitEntries } from "./entry-views.js";
23
+ import { entryFields, } from "./fields.js";
24
+ import { navigationFor } from "./navigation.js";
25
+
26
+ import { byNewest, byPosition, compile, shown, termFilter, visible } from "./source-helpers.js";
27
+
28
+ /**
29
+ * Reads the current nodes on every call. Drafts are included so authors can preview them in dev,
30
+ * and so are gated nodes (a preview shows embargoed and expired content, RFC-0008 §7.3). Without
31
+ * drafts it serves what the public would see: published nodes whose gates are open at `now`.
32
+ */
33
+ export class LiveSource {
34
+ mode = "live";
35
+ #store ;
36
+ #siteId ;
37
+ #includeDrafts ;
38
+ #now ;
39
+
40
+ constructor(
41
+ store ,
42
+ siteId ,
43
+ options = {},
44
+ ) {
45
+ this.#store = store;
46
+ this.#siteId = siteId;
47
+ this.#includeDrafts = options.includeDrafts ?? true;
48
+ this.#now = options.now ?? Date.now;
49
+ }
50
+
51
+ /** Drafts and gated nodes, or what the public sees now. */
52
+ #visible (nodes ) {
53
+ if (this.#includeDrafts) return visible(nodes, true);
54
+ const now = this.#now();
55
+ return nodes.filter((n) => isAvailable(n, now));
56
+ }
57
+
58
+ /**
59
+ * Entries as the public sees them now, derived gates included (RFC-0042 §3): `listed` for lists,
60
+ * `reachable` for routes. With drafts both are everything not archived (previews ignore gates).
61
+ */
62
+ async #split(
63
+ entries ,
64
+ /** Every entry of the site, when the caller already read them (the pool for originals). */
65
+ all ,
66
+ ) {
67
+ if (this.#includeDrafts) {
68
+ const all = visible(entries, true);
69
+ return { listed: all, reachable: all, published: all };
70
+ }
71
+ const site = await this.site();
72
+ const isPublished = (e ) => e.status === "published";
73
+ // Translations read their original's date, which may sit in another locale or collection.
74
+ const pool = !hasExpiryRules(site)
75
+ ? entries
76
+ : (all ?? (await this.#store.listContentEntries(this.#siteId)));
77
+ const published = pool.filter(isPublished);
78
+ const derived = derivedGates(site, published);
79
+ return { ...splitEntries(entries.filter(isPublished), this.#now(), derived), published };
80
+ }
81
+
82
+ async nextGate() {
83
+ if (this.#includeDrafts) return undefined;
84
+ const [site, pages, entries] = await Promise.all([
85
+ this.site(),
86
+ this.#store.listPages(this.#siteId),
87
+ this.#store.listContentEntries(this.#siteId),
88
+ ]);
89
+ const isPublished = (n ) => n.status === "published";
90
+ const gates = gateIndex(site, pages.filter(isPublished), entries.filter(isPublished));
91
+ return nextInstant(gates, this.#now());
92
+ }
93
+
94
+ async site() {
95
+ const site = await this.#store.getSite(this.#siteId);
96
+ if (!site) throw new Error(`site ${this.#siteId} not found`);
97
+ return site;
98
+ }
99
+
100
+ async pages() {
101
+ const site = await this.site();
102
+ const pages = this.#visible(await this.#store.listPages(this.#siteId));
103
+ const order = new Map(site.pageIds.map((id, i) => [id, i]));
104
+ return pages.sort((a, b) => (order.get(a.id) ?? 1e9) - (order.get(b.id) ?? 1e9));
105
+ }
106
+
107
+ async pageByPath(path , locale ) {
108
+ const loc = locale ?? (await this.site()).defaultLocale;
109
+ return (await this.pages()).find((p) => p.path === path && p.locale === loc);
110
+ }
111
+
112
+ async entries(collection , locale ) {
113
+ const loc = locale ?? (await this.site()).defaultLocale;
114
+ const { listed } = await this.#split(
115
+ await this.#store.listContentEntries(this.#siteId, collection),
116
+ );
117
+ const out = listed.filter((e) => e.locale === loc).sort(byNewest);
118
+ return rememberList(out, { source: this, locale: loc });
119
+ }
120
+
121
+ async entryBySlug(
122
+ collection ,
123
+ slug ,
124
+ locale ,
125
+ ) {
126
+ const loc = locale ?? (await this.site()).defaultLocale;
127
+ const { reachable } = await this.#split(
128
+ await this.#store.listContentEntries(this.#siteId, collection),
129
+ );
130
+ return reachable.find((e) => e.slug === slug && e.locale === loc);
131
+ }
132
+
133
+ async allEntries(locale ) {
134
+ const loc = locale ?? (await this.site()).defaultLocale;
135
+ const all = await this.#store.listContentEntries(this.#siteId);
136
+ const { listed } = await this.#split(all, all);
137
+ return listed.filter((e) => e.locale === loc).sort(byNewest);
138
+ }
139
+
140
+ /** Every entry of a locale with a public URL, unlisted ones included (RFC-0042 §3). */
141
+ async routableEntries(locale ) {
142
+ const loc = locale ?? (await this.site()).defaultLocale;
143
+ const all = await this.#store.listContentEntries(this.#siteId);
144
+ const { reachable } = await this.#split(all, all);
145
+ return reachable.filter((e) => e.locale === loc).sort(byNewest);
146
+ }
147
+
148
+ /** RFC-0042 §4: a collection by its list fields (`queryEntries`). */
149
+ async queryEntries(q ) {
150
+ const site = await this.site();
151
+ const loc = q.locale ?? site.defaultLocale;
152
+ // With expiry rules every entry is read once (originals may sit elsewhere); else the collection.
153
+ const all = hasExpiryRules(site)
154
+ ? await this.#store.listContentEntries(this.#siteId)
155
+ : undefined;
156
+ const mine = all
157
+ ? all.filter((e) => e.collection === q.collection)
158
+ : await this.#store.listContentEntries(this.#siteId, q.collection);
159
+ const [split, taxonomies, terms] = await Promise.all([
160
+ this.#split(mine, all),
161
+ this.#store.listTaxonomies(this.#siteId),
162
+ this.#store.listTerms(this.#siteId),
163
+ ]);
164
+ const shownHere = q.includeExpired ? split.reachable : split.listed;
165
+ return evaluateEntryQuery({
166
+ site,
167
+ candidates: shownHere.filter((e) => e.locale === loc),
168
+ published: split.published,
169
+ taxonomies,
170
+ terms,
171
+ query: q,
172
+ now: this.#now(),
173
+ });
174
+ }
175
+
176
+ async search(query , options = {}) {
177
+ const site = await this.site();
178
+ const locale = options.locale ?? site.defaultLocale;
179
+ // What this source shows decided visibility and gates already (drafts included).
180
+ const [entries, pages, taxonomies, terms] = await Promise.all([
181
+ this.allEntries(locale),
182
+ this.pages(),
183
+ this.taxonomies(),
184
+ this.vocabulary(),
185
+ ]);
186
+ const rows = searchDocuments({
187
+ locales: [locale],
188
+ defaultLocale: site.defaultLocale,
189
+ site,
190
+ entries,
191
+ pages: pages.filter((p) => p.locale === locale),
192
+ taxonomies,
193
+ terms,
194
+ drafts: true,
195
+ }).map((r) => ({ ...r, gateFrom: undefined, gateUntil: undefined }));
196
+ return searchRows(rows, query, { ...options, locale, now: this.#now() });
197
+ }
198
+
199
+ async entryById(id ) {
200
+ const entry = await this.#store.getContentEntry(id);
201
+ if (!entry || entry.siteId !== this.#siteId) return undefined;
202
+ return (await this.#split([entry])).reachable.length > 0 ? entry : undefined;
203
+ }
204
+
205
+ entryFields(entry , options ) {
206
+ return entryFields(this, entry, options);
207
+ }
208
+
209
+ taxonomies() {
210
+ return this.#store.listTaxonomies(this.#siteId);
211
+ }
212
+
213
+ async terms(key ) {
214
+ const loc = (await this.site()).defaultLocale;
215
+ return (await this.#store.listTerms(this.#siteId, { taxonomy: key }))
216
+ .filter((t) => shown(t, this.#includeDrafts))
217
+ .sort(byPosition(loc));
218
+ }
219
+
220
+ async termBySlug(key , slug ) {
221
+ return (await this.terms(key)).find((t) => t.slug === slug);
222
+ }
223
+
224
+ vocabulary(key ) {
225
+ return this.#store.listTerms(this.#siteId, key === undefined ? {} : { taxonomy: key });
226
+ }
227
+
228
+ async entriesByFilter(
229
+ filter ,
230
+ options = {},
231
+ ) {
232
+ const loc = options.locale ?? (await this.site()).defaultLocale;
233
+ const [taxonomies, terms, entries] = await Promise.all([
234
+ this.#store.listTaxonomies(this.#siteId),
235
+ this.#store.listTerms(this.#siteId),
236
+ this.#store.listContentEntries(this.#siteId, { locale: loc }),
237
+ ]);
238
+ const f = compile(filter, taxonomies, terms);
239
+ const out = (await this.#split(entries)).listed.filter((e) => matches(f, e)).sort(byNewest);
240
+ return rememberList(options.limit === undefined ? out : out.slice(0, options.limit), {
241
+ source: this,
242
+ locale: loc,
243
+ });
244
+ }
245
+
246
+ entriesByTerm(
247
+ key ,
248
+ slug ,
249
+ options = {},
250
+ ) {
251
+ return this.entriesByFilter(termFilter(key, slug, options.descendants === true), options);
252
+ }
253
+
254
+ redirectFor(path , locale ) {
255
+ return this.#store.redirectFor(this.#siteId, path, locale);
256
+ }
257
+
258
+ redirects() {
259
+ return this.#store.listRedirects(this.#siteId);
260
+ }
261
+
262
+ menu(key ) {
263
+ return this.#store.getMenuByKey(this.#siteId, key);
264
+ }
265
+
266
+ async navigation(
267
+ key ,
268
+ locale ,
269
+ options = {},
270
+ ) {
271
+ const menu = await this.menu(key);
272
+ if (!menu) return undefined;
273
+ const site = await this.site();
274
+ const [pages, entries, taxonomies, terms] = await Promise.all([
275
+ this.#store.listPages(this.#siteId),
276
+ this.#store.listContentEntries(this.#siteId),
277
+ this.#store.listTaxonomies(this.#siteId),
278
+ this.#store.listTerms(this.#siteId),
279
+ ]);
280
+ return navigationFor(
281
+ menu,
282
+ {
283
+ site,
284
+ // drafts: everything but archived (the lookup decides); public: what is available now
285
+ pages: this.#includeDrafts ? pages : this.#visible(pages),
286
+ entries: this.#includeDrafts ? entries : (await this.#split(entries, entries)).reachable,
287
+ taxonomies,
288
+ terms,
289
+ includeDrafts: this.#includeDrafts,
290
+ ...(options.collectionIndex ? { collectionIndex: options.collectionIndex } : {}),
291
+ },
292
+ locale ?? site.defaultLocale,
293
+ );
294
+ }
295
+
296
+ async assets() {
297
+ const out = [];
298
+ let cursor ;
299
+ do {
300
+ const page = await this.#store.listAssets(this.#siteId, {
301
+ limit: 200,
302
+ ...(cursor ? { cursor } : {}),
303
+ });
304
+ out.push(...page.assets);
305
+ cursor = page.nextCursor;
306
+ } while (cursor);
307
+ return out;
308
+ }
309
+
310
+ async asset(id ) {
311
+ const a = await this.#store.getAsset(id);
312
+ return a?.siteId === this.#siteId ? a : undefined;
313
+ }
314
+
315
+ assetByPrefix(prefix16 ) {
316
+ return this.#store.getAssetByPrefix(this.#siteId, prefix16);
317
+ }
318
+ }
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { entryPath, termSlug } from "@cloudhal/core-ts";
11
11
  import { localeRouting, localeUrl, localizedPath } from "@cloudhal/core-ts/locale-paths";
12
+ import { routableEntries } from "./entry-views.js";
12
13
 
13
14
 
14
15
 
@@ -110,7 +111,7 @@ async function groupMembers(
110
111
  ) {
111
112
  const inGroup = (n ) => n.id === group || n.translation?.group === group;
112
113
  if (pages) return (await source.pages()).filter(inGroup);
113
- const all = await Promise.all(site.locales.map((l) => source.allEntries(l)));
114
+ const all = await Promise.all(site.locales.map((l) => routableEntries(source, l)));
114
115
  return all.flat().filter(inGroup);
115
116
  }
116
117
 
@@ -195,8 +196,8 @@ export async function linkLocalizer(
195
196
  const home = (p ) => (own ? localeUrl(site, def, p, origin) : localizedPath(site, def, p));
196
197
  const [pages, entries, translated, taxonomies, terms] = await Promise.all([
197
198
  source.pages(),
198
- source.allEntries(def),
199
- source.allEntries(locale),
199
+ routableEntries(source, def),
200
+ routableEntries(source, locale),
200
201
  source.taxonomies(),
201
202
  source.vocabulary(),
202
203
  ]);
@@ -8,7 +8,17 @@ export declare function previewCollections(sections: readonly Section[]): string
8
8
  * (`.ch-*` classes, `data-section-id`), so agents can preview a change without a build and the
9
9
  * markup matches what the site will render.
10
10
  */
11
- export declare function renderSectionHtml(section: Section, entries?: Record<string, ContentEntry[]>, media?: MediaContext): string;
11
+ /**
12
+ * What a preview needs to list a `contentList` section by field (RFC-0042 §4): the site (field
13
+ * definitions, list fields, time zone) and the instant `now` compares with (default: the clock).
14
+ */
15
+ export interface PreviewListing {
16
+ readonly site: Site;
17
+ readonly now?: number | undefined;
18
+ }
19
+ export declare function renderSectionHtml(section: Section, entries?: Record<string, ContentEntry[]>, media?: MediaContext,
20
+ /** RFC-0042: lets a `contentList` with `where`/`orderBy` list as the site does. */
21
+ listing?: PreviewListing): string;
12
22
  export interface PreviewDocument {
13
23
  html: string;
14
24
  title: string;
@@ -19,6 +29,11 @@ export interface PreviewDocument {
19
29
  * expired, RFC-0008 §7.3); empty when its gates are open.
20
30
  */
21
31
  export declare function gateNoticeHtml(site: Site, node: Pick<Page, "availability">, now: number, locale?: string): string;
32
+ /**
33
+ * The notice for an entry past its collection's expiry at `now` (RFC-0042 §3.3): "Ended on …"
34
+ * for `unlist`, "Expired on …" for `hide`; empty before it, or when its own gates already speak.
35
+ */
36
+ export declare function derivedGateNoticeHtml(site: Site, entry: ContentEntry, now: number, locale?: string): string;
22
37
  /**
23
38
  * Full HTML document for a page preview. `now` (default: the caller's clock) decides whether the
24
39
  * page's gates are closed, which adds a notice.
@@ -1,5 +1,6 @@
1
1
 
2
2
 
3
+
3
4
 
4
5
 
5
6
 
@@ -8,6 +9,7 @@
8
9
 
9
10
 
10
11
  import { entryPath } from "@cloudhal/core-ts";
12
+ import { derivedGate } from "@cloudhal/core-ts/fields";
11
13
  import {
12
14
 
13
15
 
@@ -17,7 +19,8 @@ import {
17
19
  viewPagePath,
18
20
  } from "./archive.js";
19
21
  import { renderComponentSection } from "./blocks.js";
20
- import { gateNotice } from "./gates.js";
22
+ import { evaluateEntryQuery, listsByField, sectionQuery } from "./entry-query.js";
23
+ import { formatGateTime, gateNotice } from "./gates.js";
21
24
  import { renderBody, renderEntryArticle, renderMarkdown, safeHref, safeSrc } from "./markdown.js";
22
25
  import { assetCaption, imageAttributes, imgHtml, } from "./media.js";
23
26
  import { archiveHead, siteOrigin } from "./seo.js";
@@ -82,10 +85,55 @@ export function previewCollections(sections ) {
82
85
  * (`.ch-*` classes, `data-section-id`), so agents can preview a change without a build and the
83
86
  * markup matches what the site will render.
84
87
  */
88
+ /**
89
+ * What a preview needs to list a `contentList` section by field (RFC-0042 §4): the site (field
90
+ * definitions, list fields, time zone) and the instant `now` compares with (default: the clock).
91
+ */
92
+
93
+
94
+
95
+
96
+
97
+ /**
98
+ * A `contentList` section's entries in a preview: with `where`/`orderBy` (and `listing`), through
99
+ * the live renderer's evaluator (`evaluateEntryQuery`); otherwise the collection by the section's
100
+ * `sort`. A term `filter` is applied on the site only; a preview ignores it.
101
+ */
102
+ function previewList(
103
+ section ,
104
+ entries ,
105
+ listing ,
106
+ ) {
107
+ const all = entries[section.collection] ?? [];
108
+ if (listing && listsByField(section)) {
109
+ const { filter: _ignored, ...query } = sectionQuery(section);
110
+ return evaluateEntryQuery({
111
+ site: listing.site,
112
+ candidates: all,
113
+ published: all,
114
+ taxonomies: [],
115
+ terms: [],
116
+ query,
117
+ now: listing.now ?? Date.now(),
118
+ }).entries;
119
+ }
120
+ return [...all]
121
+ .sort((a, b) =>
122
+ section.sort === "title"
123
+ ? a.title.localeCompare(b.title)
124
+ : section.sort === "oldest"
125
+ ? (a.publishedAt ?? a.createdAt).localeCompare(b.publishedAt ?? b.createdAt)
126
+ : (b.publishedAt ?? b.createdAt).localeCompare(a.publishedAt ?? a.createdAt),
127
+ )
128
+ .slice(0, section.limit);
129
+ }
130
+
85
131
  export function renderSectionHtml(
86
132
  section ,
87
133
  entries = {},
88
134
  media ,
135
+ /** RFC-0042: lets a `contentList` with `where`/`orderBy` list as the site does. */
136
+ listing ,
89
137
  ) {
90
138
  switch (section.kind) {
91
139
  case "hero":
@@ -114,15 +162,7 @@ export function renderSectionHtml(
114
162
  }</figure>`;
115
163
  }
116
164
  case "contentList": {
117
- const list = [...(entries[section.collection] ?? [])]
118
- .sort((a, b) =>
119
- section.sort === "title"
120
- ? a.title.localeCompare(b.title)
121
- : section.sort === "oldest"
122
- ? (a.publishedAt ?? a.createdAt).localeCompare(b.publishedAt ?? b.createdAt)
123
- : (b.publishedAt ?? b.createdAt).localeCompare(a.publishedAt ?? a.createdAt),
124
- )
125
- .slice(0, section.limit);
165
+ const list = previewList(section, entries, listing);
126
166
  const items = list
127
167
  .map(
128
168
  (e) =>
@@ -161,16 +201,25 @@ export function renderSectionHtml(
161
201
  /** Words of the preview's gate notice (RFC-0008 §7.3), as the blog starter says them. */
162
202
  const GATE_WORDS
163
203
 
164
-
204
+
205
+
206
+
207
+  
208
+
209
+
165
210
  = {
166
211
  en: {
167
212
  embargoed: (when) => `Embargoed until ${when}. Only previews show it until then.`,
168
213
  expired: (when) => `Expired on ${when}. Only previews show it now.`,
214
+ ended: (when) =>
215
+ `Ended on ${when} (collection rule). It keeps its address but is left out of lists, feeds and search.`,
169
216
  },
170
217
  tr: {
171
218
  embargoed: (when) =>
172
219
  `${when} tarihine kadar ambargolu. O zamana kadar yalnızca önizlemede görünür.`,
173
220
  expired: (when) => `${when} tarihinde yayından kalktı. Artık yalnızca önizlemede görünür.`,
221
+ ended: (when) =>
222
+ `${when} tarihinde sona erdi (koleksiyon kuralı). Adresi kalır, ama listelerde, akışlarda ve aramada yer almaz.`,
174
223
  },
175
224
  };
176
225
 
@@ -186,10 +235,36 @@ export function gateNoticeHtml(
186
235
  ) {
187
236
  const notice = gateNotice(node, site, locale, now);
188
237
  if (!notice) return "";
238
+ return noticeHtml(notice.state, notice.at, notice.when, locale);
239
+ }
240
+
241
+ function noticeHtml(
242
+ state ,
243
+ at ,
244
+ when ,
245
+ locale ,
246
+ ) {
189
247
  const words =
190
248
  GATE_WORDS[locale.split("-")[0] ?? locale] ??
191
249
  (GATE_WORDS.en );
192
- return `<p class="ch-gate-notice" role="status" data-gate="${notice.state}" data-gate-at="${esc(notice.at)}">${esc(words[notice.state](notice.when))}</p>`;
250
+ return `<p class="ch-gate-notice" role="status" data-gate="${state}" data-gate-at="${esc(at)}">${esc(words[state](when))}</p>`;
251
+ }
252
+
253
+ /**
254
+ * The notice for an entry past its collection's expiry at `now` (RFC-0042 §3.3): "Ended on …"
255
+ * for `unlist`, "Expired on …" for `hide`; empty before it, or when its own gates already speak.
256
+ */
257
+ export function derivedGateNoticeHtml(
258
+ site ,
259
+ entry ,
260
+ now ,
261
+ locale = site.defaultLocale,
262
+ ) {
263
+ const gate = derivedGate(site, entry);
264
+ if (!gate || now < gate.at) return "";
265
+ const at = new Date(gate.at).toISOString();
266
+ const state = gate.action === "hide" ? "expired" : "ended";
267
+ return noticeHtml(state, at, formatGateTime(at, site, locale), locale);
193
268
  }
194
269
 
195
270
  /**
@@ -206,7 +281,7 @@ export function renderPagePreview(
206
281
  const ctx = previewMedia(site, media);
207
282
  const body =
208
283
  gateNoticeHtml(site, page, now) +
209
- page.sections.map((s) => renderSectionHtml(s, entries, ctx)).join("\n");
284
+ page.sections.map((s) => renderSectionHtml(s, entries, ctx, { site, now })).join("\n");
210
285
  const title = page.seo?.title ?? page.title;
211
286
  return { title, path: page.path, html: document(site, title, page.seo?.description, body) };
212
287
  }
@@ -233,7 +308,7 @@ export function renderEntryPreview(
233
308
  now = Date.now(),
234
309
  ) {
235
310
  const body =
236
- gateNoticeHtml(site, entry, now) +
311
+ (gateNoticeHtml(site, entry, now) || derivedGateNoticeHtml(site, entry, now)) +
237
312
  renderEntryArticle(entry, site.defaultLocale, previewMedia(site, media));
238
313
  return {
239
314
  title: entry.title,
@@ -99,7 +99,7 @@ export declare function redirectPaths(redirects: readonly Redirect[], served: re
99
99
  export interface StaticPaths {
100
100
  /** For the catch-all page route: pages, entries, archive pages, then paths that redirect. */
101
101
  readonly pages: string[];
102
- /** For the term feed route (`<archive>/rss.xml`). */
102
+ /** For the term feed route (`<archive>/rss.xml`), then each collection's (`<prefix>/rss.xml`). */
103
103
  readonly feeds: string[];
104
104
  }
105
105
  /**