@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.
- package/README.md +40 -1
- 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/components/EntryFields.astro +43 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.js +1 -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/fields.d.ts +77 -0
- package/dist/src/fields.js +201 -0
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.js +10 -1
- 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-helpers.d.ts +11 -0
- package/dist/src/source-helpers.js +48 -0
- package/dist/src/source.d.ts +40 -45
- package/dist/src/source.js +104 -283
- 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/routing.js
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
parseArchivePath,
|
|
19
19
|
termForSlug,
|
|
20
20
|
} from "./archive.js";
|
|
21
|
+
import { collectionFeedPaths } from "./collection-feeds.js";
|
|
22
|
+
import { routableEntries } from "./entry-views.js";
|
|
21
23
|
import { PREVIEW_PARAM } from "./resolver.js";
|
|
22
24
|
import { searchRequest } from "./search.js";
|
|
23
25
|
|
|
@@ -71,7 +73,8 @@ export async function routablePaths(source , locale )
|
|
|
71
73
|
const loc = locale ?? site.defaultLocale;
|
|
72
74
|
const pagePaths = pages.filter((p) => p.locale === loc).map((p) => p.path);
|
|
73
75
|
const taken = new Set(pagePaths);
|
|
74
|
-
|
|
76
|
+
// RFC-0042 §3: an unlisted entry keeps its URL (static builds write it), only lists drop it.
|
|
77
|
+
const entryPaths = (await routableEntries(source, loc))
|
|
75
78
|
.map((e) => entryPath(site, e))
|
|
76
79
|
.filter((p) => !taken.has(p));
|
|
77
80
|
return [...pagePaths, ...entryPaths];
|
|
@@ -259,7 +262,7 @@ export function redirectPaths(redirects , served
|
|
|
259
262
|
|
|
260
263
|
|
|
261
264
|
|
|
262
|
-
|
|
265
|
+
|
|
263
266
|
|
|
264
267
|
|
|
265
268
|
|
|
@@ -291,7 +294,14 @@ export async function staticPaths(
|
|
|
291
294
|
)
|
|
292
295
|
.filter((p) => !taken.has(p));
|
|
293
296
|
const served = [...base, ...archivePages];
|
|
294
|
-
|
|
297
|
+
// RFC-0042 §5: each collection's feed too (the starter's feed route answers 404 for it, and the
|
|
298
|
+
// renderer's middleware answers with the feed), so old theme copies write it as well.
|
|
299
|
+
const feeds = [
|
|
300
|
+
...new Set([
|
|
301
|
+
...archives.flatMap((a) => (a.feedPath ? [a.feedPath] : [])),
|
|
302
|
+
...collectionFeedPaths(site, entries),
|
|
303
|
+
]),
|
|
304
|
+
];
|
|
295
305
|
// `…/page/1` answers with a 301 to the archive root (a meta-refresh page in static builds).
|
|
296
306
|
const firstPages = archives.map((a) => `${a.path}/page/1`);
|
|
297
307
|
return {
|
package/dist/src/seo.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ import type { ContentEntry, ImageRef, Page, Site } from "@cloudhal/core-contract
|
|
|
7
7
|
import type { ArchiveView } from "./archive.js";
|
|
8
8
|
import { type MediaContext } from "./media.js";
|
|
9
9
|
import { type EntryTaxonomy, type ShownTerm } from "./taxonomy.js";
|
|
10
|
+
/** RFC-0042 §5: the `<link rel="alternate">` of a collection's feed. */
|
|
11
|
+
export { collectionFeedLink, type FeedLink } from "./collection-feeds.js";
|
|
12
|
+
/** RFC-0042 §2: a collection's JSON-LD preset in place of the generic `BlogPosting`. */
|
|
13
|
+
export { entryStructuredData, type StructuredDataOptions, withStructuredData, } from "./structured-data.js";
|
|
10
14
|
export interface HeadMeta {
|
|
11
15
|
/** `<title>`. */
|
|
12
16
|
title: string;
|
|
@@ -82,4 +86,3 @@ export declare function archiveHead(site: Site, view: ArchiveView, origin: strin
|
|
|
82
86
|
* (English for languages without them).
|
|
83
87
|
*/
|
|
84
88
|
export declare function searchHead(site: Site, query: string, origin: string, locale?: string): HeadMeta;
|
|
85
|
-
export {};
|
package/dist/src/seo.js
CHANGED
|
@@ -10,6 +10,15 @@ import { inlineMarkdownText, markdownText, safeSrc } from "./markdown.js";
|
|
|
10
10
|
import { assetAlt, imageObject, socialImageUrl } from "./media.js";
|
|
11
11
|
import { entryTaxonomy, } from "./taxonomy.js";
|
|
12
12
|
|
|
13
|
+
/** RFC-0042 §5: the `<link rel="alternate">` of a collection's feed. */
|
|
14
|
+
export { collectionFeedLink, } from "./collection-feeds.js";
|
|
15
|
+
/** RFC-0042 §2: a collection's JSON-LD preset in place of the generic `BlogPosting`. */
|
|
16
|
+
export {
|
|
17
|
+
entryStructuredData,
|
|
18
|
+
|
|
19
|
+
withStructuredData,
|
|
20
|
+
} from "./structured-data.js";
|
|
21
|
+
|
|
13
22
|
|
|
14
23
|
|
|
15
24
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Small pure helpers of `source.ts`: ordering, visibility and filter compilation. */
|
|
2
|
+
import type { ContentEntry, Page, Taxonomy, Term } from "@cloudhal/core-contracts";
|
|
3
|
+
export declare function byNewest(a: ContentEntry, b: ContentEntry): number;
|
|
4
|
+
export declare function byPosition(locale: string): (a: Term, b: Term) => number;
|
|
5
|
+
export declare function shown(term: Term, includeDrafts: boolean): boolean;
|
|
6
|
+
export declare function termFilter(key: string, slug: string, descendants: boolean): string;
|
|
7
|
+
/** Resolves a filter against a vocabulary; unknown terms match nothing and are logged. */
|
|
8
|
+
export declare function compile(filter: string, taxonomies: Taxonomy[], terms: Term[]): import("@cloudhal/core-ts").ResolvedFilter;
|
|
9
|
+
export declare function visible<T extends {
|
|
10
|
+
status: Page["status"];
|
|
11
|
+
}>(nodes: T[], includeDrafts: boolean): T[];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Small pure helpers of `source.ts`: ordering, visibility and filter compilation. */
|
|
2
|
+
|
|
3
|
+
import { termName } from "@cloudhal/core-ts";
|
|
4
|
+
import { parseFilter, resolveFilter } from "@cloudhal/core-ts/filter";
|
|
5
|
+
|
|
6
|
+
export function byNewest(a , b ) {
|
|
7
|
+
return (b.publishedAt ?? b.createdAt).localeCompare(a.publishedAt ?? a.createdAt);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function byPosition(locale ) {
|
|
11
|
+
return (a , b ) =>
|
|
12
|
+
(a.position ?? Number.MAX_SAFE_INTEGER) - (b.position ?? Number.MAX_SAFE_INTEGER) ||
|
|
13
|
+
termName(a, locale).localeCompare(termName(b, locale)) ||
|
|
14
|
+
a.slug.localeCompare(b.slug);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function shown(term , includeDrafts ) {
|
|
18
|
+
return includeDrafts
|
|
19
|
+
? term.status !== "retired"
|
|
20
|
+
: term.status === "active" && term.visibility === "public";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function termFilter(key , slug , descendants ) {
|
|
24
|
+
return `${key}:${slug}${descendants ? ">*" : ""}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Resolves a filter against a vocabulary; unknown terms match nothing and are logged. */
|
|
28
|
+
export function compile(filter , taxonomies , terms ) {
|
|
29
|
+
const resolved = resolveFilter(
|
|
30
|
+
parseFilter(filter),
|
|
31
|
+
{ taxonomies, terms },
|
|
32
|
+
{ unknown: "match-nothing" },
|
|
33
|
+
);
|
|
34
|
+
if (resolved.unknown.length > 0)
|
|
35
|
+
console.warn(
|
|
36
|
+
`cloudhal: filter "${filter}" names unknown terms: ${resolved.unknown.join(", ")}`,
|
|
37
|
+
);
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function visible (
|
|
42
|
+
nodes ,
|
|
43
|
+
includeDrafts ,
|
|
44
|
+
) {
|
|
45
|
+
return includeDrafts
|
|
46
|
+
? nodes.filter((n) => n.status !== "archived")
|
|
47
|
+
: nodes.filter((n) => n.status === "published");
|
|
48
|
+
}
|
package/dist/src/source.d.ts
CHANGED
|
@@ -1,6 +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";
|
|
5
|
+
import { type EntryFieldsOptions, type RenderedFields } from "./fields.js";
|
|
3
6
|
import { type Navigation, type NavigationOptions } from "./navigation.js";
|
|
7
|
+
export { LiveSource } from "./live-source.js";
|
|
4
8
|
/**
|
|
5
9
|
* What a renderer needs from a site, independent of whether it reads live nodes (dev) or a
|
|
6
10
|
* published snapshot (build/production).
|
|
@@ -10,10 +14,22 @@ export interface GraphSource {
|
|
|
10
14
|
site(): Promise<Site>;
|
|
11
15
|
pages(): Promise<Page[]>;
|
|
12
16
|
pageByPath(path: string, locale?: string): Promise<Page | undefined>;
|
|
17
|
+
/** Listed entries of a collection, newest first (RFC-0042: unlisted ones left out). */
|
|
13
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. */
|
|
14
20
|
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
15
|
-
/** Every
|
|
21
|
+
/** Every listed entry of a locale, newest first, across collections (feeds, sitemaps). */
|
|
16
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>;
|
|
17
33
|
/**
|
|
18
34
|
* A visible entry by id, any locale (reader comments name the entry by id, RFC-0007 §6.2).
|
|
19
35
|
* Optional for sources that predate comments.
|
|
@@ -80,6 +96,14 @@ export interface GraphSource {
|
|
|
80
96
|
* entries it shows, drafts included. Optional for sources that predate search.
|
|
81
97
|
*/
|
|
82
98
|
search?(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
99
|
+
/**
|
|
100
|
+
* RFC-0041 §9: an entry's typed fields as a theme draws them: resolved (a translation reads the
|
|
101
|
+
* original's values where §5 says so), labelled in `options.locale` (default: the entry's), rich
|
|
102
|
+
* text as sanitized HTML, URLs through `safeHref`, images as `<img>` attributes. `{}` when the
|
|
103
|
+
* collection has no definitions. Optional for sources that predate fields; any source works
|
|
104
|
+
* with the standalone `entryFields(source, entry)`.
|
|
105
|
+
*/
|
|
106
|
+
entryFields?(entry: ContentEntry, options?: EntryFieldsOptions): Promise<RenderedFields>;
|
|
83
107
|
}
|
|
84
108
|
export interface SourceSearchOptions {
|
|
85
109
|
page?: number;
|
|
@@ -89,54 +113,20 @@ export interface SourceSearchOptions {
|
|
|
89
113
|
/** RFC-0029: only these kinds (default: all). */
|
|
90
114
|
kinds?: readonly SearchKind[];
|
|
91
115
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Reads the current nodes on every call. Drafts are included so authors can preview them in dev,
|
|
94
|
-
* and so are gated nodes (a preview shows embargoed and expired content, RFC-0008 §7.3). Without
|
|
95
|
-
* drafts it serves what the public would see: published nodes whose gates are open at `now`.
|
|
96
|
-
*/
|
|
97
|
-
export declare class LiveSource implements GraphSource {
|
|
98
|
-
#private;
|
|
99
|
-
readonly mode = "live";
|
|
100
|
-
constructor(store: SiteGraphStore, siteId: string, options?: {
|
|
101
|
-
includeDrafts?: boolean;
|
|
102
|
-
now?: () => number;
|
|
103
|
-
});
|
|
104
|
-
nextGate(): Promise<number | undefined>;
|
|
105
|
-
site(): Promise<Site>;
|
|
106
|
-
pages(): Promise<Page[]>;
|
|
107
|
-
pageByPath(path: string, locale?: string): Promise<Page | undefined>;
|
|
108
|
-
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
109
|
-
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
110
|
-
allEntries(locale?: string): Promise<ContentEntry[]>;
|
|
111
|
-
search(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
112
|
-
entryById(id: string): Promise<ContentEntry | undefined>;
|
|
113
|
-
taxonomies(): Promise<Taxonomy[]>;
|
|
114
|
-
terms(key: string): Promise<Term[]>;
|
|
115
|
-
termBySlug(key: string, slug: string): Promise<Term | undefined>;
|
|
116
|
-
vocabulary(key?: string): Promise<Term[]>;
|
|
117
|
-
entriesByFilter(filter: string, options?: {
|
|
118
|
-
locale?: string;
|
|
119
|
-
limit?: number;
|
|
120
|
-
}): Promise<ContentEntry[]>;
|
|
121
|
-
entriesByTerm(key: string, slug: string, options?: {
|
|
122
|
-
locale?: string;
|
|
123
|
-
limit?: number;
|
|
124
|
-
descendants?: boolean;
|
|
125
|
-
}): Promise<ContentEntry[]>;
|
|
126
|
-
redirectFor(path: string, locale?: string): Promise<RedirectMatch | undefined>;
|
|
127
|
-
redirects(): Promise<Redirect[]>;
|
|
128
|
-
menu(key: string): Promise<Menu | undefined>;
|
|
129
|
-
navigation(key: string, locale?: string, options?: NavigationOptions): Promise<Navigation | undefined>;
|
|
130
|
-
assets(): Promise<Asset[]>;
|
|
131
|
-
asset(id: string): Promise<Asset | undefined>;
|
|
132
|
-
assetByPrefix(prefix16: string): Promise<Asset | undefined>;
|
|
133
|
-
}
|
|
134
116
|
/** Everything a snapshot shows before gates are applied; built once per snapshot and isolate. */
|
|
135
117
|
interface Loaded {
|
|
136
118
|
site: Site;
|
|
137
119
|
/** Published pages in `Site.pageIds` order and published entries, gates not yet applied. */
|
|
138
120
|
pages: Page[];
|
|
139
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>;
|
|
140
130
|
taxonomies: Taxonomy[];
|
|
141
131
|
terms: Term[];
|
|
142
132
|
redirects: Redirect[];
|
|
@@ -146,7 +136,8 @@ interface Loaded {
|
|
|
146
136
|
assetIndex: Map<string, Asset>;
|
|
147
137
|
/**
|
|
148
138
|
* The gate index (RFC-0008 §7.4): every instant at which a published page's or entry's gate
|
|
149
|
-
* 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.
|
|
150
141
|
*/
|
|
151
142
|
gates: number[];
|
|
152
143
|
}
|
|
@@ -200,9 +191,14 @@ export declare class SnapshotSource implements GraphSource {
|
|
|
200
191
|
entries(collection: string, locale?: string): Promise<ContentEntry[]>;
|
|
201
192
|
entryBySlug(collection: string, slug: string, locale?: string): Promise<ContentEntry | undefined>;
|
|
202
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>;
|
|
203
198
|
search(query: string, options?: SourceSearchOptions): Promise<SearchResults>;
|
|
204
199
|
/** A published entry of this snapshot by id (any locale), if its gates are open. */
|
|
205
200
|
entryById(id: string): Promise<ContentEntry | undefined>;
|
|
201
|
+
entryFields(entry: ContentEntry, options?: EntryFieldsOptions): Promise<RenderedFields>;
|
|
206
202
|
taxonomies(): Promise<Taxonomy[]>;
|
|
207
203
|
terms(key: string): Promise<Term[]>;
|
|
208
204
|
termBySlug(key: string, slug: string): Promise<Term | undefined>;
|
|
@@ -224,4 +220,3 @@ export declare class SnapshotSource implements GraphSource {
|
|
|
224
220
|
asset(id: string): Promise<Asset | undefined>;
|
|
225
221
|
assetByPrefix(prefix16: string): Promise<Asset | undefined>;
|
|
226
222
|
}
|
|
227
|
-
export {};
|