@nakedcreativity/cee-ms-node 2.0.0-beta.10 → 2.0.0-beta.3

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.
@@ -3,7 +3,6 @@ import type express from 'express';
3
3
  import type { Context, FilterImplOptions } from 'liquidjs';
4
4
  export declare enum CacheSource {
5
5
  Local = 0,
6
- /** The bucket, read with the host's own AWS credentials (`cacheBucket`, `cacheRegion`). */
7
6
  S3 = 1
8
7
  }
9
8
  export interface CeemsConfig {
@@ -19,11 +18,9 @@ export interface CeemsConfig {
19
18
  cacheRegion?: string;
20
19
  cacheFolder?: string;
21
20
  /**
22
- * The environment this renderer serves: published files are read from `<environment>/` in the bucket or
23
- * folder. Defaults to the `CEEMS_ENVIRONMENT` environment variable, then `development`.
21
+ * Where Cee.ms 2 publishes in the bucket or folder: `ceems/` by default, so it can publish to the same bucket
22
+ * as Cee.ms 1 (which writes `pages/` and `data/` at the top) while a site moves over. `''` reads from the top.
24
23
  */
25
- environment?: string;
26
- /** Where published files are read from in the bucket or folder: `<environment>/` unless set. */
27
24
  cachePrefix?: string;
28
25
  whitelistedCookies?: Array<string>;
29
26
  tags?: Array<LiquidTag>;
@@ -72,247 +69,13 @@ export interface CeemsSite {
72
69
  navigation: any;
73
70
  blogs: any;
74
71
  pages: any;
75
- site: CeemsSiteInfo;
72
+ site: any;
76
73
  /**
77
74
  * Site settings by field key (from Cee.ms 2), as published; drafts carry them as edited. Templates
78
75
  * read them as `settings`, e.g. `{{ settings.phone }}`. Stored links read as their address.
79
76
  */
80
77
  settings?: Record<string, any>;
81
78
  collections?: any;
82
- /**
83
- * Every published page by id (absent for sites last published before it): page links read their address from here when the page
84
- * renders, so a renamed or moved page is right everywhere once it is published. A link to a page that
85
- * isn't here is broken.
86
- */
87
- pageIndex?: Record<string, CeemsPageIndexEntry>;
88
- /** The documents published content uses, by id, read by document links and values as the page renders. */
89
- documents?: Record<string, CeemsPublishedDocument>;
90
- /** The site's People by row id, for bylines, profile pages and row fields. */
91
- people?: Record<string, CeemsPerson>;
92
- }
93
- /** A person from the site's People, in `site.json` `people`. Sites may add columns of their own. */
94
- export interface CeemsPerson {
95
- name: string;
96
- jobTitle?: string;
97
- photo?: CeemsImage;
98
- /** Rich text. */
99
- bio?: string;
100
- links?: {
101
- url: string;
102
- }[];
103
- /** `links` as addresses, for structured data. */
104
- sameAs: string[];
105
- email?: string;
106
- telephone?: string;
107
- /** Their profile page, if they have one. */
108
- profile?: {
109
- kind: 'page';
110
- pageId: string;
111
- url: string;
112
- };
113
- [column: string]: unknown;
114
- }
115
- /** A byline author, as published: a person from People, someone typed in, or the organisation. */
116
- export type CeemsBylineAuthor = {
117
- kind: 'person';
118
- collectionId: string;
119
- rowId: string;
120
- } | {
121
- kind: 'guest';
122
- name: string;
123
- url?: string;
124
- jobTitle?: string;
125
- } | {
126
- kind: 'organisation';
127
- };
128
- /** A published page, in `site.json` `pageIndex`. */
129
- export interface CeemsPageIndexEntry {
130
- /** Its address, e.g. `/about/team`, or `/` for the home page. */
131
- path: string;
132
- name: string;
133
- }
134
- export interface CeemsDocumentInfo {
135
- numpages?: number;
136
- dimensions?: {
137
- width: number;
138
- height: number;
139
- };
140
- }
141
- /** A library document, in `site.json` `documents`. */
142
- export interface CeemsPublishedDocument {
143
- url: string;
144
- thumbnail?: string;
145
- info?: CeemsDocumentInfo;
146
- }
147
- /** A published `data/<id>.json`. */
148
- export interface CeemsDataFile {
149
- _id: string;
150
- name: string;
151
- slug: string;
152
- columns: any[];
153
- /** Each row's values, in order: as Cee.ms 1 published them. */
154
- data: Record<string, any>[];
155
- /** The same rows with their ids, for row references. Absent for data last published before it. */
156
- rows?: ({
157
- _id: string;
158
- } & Record<string, any>)[];
159
- }
160
- /** The published `site.json` `site`. */
161
- export interface CeemsSiteInfo {
162
- name: string;
163
- cdn: string;
164
- url: string;
165
- /** The site's organisation, for templates (`{{ site.organisation.telephone }}`) and structured data. */
166
- organisation?: CeemsOrganisation;
167
- structuredData?: {
168
- defaults?: StructuredDataDefaults;
169
- /** For module types holding questions and answers: where they are, by module config type. */
170
- faqModules?: Record<string, FaqModuleMapping>;
171
- /** For module types holding reviews, which attach to a product or event page. */
172
- reviewModules?: Record<string, ReviewsModuleMapping>;
173
- /** For module types featuring people: their row field to People, by module config type. */
174
- peopleModules?: Record<string, {
175
- field: string;
176
- }>;
177
- };
178
- [key: string]: any;
179
- }
180
- /** A schema.org type a page or the site's defaults can switch on for `{% structureddata %}`. */
181
- export type StructuredDataType = 'WEBSITE' | 'WEBPAGE' | 'BREADCRUMB' | 'ORGANISATION' | 'ARTICLE' | 'FAQ';
182
- /**
183
- * What a page is about. Products, events, people and services output their own node when they have the data;
184
- * `HOME` is the site's front page, which by default carries the site and organisation. Templates and modules
185
- * can read it, e.g. `{% if page.entity == 'PRODUCT' %}`.
186
- */
187
- export type PageEntity = 'HOME' | 'PAGE' | 'ARTICLE' | 'PRODUCT' | 'EVENT' | 'PERSON' | 'SERVICE';
188
- /** The types each kind of page outputs unless it chooses its own. */
189
- export interface StructuredDataDefaults {
190
- home: StructuredDataType[];
191
- page: StructuredDataType[];
192
- blog: StructuredDataType[];
193
- article: StructuredDataType[];
194
- }
195
- /** `itemsField` is a contributor field of the module; the others are fields of its items. */
196
- export interface FaqModuleMapping {
197
- itemsField: string;
198
- questionField: string;
199
- answerField: string;
200
- }
201
- /** `itemsField` is a contributor field of the module; the others are fields of its items. */
202
- export interface ReviewsModuleMapping {
203
- itemsField: string;
204
- authorField: string;
205
- /** A select of numbers, or text holding one. */
206
- ratingField: string;
207
- bodyField?: string;
208
- dateField?: string;
209
- bestRating: number;
210
- worstRating: number;
211
- }
212
- /** An image value as published. */
213
- export interface CeemsImage {
214
- src: string;
215
- variants?: Record<string, string>;
216
- alt?: string;
217
- width?: number;
218
- height?: number;
219
- }
220
- export interface CeemsPostalAddress {
221
- street?: string;
222
- locality?: string;
223
- region?: string;
224
- postalCode?: string;
225
- country?: string;
226
- }
227
- export interface CeemsOrganisation {
228
- /** The schema.org type, from Cee.ms's business types: `Organization`, or one such as `RealEstateAgent`. */
229
- type: string;
230
- name: string;
231
- legalName?: string;
232
- logo?: CeemsImage;
233
- url?: string;
234
- email?: string;
235
- telephone?: string;
236
- address?: CeemsPostalAddress;
237
- /** Its profiles by platform, e.g. `{{ site.organisation.socialProfiles.instagram }}`. */
238
- socialProfiles?: CeemsSocialProfiles;
239
- /** Every profile URL in `socialProfiles`, as structured data lists them. */
240
- sameAs?: string[];
241
- openingHours?: {
242
- days: string[];
243
- opens: string;
244
- closes: string;
245
- }[];
246
- priceRange?: string;
247
- }
248
- /** Profile URLs on the platforms most sites link to, and any others by name. */
249
- export interface CeemsSocialProfiles {
250
- instagram?: string;
251
- facebook?: string;
252
- linkedin?: string;
253
- x?: string;
254
- youtube?: string;
255
- tiktok?: string;
256
- bluesky?: string;
257
- /** A `wa.me` link. */
258
- whatsapp?: string;
259
- custom: {
260
- name: string;
261
- url: string;
262
- }[];
263
- }
264
- export type CeemsAvailability = 'IN_STOCK' | 'OUT_OF_STOCK' | 'PRE_ORDER' | 'SOLD_OUT' | 'DISCONTINUED';
265
- export interface CeemsOffer {
266
- price: number;
267
- currency: string;
268
- url?: string;
269
- availability?: CeemsAvailability;
270
- }
271
- /** A page's structured data choices, and the details of its entity. */
272
- export interface CeemsPageStructuredData {
273
- /** Absent: the site's defaults for the page's kind. */
274
- types?: StructuredDataType[];
275
- event?: {
276
- name?: string;
277
- description?: string;
278
- startDate: string;
279
- endDate?: string;
280
- attendance?: 'OFFLINE' | 'ONLINE' | 'MIXED';
281
- status?: 'SCHEDULED' | 'CANCELLED' | 'POSTPONED' | 'RESCHEDULED' | 'MOVED_ONLINE';
282
- location?: {
283
- name?: string;
284
- address?: CeemsPostalAddress;
285
- url?: string;
286
- };
287
- image?: CeemsImage;
288
- offers?: CeemsOffer;
289
- };
290
- product?: {
291
- name?: string;
292
- description?: string;
293
- brand?: string;
294
- sku?: string;
295
- image?: CeemsImage;
296
- /** With `currency`; a product needs a price or reviews. */
297
- price?: number;
298
- currency?: string;
299
- availability?: CeemsAvailability;
300
- };
301
- person?: {
302
- name: string;
303
- jobTitle?: string;
304
- url?: string;
305
- image?: CeemsImage;
306
- sameAs?: string[];
307
- };
308
- service?: {
309
- name?: string;
310
- description?: string;
311
- serviceType?: string;
312
- areaServed?: string;
313
- image?: CeemsImage;
314
- offers?: CeemsOffer;
315
- };
316
79
  }
317
80
  export interface CeemsRequest extends express.Request {
318
81
  page: CeemsPage;
@@ -331,43 +94,11 @@ export interface CeemsPage {
331
94
  modules: Record<string, CeemsModule | string>;
332
95
  template: string;
333
96
  path: Array<string>;
334
- /** A stored link (read as its address), or a path on sites from before links; a published page redirects */
335
- redirect?: string | {
336
- url: string;
337
- toString(): string;
338
- } | null;
97
+ redirect: string;
339
98
  _id: string;
340
99
  pagination: number;
341
100
  fullpath: string;
342
101
  handle: string;
343
- /** The page's own name, for menus. */
344
- name?: string;
345
- /** SEO title. */
346
- title?: string;
347
- /** SEO description. */
348
- description?: string;
349
- /** Social sharing image. */
350
- social?: CeemsImage;
351
- type?: 'blog' | 'article';
352
- /** Published from Cee.ms with the default resolved: `HOME` for the home page, else `PAGE`. */
353
- entity?: PageEntity;
354
- /** The site's own page type, such as `property`, by key. Its `entity` is the type's base. */
355
- pageType?: string;
356
- tags?: string[];
357
- /** An article's date. */
358
- date?: string;
359
- publishedAt?: string;
360
- updatedAt?: string;
361
- structuredData?: CeemsPageStructuredData;
362
- /** An article's byline, as published. Templates read `page.authors`. */
363
- byline?: {
364
- authors: CeemsBylineAuthor[];
365
- reviewedBy?: unknown;
366
- };
367
- /** For entity `PERSON`: the person whose profile page it is, as a `RowDrop` once loaded. */
368
- person?: unknown;
369
- /** The byline, resolved (see `bylineAuthors`): people, guests and the organisation, in order. */
370
- authors?: Record<string, unknown>[];
371
102
  [key: string]: any;
372
103
  }
373
104
  export interface CeemsRegion {
package/lib/interfaces.js CHANGED
@@ -4,7 +4,6 @@ exports.CacheSource = void 0;
4
4
  var CacheSource;
5
5
  (function (CacheSource) {
6
6
  CacheSource[CacheSource["Local"] = 0] = "Local";
7
- /** The bucket, read with the host's own AWS credentials (`cacheBucket`, `cacheRegion`). */
8
7
  CacheSource[CacheSource["S3"] = 1] = "S3";
9
8
  })(CacheSource || (exports.CacheSource = CacheSource = {}));
10
9
  //# sourceMappingURL=interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AAIA,IAAY,WAIX;AAJD,WAAY,WAAW;IACnB,+CAAK,CAAA;IACL,2FAA2F;IAC3F,yCAAE,CAAA;AACN,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB"}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AAIA,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,+CAAK,CAAA;IACL,yCAAE,CAAA;AACN,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB"}
package/lib/links.d.ts CHANGED
@@ -1,24 +1,9 @@
1
1
  import { Drop } from 'liquidjs';
2
- import type { CeemsDataFile, CeemsDocumentInfo, CeemsPageIndexEntry, CeemsPublishedDocument, CeemsSite } from './interfaces';
3
- /**
4
- * What references resolve against when a page renders: the published pages and documents from `site.json`,
5
- * and the rows of the data collections the page points at. Each is published once, so a renamed page or an
6
- * edited row is right everywhere as soon as that one change is published. A site published before Cee.ms
7
- * sent these has none of them, and links read their stored address as before.
8
- */
9
- export interface LinkContext {
10
- pageIndex?: Record<string, CeemsPageIndexEntry>;
11
- documents?: Record<string, CeemsPublishedDocument>;
12
- /** A row by collection and row id, or undefined if it isn't published (or was deleted). */
13
- row?: (collectionId: string, rowId: string) => Record<string, unknown> | undefined;
14
- }
15
2
  /**
16
3
  * A stored link value in templates. It reads as its address, so a field that held a URL string and became a
17
4
  * link field still works where templates print it (`{{ item.url }}`), filter it (`| escape`, `| append`),
18
5
  * compare it (`== '/about'`, `!= blank`) or measure it (`| size`); and its parts are there too
19
6
  * (`{{ item.url.kind }}`, `.pageId`, `.anchor`). `| json` shows the whole link.
20
- *
21
- * A page link whose page isn't published reads as `''`, with `broken` true, so `{% if link %}` leaves it out.
22
7
  */
23
8
  export declare class LinkDrop extends Drop {
24
9
  kind: string;
@@ -27,7 +12,6 @@ export declare class LinkDrop extends Drop {
27
12
  documentId?: string;
28
13
  anchor?: string;
29
14
  email?: string;
30
- broken?: boolean;
31
15
  constructor(link: Record<string, unknown>);
32
16
  valueOf(): string;
33
17
  toString(): string;
@@ -37,54 +21,5 @@ export declare class LinkDrop extends Drop {
37
21
  get size(): number;
38
22
  toJSON(): Record<string, unknown>;
39
23
  }
40
- /**
41
- * A document value (`{ documentId, url, thumbnail, info }`) in templates, read from the published documents
42
- * so a replaced file is right everywhere. It prints as its address, so `{{ download }}` and
43
- * `{{ download.url }}` both work.
44
- */
45
- export declare class DocumentDrop extends Drop {
46
- documentId?: string;
47
- url: string;
48
- thumbnail?: string;
49
- info?: CeemsDocumentInfo;
50
- constructor(value: Record<string, unknown>);
51
- valueOf(): string;
52
- toString(): string;
53
- toJSON(): Record<string, unknown>;
54
- }
55
- /**
56
- * A row of a data collection, from a `row` field: its columns by key (`{{ author.name }}`,
57
- * `{% image person.photo 'square' %}`), plus `_id`. It prints as its `name`, else its first text value.
58
- */
59
- export declare class RowDrop extends Drop {
60
- _id: string;
61
- [column: string]: unknown;
62
- constructor(row: Record<string, unknown>);
63
- toString(): string;
64
- valueOf(): string;
65
- toJSON(): Record<string, unknown>;
66
- }
67
- /**
68
- * Rich text links carry the page they point at (`data-page-id`); their `href` comes from the published page,
69
- * keeping any `#anchor`, and is dropped when that page isn't published. Documents' come from `documents`.
70
- */
71
- export declare function resolveRichText(html: string, context: LinkContext): string;
72
- /**
73
- * Wraps every stored link in a published page, data file or draft in a `LinkDrop`, every document value in a
74
- * `DocumentDrop` and every row reference in a `RowDrop`, in place, resolving each against `context`. A row
75
- * that isn't published reads as nothing, and is left out of lists.
76
- */
77
- export declare function wrapLinks<T>(value: T, context?: LinkContext, depth?: number): T;
78
- /** The rows a page's row references and byline authors point at, by collection id. */
79
- export declare function referencedRows(value: unknown, found?: Map<string, Set<string>>): Map<string, Set<string>>;
80
- /**
81
- * The context for a site and the data files its page points at. People come from `site.json` `people` (with
82
- * `sameAs`), so a person reads the same wherever they are referenced.
83
- */
84
- export declare function linkContextFor(site: CeemsSite | undefined, files?: Iterable<CeemsDataFile | null>): LinkContext;
85
- /**
86
- * An article's byline as templates and structured data read it, in order: `page.authors`. A person is their
87
- * People row (`{{ author.name }}`, `{{ author.profile }}`); a guest is what was typed; the organisation is the
88
- * site's. Each has `kind`, `name` and `url` (a person's profile page, else their first profile link).
89
- */
90
- export declare function bylineAuthors(page: Record<string, any>, site: CeemsSite | undefined, context: LinkContext): Record<string, unknown>[];
24
+ /** Wraps every stored link in a published page, data file or draft in a `LinkDrop`, in place. */
25
+ export declare function wrapLinks<T>(value: T): T;
package/lib/links.js CHANGED
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RowDrop = exports.DocumentDrop = exports.LinkDrop = void 0;
4
- exports.resolveRichText = resolveRichText;
3
+ exports.LinkDrop = void 0;
5
4
  exports.wrapLinks = wrapLinks;
6
- exports.referencedRows = referencedRows;
7
- exports.linkContextFor = linkContextFor;
8
- exports.bylineAuthors = bylineAuthors;
9
5
  const liquidjs_1 = require("liquidjs");
10
6
  /** The kinds of link Cee.ms stores: `{ kind, url, pageId?, documentId?, anchor?, email? }`. */
11
7
  const LINK_KINDS = ['url', 'page', 'document', 'anchor', 'email'];
@@ -14,8 +10,6 @@ const LINK_KINDS = ['url', 'page', 'document', 'anchor', 'email'];
14
10
  * link field still works where templates print it (`{{ item.url }}`), filter it (`| escape`, `| append`),
15
11
  * compare it (`== '/about'`, `!= blank`) or measure it (`| size`); and its parts are there too
16
12
  * (`{{ item.url.kind }}`, `.pageId`, `.anchor`). `| json` shows the whole link.
17
- *
18
- * A page link whose page isn't published reads as `''`, with `broken` true, so `{% if link %}` leaves it out.
19
13
  */
20
14
  class LinkDrop extends liquidjs_1.Drop {
21
15
  kind;
@@ -24,7 +18,6 @@ class LinkDrop extends liquidjs_1.Drop {
24
18
  documentId;
25
19
  anchor;
26
20
  email;
27
- broken;
28
21
  constructor(link) {
29
22
  super();
30
23
  Object.assign(this, link);
@@ -48,208 +41,21 @@ class LinkDrop extends liquidjs_1.Drop {
48
41
  }
49
42
  }
50
43
  exports.LinkDrop = LinkDrop;
51
- /**
52
- * A document value (`{ documentId, url, thumbnail, info }`) in templates, read from the published documents
53
- * so a replaced file is right everywhere. It prints as its address, so `{{ download }}` and
54
- * `{{ download.url }}` both work.
55
- */
56
- class DocumentDrop extends liquidjs_1.Drop {
57
- documentId;
58
- url;
59
- thumbnail;
60
- info;
61
- constructor(value) {
62
- super();
63
- Object.assign(this, value);
64
- }
65
- valueOf() {
66
- return this.url;
67
- }
68
- toString() {
69
- return this.url;
70
- }
71
- toJSON() {
72
- return { ...this };
73
- }
74
- }
75
- exports.DocumentDrop = DocumentDrop;
76
- /**
77
- * A row of a data collection, from a `row` field: its columns by key (`{{ author.name }}`,
78
- * `{% image person.photo 'square' %}`), plus `_id`. It prints as its `name`, else its first text value.
79
- */
80
- class RowDrop extends liquidjs_1.Drop {
81
- _id;
82
- constructor(row) {
83
- super();
84
- Object.assign(this, row);
85
- }
86
- toString() {
87
- if (typeof this.name === 'string')
88
- return this.name;
89
- const first = Object.entries(this).find(([key, v]) => key !== '_id' && typeof v === 'string');
90
- return first ? String(first[1]) : '';
91
- }
92
- valueOf() {
93
- return this.toString();
94
- }
95
- toJSON() {
96
- return { ...this };
97
- }
98
- }
99
- exports.RowDrop = RowDrop;
100
44
  const isLink = (value) => typeof value.kind === 'string' && LINK_KINDS.includes(value.kind) && typeof value.url === 'string';
101
- const isRowRef = (value) => value.kind === 'row' && value.rowId !== undefined && value.collectionId !== undefined;
102
- const isDocumentValue = (value) => value.documentId !== undefined && typeof value.url === 'string' && value.kind === undefined;
103
- const RICH_LINK = /<a\b([^>]*)>/gi;
104
- /**
105
- * Rich text links carry the page they point at (`data-page-id`); their `href` comes from the published page,
106
- * keeping any `#anchor`, and is dropped when that page isn't published. Documents' come from `documents`.
107
- */
108
- function resolveRichText(html, context) {
109
- if (!context.pageIndex && !context.documents)
110
- return html;
111
- return html.replace(RICH_LINK, (tag, attrs) => {
112
- const pageId = /\bdata-page-id="([0-9a-f]{24})"/i.exec(attrs)?.[1];
113
- const documentId = /\bdata-document-id="([0-9a-f]{24})"/i.exec(attrs)?.[1];
114
- let href;
115
- if (pageId && context.pageIndex) {
116
- const anchor = /\bhref="[^"#]*#([^"]*)"/i.exec(attrs)?.[1];
117
- const entry = context.pageIndex[pageId];
118
- href = entry ? entry.path + (anchor ? `#${anchor}` : '') : null;
119
- }
120
- else if (documentId && context.documents) {
121
- href = context.documents[documentId]?.url;
122
- }
123
- if (href === undefined)
124
- return tag;
125
- if (href === null)
126
- return tag.replace(/\s*\bhref="[^"]*"/i, '');
127
- const value = `href="${href.replace(/&/g, '&amp;').replace(/"/g, '&quot;')}"`;
128
- return /\bhref="[^"]*"/i.test(attrs) ? tag.replace(/\bhref="[^"]*"/i, value) : `<a ${value}${attrs}>`;
129
- });
130
- }
131
- function linkDrop(record, context) {
132
- if (record.kind === 'page' && record.pageId && context.pageIndex) {
133
- const entry = context.pageIndex[String(record.pageId)];
134
- const anchor = record.anchor ? `#${record.anchor}` : '';
135
- return new LinkDrop(entry ? { ...record, url: entry.path + anchor, broken: false } : { ...record, url: '', broken: true });
136
- }
137
- if (record.kind === 'document' && record.documentId && context.documents) {
138
- const document = context.documents[String(record.documentId)];
139
- if (document)
140
- return new LinkDrop({ ...record, url: document.url });
141
- }
142
- return new LinkDrop(record);
143
- }
144
- /** Rows inside rows resolve this deep, so rows that point at each other can't loop. */
145
- const ROW_DEPTH = 2;
146
- /**
147
- * Wraps every stored link in a published page, data file or draft in a `LinkDrop`, every document value in a
148
- * `DocumentDrop` and every row reference in a `RowDrop`, in place, resolving each against `context`. A row
149
- * that isn't published reads as nothing, and is left out of lists.
150
- */
151
- function wrapLinks(value, context = {}, depth = 0) {
45
+ /** Wraps every stored link in a published page, data file or draft in a `LinkDrop`, in place. */
46
+ function wrapLinks(value) {
152
47
  if (Array.isArray(value)) {
153
- const wrapped = value.map((item) => wrapLinks(item, context, depth));
154
- // a list of rows skips the ones that are gone
155
- const kept = wrapped.filter((item, i) => item !== undefined || !isRowLike(value[i]));
156
- value.splice(0, value.length, ...kept);
48
+ for (let i = 0; i < value.length; i++)
49
+ value[i] = wrapLinks(value[i]);
157
50
  return value;
158
51
  }
159
- if (typeof value === 'string')
160
- return (value.includes('<a') ? resolveRichText(value, context) : value);
161
52
  if (!value || typeof value !== 'object' || value instanceof liquidjs_1.Drop)
162
53
  return value;
163
54
  const record = value;
164
55
  if (isLink(record))
165
- return linkDrop(record, context);
166
- if (isRowRef(record)) {
167
- if (!context.row || depth >= ROW_DEPTH)
168
- return (context.row ? undefined : value);
169
- const row = context.row(String(record.collectionId), String(record.rowId));
170
- // a copy: rows come from data files cached across renders
171
- return (row ? new RowDrop(wrapLinks(structuredClone(row), context, depth + 1)) : undefined);
172
- }
173
- if (isDocumentValue(record) && context.documents) {
174
- const document = context.documents[String(record.documentId)];
175
- return new DocumentDrop(document ? { ...record, ...document } : record);
176
- }
56
+ return new LinkDrop(record);
177
57
  for (const key of Object.keys(record))
178
- record[key] = wrapLinks(record[key], context, depth);
58
+ record[key] = wrapLinks(record[key]);
179
59
  return value;
180
60
  }
181
- const isRowLike = (value) => !!value && typeof value === 'object' && isRowRef(value);
182
- /** The rows a page's row references and byline authors point at, by collection id. */
183
- function referencedRows(value, found = new Map()) {
184
- if (Array.isArray(value)) {
185
- for (const item of value)
186
- referencedRows(item, found);
187
- }
188
- else if (value && typeof value === 'object' && !(value instanceof liquidjs_1.Drop)) {
189
- const record = value;
190
- if (isRowRef(record) || (record.kind === 'person' && record.rowId !== undefined)) {
191
- const collection = String(record.collectionId);
192
- found.set(collection, (found.get(collection) ?? new Set()).add(String(record.rowId)));
193
- }
194
- else
195
- for (const child of Object.values(record))
196
- referencedRows(child, found);
197
- }
198
- return found;
199
- }
200
- /**
201
- * The context for a site and the data files its page points at. People come from `site.json` `people` (with
202
- * `sameAs`), so a person reads the same wherever they are referenced.
203
- */
204
- function linkContextFor(site, files = []) {
205
- const rows = new Map();
206
- for (const file of files) {
207
- if (!file?.rows)
208
- continue;
209
- rows.set(String(file._id), new Map(file.rows.map((row) => [String(row._id), row])));
210
- }
211
- return {
212
- pageIndex: site?.pageIndex,
213
- documents: site?.documents,
214
- row: (collectionId, rowId) => {
215
- const person = site?.people?.[rowId];
216
- return person ? { _id: rowId, ...person } : rows.get(collectionId)?.get(rowId);
217
- },
218
- };
219
- }
220
- /**
221
- * An article's byline as templates and structured data read it, in order: `page.authors`. A person is their
222
- * People row (`{{ author.name }}`, `{{ author.profile }}`); a guest is what was typed; the organisation is the
223
- * site's. Each has `kind`, `name` and `url` (a person's profile page, else their first profile link).
224
- */
225
- function bylineAuthors(page, site, context) {
226
- const authors = [];
227
- for (const author of page.byline?.authors ?? []) {
228
- if (author?.kind === 'person') {
229
- const row = context.row?.(String(author.collectionId), String(author.rowId));
230
- if (!row)
231
- continue;
232
- const person = new RowDrop(wrapLinks(structuredClone(row), context, 1));
233
- const profile = person.profile;
234
- const sameAs = Array.isArray(person.sameAs) ? person.sameAs : [];
235
- person.kind = 'person';
236
- person.url = profile && String(profile) ? String(profile) : sameAs[0];
237
- authors.push(person);
238
- }
239
- else if (author?.kind === 'guest') {
240
- authors.push({ kind: 'guest', name: author.name, url: author.url, jobTitle: author.jobTitle });
241
- }
242
- else if (author?.kind === 'organisation') {
243
- const org = site?.site?.organisation;
244
- if (org?.name)
245
- authors.push({
246
- kind: 'organisation',
247
- name: org.name,
248
- url: org.url || site?.site?.url,
249
- photo: org.logo,
250
- });
251
- }
252
- }
253
- return authors;
254
- }
255
61
  //# sourceMappingURL=links.js.map