@cloudhal/astro-renderer 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +36 -2
- package/dist/src/ambient-client.d.ts +17 -0
- package/dist/src/ambient-client.js +55 -0
- package/dist/src/analytics-client.d.ts +17 -0
- package/dist/src/analytics-client.js +96 -0
- package/dist/src/analytics-middleware.d.ts +6 -0
- package/dist/src/analytics-middleware.js +43 -0
- package/dist/src/analytics-node.d.ts +46 -0
- package/dist/src/analytics-node.js +134 -0
- package/dist/src/analytics.d.ts +117 -0
- package/dist/src/analytics.js +372 -0
- package/dist/src/archive.d.ts +106 -0
- package/dist/src/archive.js +207 -0
- package/dist/src/astro-env.d.ts +21 -0
- package/dist/src/block-html.d.ts +14 -0
- package/dist/src/block-html.js +103 -0
- package/dist/src/blocks.d.ts +24 -0
- package/dist/src/blocks.js +66 -0
- package/dist/src/cache-tags.d.ts +25 -0
- package/dist/src/cache-tags.js +59 -0
- package/dist/src/carousel-client.d.ts +28 -0
- package/dist/src/carousel-client.js +67 -0
- package/dist/src/chart.d.ts +34 -0
- package/dist/src/chart.js +182 -0
- package/dist/src/chrome-client.d.ts +27 -0
- package/dist/src/chrome-client.js +64 -0
- package/dist/src/cloudflare-entry.d.ts +87 -0
- package/dist/src/cloudflare-entry.js +548 -0
- package/dist/src/comments-client.d.ts +11 -0
- package/dist/src/comments-client.js +58 -0
- package/dist/src/comments-html.d.ts +42 -0
- package/dist/src/comments-html.js +303 -0
- package/dist/src/comments-middleware.d.ts +6 -0
- package/dist/src/comments-middleware.js +38 -0
- package/dist/src/comments-node.d.ts +42 -0
- package/dist/src/comments-node.js +112 -0
- package/dist/src/comments-view.d.ts +68 -0
- package/dist/src/comments-view.js +174 -0
- package/dist/src/comments.d.ts +66 -0
- package/dist/src/comments.js +258 -0
- package/dist/src/components/Block.astro +39 -0
- package/dist/src/components/Body.astro +43 -0
- package/dist/src/components/Comments.astro +19 -0
- package/dist/src/components/ContentList.astro +31 -0
- package/dist/src/components/EntryArticle.astro +31 -0
- package/dist/src/components/Hero.astro +36 -0
- package/dist/src/components/Image.astro +36 -0
- package/dist/src/components/RichText.astro +19 -0
- package/dist/src/components/Sections.astro +66 -0
- package/dist/src/components/SeoHead.astro +22 -0
- package/dist/src/components/Surface.astro +36 -0
- package/dist/src/components/SurfaceNode.astro +82 -0
- package/dist/src/components/index.d.ts +12 -0
- package/dist/src/components/index.js +12 -0
- package/dist/src/csp.d.ts +20 -0
- package/dist/src/csp.js +28 -0
- package/dist/src/embed-client.d.ts +38 -0
- package/dist/src/embed-client.js +98 -0
- package/dist/src/embed-middleware.d.ts +9 -0
- package/dist/src/embed-middleware.js +49 -0
- package/dist/src/feeds.d.ts +72 -0
- package/dist/src/feeds.js +246 -0
- package/dist/src/gates.d.ts +25 -0
- package/dist/src/gates.js +63 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +17 -0
- package/dist/src/integration.d.ts +55 -0
- package/dist/src/integration.js +244 -0
- package/dist/src/kit.d.ts +48 -0
- package/dist/src/kit.js +83 -0
- package/dist/src/locale-feeds.d.ts +29 -0
- package/dist/src/locale-feeds.js +152 -0
- package/dist/src/locale-middleware.d.ts +5 -0
- package/dist/src/locale-middleware.js +26 -0
- package/dist/src/locales.d.ts +87 -0
- package/dist/src/locales.js +336 -0
- package/dist/src/markdown.d.ts +83 -0
- package/dist/src/markdown.js +533 -0
- package/dist/src/media-middleware.d.ts +5 -0
- package/dist/src/media-middleware.js +18 -0
- package/dist/src/media-route.d.ts +47 -0
- package/dist/src/media-route.js +238 -0
- package/dist/src/media.d.ts +109 -0
- package/dist/src/media.js +298 -0
- package/dist/src/motion-client.d.ts +39 -0
- package/dist/src/motion-client.js +115 -0
- package/dist/src/navigation.d.ts +127 -0
- package/dist/src/navigation.js +382 -0
- package/dist/src/not-found.d.ts +16 -0
- package/dist/src/not-found.js +41 -0
- package/dist/src/overlay-client.d.ts +20 -0
- package/dist/src/overlay-client.js +49 -0
- package/dist/src/prefs-client.d.ts +14 -0
- package/dist/src/prefs-client.js +18 -0
- package/dist/src/preview.d.ts +70 -0
- package/dist/src/preview.js +551 -0
- package/dist/src/resolver.d.ts +71 -0
- package/dist/src/resolver.js +206 -0
- package/dist/src/routing.d.ts +108 -0
- package/dist/src/routing.js +285 -0
- package/dist/src/runtime-workerd.d.ts +87 -0
- package/dist/src/runtime-workerd.js +275 -0
- package/dist/src/runtime.d.ts +59 -0
- package/dist/src/runtime.js +153 -0
- package/dist/src/safe-urls.d.ts +13 -0
- package/dist/src/safe-urls.js +35 -0
- package/dist/src/sanitize.d.ts +7 -0
- package/dist/src/sanitize.js +217 -0
- package/dist/src/search-client.d.ts +29 -0
- package/dist/src/search-client.js +92 -0
- package/dist/src/search-limit.d.ts +36 -0
- package/dist/src/search-limit.js +66 -0
- package/dist/src/search.d.ts +64 -0
- package/dist/src/search.js +155 -0
- package/dist/src/seo.d.ts +85 -0
- package/dist/src/seo.js +468 -0
- package/dist/src/site-dispatch.d.ts +37 -0
- package/dist/src/site-dispatch.js +86 -0
- package/dist/src/site-hosts.d.ts +35 -0
- package/dist/src/site-hosts.js +110 -0
- package/dist/src/source.d.ts +227 -0
- package/dist/src/source.js +794 -0
- package/dist/src/static-gates.d.ts +3 -0
- package/dist/src/static-gates.js +28 -0
- package/dist/src/static-headers.d.ts +30 -0
- package/dist/src/static-headers.js +140 -0
- package/dist/src/static-media.d.ts +4 -0
- package/dist/src/static-media.js +65 -0
- package/dist/src/static-redirects.d.ts +4 -0
- package/dist/src/static-redirects.js +40 -0
- package/dist/src/surface-client.d.ts +34 -0
- package/dist/src/surface-client.js +146 -0
- package/dist/src/surfaces/html.d.ts +35 -0
- package/dist/src/surfaces/html.js +184 -0
- package/dist/src/surfaces/markup.d.ts +57 -0
- package/dist/src/surfaces/markup.js +135 -0
- package/dist/src/surfaces/motion.d.ts +33 -0
- package/dist/src/surfaces/motion.js +132 -0
- package/dist/src/surfaces/primitives/carousel.d.ts +2 -0
- package/dist/src/surfaces/primitives/carousel.js +95 -0
- package/dist/src/surfaces/primitives/content.d.ts +13 -0
- package/dist/src/surfaces/primitives/content.js +159 -0
- package/dist/src/surfaces/primitives/data.d.ts +5 -0
- package/dist/src/surfaces/primitives/data.js +80 -0
- package/dist/src/surfaces/primitives/index.d.ts +54 -0
- package/dist/src/surfaces/primitives/index.js +106 -0
- package/dist/src/surfaces/primitives/inputs.d.ts +8 -0
- package/dist/src/surfaces/primitives/inputs.js +68 -0
- package/dist/src/surfaces/primitives/layout.d.ts +14 -0
- package/dist/src/surfaces/primitives/layout.js +61 -0
- package/dist/src/surfaces/primitives/motion.d.ts +9 -0
- package/dist/src/surfaces/primitives/motion.js +45 -0
- package/dist/src/surfaces/primitives/overlays.d.ts +6 -0
- package/dist/src/surfaces/primitives/overlays.js +79 -0
- package/dist/src/surfaces/tree.d.ts +107 -0
- package/dist/src/surfaces/tree.js +321 -0
- package/dist/src/surfaces.d.ts +14 -0
- package/dist/src/surfaces.js +33 -0
- package/dist/src/taxonomy.d.ts +86 -0
- package/dist/src/taxonomy.js +268 -0
- package/dist/src/theme-settings.d.ts +24 -0
- package/dist/src/theme-settings.js +111 -0
- package/package.json +219 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Term archives (RFC-0002 §7): `<basePath>/<slug>`, `<basePath>/<slug>/page/<n>` and
|
|
3
|
+
* `<basePath>/<slug>/rss.xml`. Parsing, the status-code rules and the archive list are pure, so the
|
|
4
|
+
* starter's routes, sitemaps and static builds share one tested decision:
|
|
5
|
+
*
|
|
6
|
+
* | Request | Answer |
|
|
7
|
+
* |---------------------------------------------------------------|--------------------------------|
|
|
8
|
+
* | active + public, published entries ≥ `minEntriesToIndex` | 200, indexable, in the sitemap |
|
|
9
|
+
* | active + public, fewer entries, or `seo.noindex` | 200 `noindex,follow` |
|
|
10
|
+
* | no published entries; proposed or internal; archive disabled | 404 |
|
|
11
|
+
* | retired without a redirect | 410 (accepted answer 8) |
|
|
12
|
+
* | old slug, merged or redirected term | 301 via the Redirect node |
|
|
13
|
+
* | `…/page/1` | 301 to the archive root |
|
|
14
|
+
* | `…/page/n` past the last page | 404 |
|
|
15
|
+
*/
|
|
16
|
+
import type { ContentEntry, Taxonomy, Term } from "@cloudhal/core-contracts";
|
|
17
|
+
import { type ShownTerm, type TaxonomyIndex } from "./taxonomy.js";
|
|
18
|
+
/** Entries per archive page when a theme does not choose (the blog starter sets its own). */
|
|
19
|
+
export declare const DEFAULT_ARCHIVE_PAGE_SIZE = 20;
|
|
20
|
+
/** A request path that addresses a term archive. */
|
|
21
|
+
export interface ArchiveRequest {
|
|
22
|
+
readonly taxonomy: Taxonomy;
|
|
23
|
+
readonly slug: string;
|
|
24
|
+
/** The archive root (`<basePath>/<slug>`). */
|
|
25
|
+
readonly root: string;
|
|
26
|
+
readonly kind: "page" | "feed";
|
|
27
|
+
/** Requested page (1 for the root and the feed). */
|
|
28
|
+
readonly page: number;
|
|
29
|
+
/** `…/page/1`: the root's duplicate, answered with a 301 to the root. */
|
|
30
|
+
readonly explicitFirstPage: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The archive a path addresses, if any: only taxonomies with `archive.enabled`, a valid slug and
|
|
34
|
+
* one of the three shapes. A page number must be canonical (`2`, not `02` or `0`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseArchivePath(taxonomies: readonly Taxonomy[], path: string): ArchiveRequest | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The term an archive slug names: a live (non-retired) term with that current slug, else the most
|
|
39
|
+
* recently retired one. Old slugs (`slugHistory`) are not matched here: they answer through their
|
|
40
|
+
* redirects.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* The term an archive slug names; with `locale` (RFC-0033), the slug that locale shows
|
|
44
|
+
* (`labels[locale].slug`, else the term's own).
|
|
45
|
+
*/
|
|
46
|
+
export declare function termForSlug(terms: readonly Term[], slug: string, locale?: {
|
|
47
|
+
readonly locale: string;
|
|
48
|
+
readonly defaultLocale: string;
|
|
49
|
+
}): Term | undefined;
|
|
50
|
+
export type ArchiveState = {
|
|
51
|
+
readonly status: 200;
|
|
52
|
+
readonly indexable: boolean;
|
|
53
|
+
} | {
|
|
54
|
+
readonly status: 404;
|
|
55
|
+
} | {
|
|
56
|
+
readonly status: 410;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The status of a term's archive (before redirects, which the route consults for anything that is
|
|
60
|
+
* not a 200): `count` is the number of entries the archive lists in `locale`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function archiveState(taxonomy: Taxonomy, term: Term | undefined, count: number, locale: string): ArchiveState;
|
|
63
|
+
/** Pages an archive of `total` entries has (at least 1). */
|
|
64
|
+
export declare function pageCount(total: number, perPage: number): number;
|
|
65
|
+
/** What an archive page renders. */
|
|
66
|
+
export interface ArchiveView {
|
|
67
|
+
readonly taxonomy: Taxonomy;
|
|
68
|
+
readonly term: Term;
|
|
69
|
+
/** The term as shown (name in the locale, archive link). */
|
|
70
|
+
readonly shown: ShownTerm;
|
|
71
|
+
/** Public ancestors, root first (breadcrumb). */
|
|
72
|
+
readonly trail: ShownTerm[];
|
|
73
|
+
readonly locale: string;
|
|
74
|
+
/** Archive root path. */
|
|
75
|
+
readonly root: string;
|
|
76
|
+
/** This page's path (the root for page 1). */
|
|
77
|
+
readonly path: string;
|
|
78
|
+
/** The term feed's path, when the taxonomy publishes feeds. */
|
|
79
|
+
readonly feedPath?: string;
|
|
80
|
+
readonly page: number;
|
|
81
|
+
readonly pages: number;
|
|
82
|
+
readonly perPage: number;
|
|
83
|
+
/** Entries listed by the whole archive. */
|
|
84
|
+
readonly total: number;
|
|
85
|
+
/** Entries on this page, newest first. */
|
|
86
|
+
readonly entries: ContentEntry[];
|
|
87
|
+
readonly indexable: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** Path of page `n` of the archive a view belongs to. */
|
|
90
|
+
export declare function viewPagePath(view: Pick<ArchiveView, "root">, page: number): string;
|
|
91
|
+
/** One public archive of the site, as sitemaps, navigation and static builds list them. */
|
|
92
|
+
export interface ArchiveSummary {
|
|
93
|
+
readonly taxonomy: Taxonomy;
|
|
94
|
+
readonly term: Term;
|
|
95
|
+
readonly path: string;
|
|
96
|
+
readonly feedPath?: string;
|
|
97
|
+
readonly total: number;
|
|
98
|
+
readonly indexable: boolean;
|
|
99
|
+
/** The later of the newest listed entry's `updatedAt` and the term's `updatedAt`. */
|
|
100
|
+
readonly lastmod: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Every archive the site serves (a 200 by `archiveState`), from the entries a source shows: pass
|
|
104
|
+
* published entries for the public site. Ordered by taxonomy (index order), then term order.
|
|
105
|
+
*/
|
|
106
|
+
export declare function archiveSummaries(index: TaxonomyIndex, entries: readonly ContentEntry[]): ArchiveSummary[];
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Term archives (RFC-0002 §7): `<basePath>/<slug>`, `<basePath>/<slug>/page/<n>` and
|
|
3
|
+
* `<basePath>/<slug>/rss.xml`. Parsing, the status-code rules and the archive list are pure, so the
|
|
4
|
+
* starter's routes, sitemaps and static builds share one tested decision:
|
|
5
|
+
*
|
|
6
|
+
* | Request | Answer |
|
|
7
|
+
* |---------------------------------------------------------------|--------------------------------|
|
|
8
|
+
* | active + public, published entries ≥ `minEntriesToIndex` | 200, indexable, in the sitemap |
|
|
9
|
+
* | active + public, fewer entries, or `seo.noindex` | 200 `noindex,follow` |
|
|
10
|
+
* | no published entries; proposed or internal; archive disabled | 404 |
|
|
11
|
+
* | retired without a redirect | 410 (accepted answer 8) |
|
|
12
|
+
* | old slug, merged or redirected term | 301 via the Redirect node |
|
|
13
|
+
* | `…/page/1` | 301 to the archive root |
|
|
14
|
+
* | `…/page/n` past the last page | 404 |
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { termSlug } from "@cloudhal/core-ts";
|
|
18
|
+
import {
|
|
19
|
+
archiveFeedPath,
|
|
20
|
+
archiveMembers,
|
|
21
|
+
archivePagePath,
|
|
22
|
+
archivePath,
|
|
23
|
+
isPublicTerm,
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
} from "./taxonomy.js";
|
|
27
|
+
|
|
28
|
+
/** Entries per archive page when a theme does not choose (the blog starter sets its own). */
|
|
29
|
+
export const DEFAULT_ARCHIVE_PAGE_SIZE = 20;
|
|
30
|
+
|
|
31
|
+
const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
32
|
+
|
|
33
|
+
/** A request path that addresses a term archive. */
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The archive a path addresses, if any: only taxonomies with `archive.enabled`, a valid slug and
|
|
48
|
+
* one of the three shapes. A page number must be canonical (`2`, not `02` or `0`).
|
|
49
|
+
*/
|
|
50
|
+
export function parseArchivePath(
|
|
51
|
+
taxonomies ,
|
|
52
|
+
path ,
|
|
53
|
+
) {
|
|
54
|
+
for (const taxonomy of taxonomies) {
|
|
55
|
+
if (!taxonomy.archive.enabled) continue;
|
|
56
|
+
const base = taxonomy.archive.basePath;
|
|
57
|
+
if (!path.startsWith(`${base}/`)) continue;
|
|
58
|
+
const [slug, ...rest] = path.slice(base.length + 1).split("/");
|
|
59
|
+
if (!slug || !SLUG.test(slug)) continue;
|
|
60
|
+
const root = archivePath(taxonomy, slug);
|
|
61
|
+
const common = { taxonomy, slug, root };
|
|
62
|
+
if (rest.length === 0) return { ...common, kind: "page", page: 1, explicitFirstPage: false };
|
|
63
|
+
if (rest.length === 1 && rest[0] === "rss.xml")
|
|
64
|
+
return { ...common, kind: "feed", page: 1, explicitFirstPage: false };
|
|
65
|
+
if (rest.length === 2 && rest[0] === "page" && /^[1-9]\d{0,5}$/.test(rest[1] ?? ""))
|
|
66
|
+
return {
|
|
67
|
+
...common,
|
|
68
|
+
kind: "page",
|
|
69
|
+
page: Number(rest[1]),
|
|
70
|
+
explicitFirstPage: rest[1] === "1",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The term an archive slug names: a live (non-retired) term with that current slug, else the most
|
|
78
|
+
* recently retired one. Old slugs (`slugHistory`) are not matched here: they answer through their
|
|
79
|
+
* redirects.
|
|
80
|
+
*/
|
|
81
|
+
/**
|
|
82
|
+
* The term an archive slug names; with `locale` (RFC-0033), the slug that locale shows
|
|
83
|
+
* (`labels[locale].slug`, else the term's own).
|
|
84
|
+
*/
|
|
85
|
+
export function termForSlug(
|
|
86
|
+
terms ,
|
|
87
|
+
slug ,
|
|
88
|
+
locale ,
|
|
89
|
+
) {
|
|
90
|
+
const of = (t ) => (locale ? termSlug(t, locale.locale, locale.defaultLocale) : t.slug);
|
|
91
|
+
return (
|
|
92
|
+
terms.find((t) => of(t) === slug && t.status !== "retired") ??
|
|
93
|
+
terms.filter((t) => of(t) === slug).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))[0]
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The status of a term's archive (before redirects, which the route consults for anything that is
|
|
104
|
+
* not a 200): `count` is the number of entries the archive lists in `locale`.
|
|
105
|
+
*/
|
|
106
|
+
export function archiveState(
|
|
107
|
+
taxonomy ,
|
|
108
|
+
term ,
|
|
109
|
+
count ,
|
|
110
|
+
locale ,
|
|
111
|
+
) {
|
|
112
|
+
if (!taxonomy.archive.enabled || !term || term.taxonomyId !== taxonomy.id) return { status: 404 };
|
|
113
|
+
if (term.status === "retired") return { status: 410 };
|
|
114
|
+
if (!isPublicTerm(term) || count < 1) return { status: 404 };
|
|
115
|
+
const noindex = term.labels[locale]?.seo?.noindex === true;
|
|
116
|
+
return { status: 200, indexable: !noindex && count >= taxonomy.minEntriesToIndex };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Pages an archive of `total` entries has (at least 1). */
|
|
120
|
+
export function pageCount(total , perPage ) {
|
|
121
|
+
return Math.max(1, Math.ceil(total / Math.max(1, perPage)));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** What an archive page renders. */
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
/** Path of page `n` of the archive a view belongs to. */
|
|
150
|
+
export function viewPagePath(view , page ) {
|
|
151
|
+
return archivePagePath(view.root, page);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** One public archive of the site, as sitemaps, navigation and static builds list them. */
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Every archive the site serves (a 200 by `archiveState`), from the entries a source shows: pass
|
|
168
|
+
* published entries for the public site. Ordered by taxonomy (index order), then term order.
|
|
169
|
+
*/
|
|
170
|
+
export function archiveSummaries(
|
|
171
|
+
index ,
|
|
172
|
+
entries ,
|
|
173
|
+
) {
|
|
174
|
+
const members = archiveMembers(
|
|
175
|
+
index,
|
|
176
|
+
entries.filter((e) => e.locale === index.locale),
|
|
177
|
+
);
|
|
178
|
+
const out = [];
|
|
179
|
+
const terms = [...index.terms.values()];
|
|
180
|
+
for (const taxonomy of index.taxonomies) {
|
|
181
|
+
if (!taxonomy.archive.enabled) continue;
|
|
182
|
+
for (const term of terms) {
|
|
183
|
+
if (term.taxonomyId !== taxonomy.id) continue;
|
|
184
|
+
const listed = members.get(term.id) ?? [];
|
|
185
|
+
const state = archiveState(taxonomy, term, listed.length, index.locale);
|
|
186
|
+
if (state.status !== 200) continue;
|
|
187
|
+
const newest = listed.reduce(
|
|
188
|
+
(max, e) => (e.updatedAt > max ? e.updatedAt : max),
|
|
189
|
+
term.updatedAt,
|
|
190
|
+
);
|
|
191
|
+
const path = archivePath(
|
|
192
|
+
taxonomy,
|
|
193
|
+
termSlug(term, index.locale, index.defaultLocale ?? index.locale),
|
|
194
|
+
);
|
|
195
|
+
out.push({
|
|
196
|
+
taxonomy,
|
|
197
|
+
term,
|
|
198
|
+
path,
|
|
199
|
+
...(taxonomy.feed ? { feedPath: archiveFeedPath(path) } : {}),
|
|
200
|
+
total: listed.length,
|
|
201
|
+
indexable: state.indexable,
|
|
202
|
+
lastmod: newest,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare module "*.astro" {
|
|
2
|
+
const Component: (props: Record<string, unknown>) => unknown;
|
|
3
|
+
export default Component;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module "virtual:cloudhal/analytics-client" {
|
|
7
|
+
/** The built analytics scripts in `cloudhal dev`; `null` elsewhere. */
|
|
8
|
+
const client: import("./analytics-client.js").AnalyticsClient | null;
|
|
9
|
+
export default client;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module "virtual:cloudhal/config" {
|
|
13
|
+
const config: import("./integration.js").CloudhalRendererConfig;
|
|
14
|
+
export default config;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module "virtual:cloudhal/comments-client" {
|
|
18
|
+
/** The built comments module and worker in `cloudhal dev`; `null` elsewhere. */
|
|
19
|
+
const client: import("./comments-client.js").CommentsClient | null;
|
|
20
|
+
export default client;
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const escapeHtml: (s: string) => string;
|
|
2
|
+
/** Is `type` rendered by Cloudhal itself (a built-in)? Themes may still map it to their own. */
|
|
3
|
+
export declare const isBuiltInBlock: (type: string) => boolean;
|
|
4
|
+
export interface BlockHtmlContext {
|
|
5
|
+
/** Renders a markdown prop safely (asset links resolved). */
|
|
6
|
+
markdown: (source: string) => string;
|
|
7
|
+
/** A container's inner text, already rendered; else `props.content` goes through `markdown`. */
|
|
8
|
+
contentHtml?: string;
|
|
9
|
+
}
|
|
10
|
+
/** A built-in block's markup for valid props; "" for a type that is not built in. */
|
|
11
|
+
export declare function builtInBlockHtml(type: string, props: Readonly<Record<string, unknown>>, ctx: BlockHtmlContext): string;
|
|
12
|
+
/** What previews show in place of a block that renders nothing on the site (RFC-0015 §6). */
|
|
13
|
+
export declare function missingBlockHtml(tag: "section" | "div", attrs: string, type: string, why: "unknown block type" | "props do not fit the block type" | "shown by the theme on the site"): string;
|
|
14
|
+
export { escapeHtml as escapeBlockHtml };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in block types' markup (RFC-0015 §5), shared by component sections (`blocks.ts`) and
|
|
3
|
+
* body directives (`markdown.ts`), so a block looks the same in both. Text props are escaped,
|
|
4
|
+
* markdown props go through the caller's safe markdown renderer, links through `safeHref`; no raw
|
|
5
|
+
* HTML ever comes from props.
|
|
6
|
+
*
|
|
7
|
+
* `embed` renders a link card to the video; the first-party player module (`embed-client.ts`)
|
|
8
|
+
* turns it into the player when the reader follows it, so the video host sees nothing before.
|
|
9
|
+
*/
|
|
10
|
+
import { BUILT_IN_BLOCK_TYPES } from "@cloudhal/core-ts/blocks";
|
|
11
|
+
import { EMBED_SCRIPT, embedPlayerSrc } from "./embed-client.js";
|
|
12
|
+
import { safeHref } from "./safe-urls.js";
|
|
13
|
+
|
|
14
|
+
const escapeHtml = (s ) =>
|
|
15
|
+
s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
16
|
+
|
|
17
|
+
const BUILT_IN = new Set(BUILT_IN_BLOCK_TYPES.map((t) => t.name));
|
|
18
|
+
|
|
19
|
+
/** Is `type` rendered by Cloudhal itself (a built-in)? Themes may still map it to their own. */
|
|
20
|
+
export const isBuiltInBlock = (type ) => BUILT_IN.has(type);
|
|
21
|
+
|
|
22
|
+
const str = (v ) => (typeof v === "string" ? v : "");
|
|
23
|
+
|
|
24
|
+
/** A video page's host, for the card's label ("youtube.com"). */
|
|
25
|
+
function videoHost(url ) {
|
|
26
|
+
try {
|
|
27
|
+
return new URL(url).hostname.replace(/^(www|m)\./, "");
|
|
28
|
+
} catch {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/** A built-in block's markup for valid props; "" for a type that is not built in. */
|
|
41
|
+
export function builtInBlockHtml(
|
|
42
|
+
type ,
|
|
43
|
+
props ,
|
|
44
|
+
ctx ,
|
|
45
|
+
) {
|
|
46
|
+
switch (type) {
|
|
47
|
+
case "callout": {
|
|
48
|
+
const tone = ["info", "success", "warning", "danger"].includes(str(props.tone))
|
|
49
|
+
? str(props.tone)
|
|
50
|
+
: "info";
|
|
51
|
+
const title = str(props.title);
|
|
52
|
+
const body = ctx.contentHtml ?? ctx.markdown(str(props.content));
|
|
53
|
+
return `<aside class="ch-callout ch-callout--${tone}" role="note" data-block="callout">${
|
|
54
|
+
title ? `<p class="ch-callout__title"><strong>${escapeHtml(title)}</strong></p>` : ""
|
|
55
|
+
}<div class="ch-callout__body">${body}</div></aside>`;
|
|
56
|
+
}
|
|
57
|
+
case "button": {
|
|
58
|
+
const href = safeHref(str(props.href));
|
|
59
|
+
const variant = props.variant === "secondary" ? "secondary" : "primary";
|
|
60
|
+
const label = escapeHtml(str(props.label));
|
|
61
|
+
return href
|
|
62
|
+
? `<p class="ch-button-row" data-block="button"><a class="ch-button ch-button--${variant}" href="${escapeHtml(href)}">${label}</a></p>`
|
|
63
|
+
: "";
|
|
64
|
+
}
|
|
65
|
+
case "embed": {
|
|
66
|
+
const href = safeHref(str(props.url));
|
|
67
|
+
const title = escapeHtml(str(props.title));
|
|
68
|
+
if (!href) return "";
|
|
69
|
+
// The link card works without JavaScript; the first-party player module swaps it for the
|
|
70
|
+
// video's iframe when followed (`embed-client.ts`), so nothing loads from the host before.
|
|
71
|
+
const player = embedPlayerSrc(href);
|
|
72
|
+
const data = player
|
|
73
|
+
? ` data-embed-src="${escapeHtml(player)}" data-embed-title="${title}"`
|
|
74
|
+
: "";
|
|
75
|
+
return `<figure class="ch-embed" data-block="embed"${data}><a class="ch-embed__link" href="${escapeHtml(href)}" rel="noopener noreferrer" target="_blank"><span class="ch-embed__play" aria-hidden="true">▶</span><span class="ch-embed__title">${title}</span><span class="ch-embed__host">${escapeHtml(videoHost(href))}</span></a>${
|
|
76
|
+
player ? `<script type="module" src="${EMBED_SCRIPT.path}"></script>` : ""
|
|
77
|
+
}</figure>`;
|
|
78
|
+
}
|
|
79
|
+
case "faq": {
|
|
80
|
+
const items = Array.isArray(props.items) ? (props.items ) : [];
|
|
81
|
+
return `<div class="ch-faq" data-block="faq">${items
|
|
82
|
+
.map(
|
|
83
|
+
(item) =>
|
|
84
|
+
`<details class="ch-faq__item"><summary>${escapeHtml(str(item.question))}</summary><div class="ch-faq__answer">${ctx.markdown(str(item.answer))}</div></details>`,
|
|
85
|
+
)
|
|
86
|
+
.join("")}</div>`;
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** What previews show in place of a block that renders nothing on the site (RFC-0015 §6). */
|
|
94
|
+
export function missingBlockHtml(
|
|
95
|
+
tag ,
|
|
96
|
+
attrs ,
|
|
97
|
+
type ,
|
|
98
|
+
why ,
|
|
99
|
+
) {
|
|
100
|
+
return `<${tag} class="ch-block ch-block--missing" ${attrs}><p>${escapeHtml(`${type}: ${why}`)}</p></${tag}>`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { escapeHtml as escapeBlockHtml };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component sections as HTML (RFC-0015 §5): the built-ins' markup (`block-html.ts`, shared with
|
|
3
|
+
* body directives) used by `Block.astro` (unless the theme maps the type to its own component)
|
|
4
|
+
* and by `preview.ts`, so agents' previews match the site. Props are validated before render.
|
|
5
|
+
*/
|
|
6
|
+
import type { ComponentSection } from "@cloudhal/core-contracts";
|
|
7
|
+
import { type BlockRegistry, type BlockType } from "@cloudhal/core-ts/blocks";
|
|
8
|
+
import { isBuiltInBlock } from "./block-html.js";
|
|
9
|
+
import { type MediaContext } from "./markdown.js";
|
|
10
|
+
export { isBuiltInBlock };
|
|
11
|
+
/**
|
|
12
|
+
* A component section's markup. Invalid props, or a type no one renders, give nothing on the
|
|
13
|
+
* site and a labelled placeholder in previews (RFC-0015 §6).
|
|
14
|
+
*/
|
|
15
|
+
export declare function renderComponentSection(section: ComponentSection, options?: {
|
|
16
|
+
media?: MediaContext;
|
|
17
|
+
registry?: BlockRegistry;
|
|
18
|
+
preview?: boolean;
|
|
19
|
+
}): string;
|
|
20
|
+
/**
|
|
21
|
+
* The registry for a theme's block types (`src/blocks.ts`): the built-ins and the theme's, built
|
|
22
|
+
* once per list. Invalid types throw here, as at deploy.
|
|
23
|
+
*/
|
|
24
|
+
export declare function themeRegistry(types: readonly BlockType[] | undefined): BlockRegistry;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component sections as HTML (RFC-0015 §5): the built-ins' markup (`block-html.ts`, shared with
|
|
3
|
+
* body directives) used by `Block.astro` (unless the theme maps the type to its own component)
|
|
4
|
+
* and by `preview.ts`, so agents' previews match the site. Props are validated before render.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createBlockRegistry } from "@cloudhal/core-ts/blocks";
|
|
8
|
+
import {
|
|
9
|
+
builtInBlockHtml,
|
|
10
|
+
escapeBlockHtml,
|
|
11
|
+
isBuiltInBlock,
|
|
12
|
+
missingBlockHtml,
|
|
13
|
+
} from "./block-html.js";
|
|
14
|
+
import { renderMarkdown } from "./markdown.js";
|
|
15
|
+
|
|
16
|
+
export { isBuiltInBlock };
|
|
17
|
+
|
|
18
|
+
const builtIns = createBlockRegistry();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A component section's markup. Invalid props, or a type no one renders, give nothing on the
|
|
22
|
+
* site and a labelled placeholder in previews (RFC-0015 §6).
|
|
23
|
+
*/
|
|
24
|
+
export function renderComponentSection(
|
|
25
|
+
section ,
|
|
26
|
+
options = {},
|
|
27
|
+
) {
|
|
28
|
+
const registry = options.registry ?? options.media?.blocks ?? builtIns;
|
|
29
|
+
const issues = registry.checkSection(section.type, section.props);
|
|
30
|
+
const known = issues !== undefined && isBuiltInBlock(section.type);
|
|
31
|
+
const html =
|
|
32
|
+
known && issues.length === 0
|
|
33
|
+
? builtInBlockHtml(section.type, section.props, {
|
|
34
|
+
markdown: (source) => renderMarkdown(source, options.media),
|
|
35
|
+
})
|
|
36
|
+
: "";
|
|
37
|
+
const attrs = `data-section-id="${escapeBlockHtml(section.id)}" data-kind="component" data-block-type="${escapeBlockHtml(section.type)}"`;
|
|
38
|
+
if (html) return `<section class="ch-block" ${attrs}>${html}</section>`;
|
|
39
|
+
if (!options.preview) return "";
|
|
40
|
+
return missingBlockHtml(
|
|
41
|
+
"section",
|
|
42
|
+
attrs,
|
|
43
|
+
section.type,
|
|
44
|
+
issues === undefined
|
|
45
|
+
? "unknown block type"
|
|
46
|
+
: issues.length
|
|
47
|
+
? "props do not fit the block type"
|
|
48
|
+
: "shown by the theme on the site",
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const registries = new WeakMap ();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The registry for a theme's block types (`src/blocks.ts`): the built-ins and the theme's, built
|
|
56
|
+
* once per list. Invalid types throw here, as at deploy.
|
|
57
|
+
*/
|
|
58
|
+
export function themeRegistry(types ) {
|
|
59
|
+
if (!types?.length) return builtIns;
|
|
60
|
+
let registry = registries.get(types);
|
|
61
|
+
if (!registry) {
|
|
62
|
+
registry = createBlockRegistry(types);
|
|
63
|
+
registries.set(types, registry);
|
|
64
|
+
}
|
|
65
|
+
return registry;
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edge-cache tags (ADR-0012, RFC-0002 §7). Every published response carries the site tag; pages
|
|
3
|
+
* add a tag per node and term they render and per list they show, so a publish purges only what
|
|
4
|
+
* changed (`planCachePurge` in core-ts, called by the admin Worker):
|
|
5
|
+
*
|
|
6
|
+
* - `cloudhal-site-<siteId>` — every published response (set by the runtime);
|
|
7
|
+
* - `cloudhal-node-<id>` — the page or entry a response renders, the entries an archive lists and
|
|
8
|
+
* the related entries an article links to;
|
|
9
|
+
* - `cloudhal-term-<id>` — the term an archive is about, its ancestors in the breadcrumb, the terms
|
|
10
|
+
* an entry shows and the header categories;
|
|
11
|
+
* - `cloudhal-list-<termId>` — a term's archive pages and feed; `cloudhal-list-<siteId>` — the site
|
|
12
|
+
* feed, the sitemap and pages with a `ContentList` section;
|
|
13
|
+
* - `cloudhal-comments-<nodeId>` — an entry's page and its comment pages, which show that entry's
|
|
14
|
+
* approved comments (RFC-0007 §8.1); moderation purges only this tag.
|
|
15
|
+
*
|
|
16
|
+
* The names live in `@cloudhal/core-ts/cache-tags`, shared with the purge planner. Tags are only
|
|
17
|
+
* added where the runtime already set `cache-tag` (published responses on Cloudflare); previews and
|
|
18
|
+
* Node builds have no edge cache and stay untouched.
|
|
19
|
+
*/
|
|
20
|
+
export { ASSET_TAG_PREFIX, assetCacheTag, CACHE_TAG_PREFIX, COMMENTS_TAG_PREFIX, commentsCacheTag, isCloudhalCacheTag, LIST_TAG_PREFIX, listCacheTag, MEDIA_TAG_PREFIX, mediaCacheTag, NODE_TAG_PREFIX, nodeCacheTag, siteCacheTag, TERM_TAG_PREFIX, termCacheTag, } from "@cloudhal/core-ts/cache-tags";
|
|
21
|
+
/**
|
|
22
|
+
* Appends tags to an existing `cache-tag` header (deduplicated, bounded); no header, no change.
|
|
23
|
+
* Put the tags a purge must be able to reach first: once the header is full the rest are dropped.
|
|
24
|
+
*/
|
|
25
|
+
export declare function addCacheTags(headers: Headers, tags: readonly string[]): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edge-cache tags (ADR-0012, RFC-0002 §7). Every published response carries the site tag; pages
|
|
3
|
+
* add a tag per node and term they render and per list they show, so a publish purges only what
|
|
4
|
+
* changed (`planCachePurge` in core-ts, called by the admin Worker):
|
|
5
|
+
*
|
|
6
|
+
* - `cloudhal-site-<siteId>` — every published response (set by the runtime);
|
|
7
|
+
* - `cloudhal-node-<id>` — the page or entry a response renders, the entries an archive lists and
|
|
8
|
+
* the related entries an article links to;
|
|
9
|
+
* - `cloudhal-term-<id>` — the term an archive is about, its ancestors in the breadcrumb, the terms
|
|
10
|
+
* an entry shows and the header categories;
|
|
11
|
+
* - `cloudhal-list-<termId>` — a term's archive pages and feed; `cloudhal-list-<siteId>` — the site
|
|
12
|
+
* feed, the sitemap and pages with a `ContentList` section;
|
|
13
|
+
* - `cloudhal-comments-<nodeId>` — an entry's page and its comment pages, which show that entry's
|
|
14
|
+
* approved comments (RFC-0007 §8.1); moderation purges only this tag.
|
|
15
|
+
*
|
|
16
|
+
* The names live in `@cloudhal/core-ts/cache-tags`, shared with the purge planner. Tags are only
|
|
17
|
+
* added where the runtime already set `cache-tag` (published responses on Cloudflare); previews and
|
|
18
|
+
* Node builds have no edge cache and stay untouched.
|
|
19
|
+
*/
|
|
20
|
+
export {
|
|
21
|
+
ASSET_TAG_PREFIX,
|
|
22
|
+
assetCacheTag,
|
|
23
|
+
CACHE_TAG_PREFIX,
|
|
24
|
+
COMMENTS_TAG_PREFIX,
|
|
25
|
+
commentsCacheTag,
|
|
26
|
+
isCloudhalCacheTag,
|
|
27
|
+
LIST_TAG_PREFIX,
|
|
28
|
+
listCacheTag,
|
|
29
|
+
MEDIA_TAG_PREFIX,
|
|
30
|
+
mediaCacheTag,
|
|
31
|
+
NODE_TAG_PREFIX,
|
|
32
|
+
nodeCacheTag,
|
|
33
|
+
siteCacheTag,
|
|
34
|
+
TERM_TAG_PREFIX,
|
|
35
|
+
termCacheTag,
|
|
36
|
+
} from "@cloudhal/core-ts/cache-tags";
|
|
37
|
+
|
|
38
|
+
/** Cloudflare accepts up to 16 KB of tags per response; stay well below it. */
|
|
39
|
+
const MAX_HEADER_LENGTH = 8 * 1024;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Appends tags to an existing `cache-tag` header (deduplicated, bounded); no header, no change.
|
|
43
|
+
* Put the tags a purge must be able to reach first: once the header is full the rest are dropped.
|
|
44
|
+
*/
|
|
45
|
+
export function addCacheTags(headers , tags ) {
|
|
46
|
+
const current = headers.get("cache-tag");
|
|
47
|
+
if (!current) return;
|
|
48
|
+
const all = current.split(",").map((t) => t.trim());
|
|
49
|
+
const seen = new Set(all);
|
|
50
|
+
let length = current.length;
|
|
51
|
+
for (const tag of tags) {
|
|
52
|
+
if (seen.has(tag)) continue;
|
|
53
|
+
if (length + tag.length + 1 > MAX_HEADER_LENGTH) break;
|
|
54
|
+
seen.add(tag);
|
|
55
|
+
all.push(tag);
|
|
56
|
+
length += tag.length + 1;
|
|
57
|
+
}
|
|
58
|
+
headers.set("cache-tag", all.join(","));
|
|
59
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudhal's carousel module (RFC-0027 27b): what a carousel needs beyond scroll snap. A
|
|
3
|
+
* self-contained, versioned file under `/_cloudhal/` (CSP `script-src 'self'`), loaded only by
|
|
4
|
+
* surfaces with a `Carousel`. Without it every slide is still reachable by scrolling and by the
|
|
5
|
+
* marker links; with it:
|
|
6
|
+
*
|
|
7
|
+
* - The arrows appear (`data-ch-pending` goes) and move by a slide (hero) or by what is in view
|
|
8
|
+
* (rail), through `scrollIntoView` (the browser handles right-to-left and the site's
|
|
9
|
+
* `scroll-behavior`); at the ends they say so (`aria-disabled`).
|
|
10
|
+
* - The current slide is tracked (from the slides' boxes on `scroll` and `scrollend`) and shown on its marker
|
|
11
|
+
* (`aria-current`); a marker click scrolls the track instead of jumping the page or the hash.
|
|
12
|
+
* - After the reader moves, a polite live region names the slide ("2 of 5").
|
|
13
|
+
* - A hero's or gallery's slides out of view are `inert` (one slide in view: Tab never lands on
|
|
14
|
+
* what cannot be seen).
|
|
15
|
+
* - 27d: a hero with `data-loop` wraps at its ends. A hero with `data-autoplay` (slow 8 s, normal 6 s)
|
|
16
|
+
* moves on its own only while the site's motion is standard or expressive, the reader has not
|
|
17
|
+
* asked for reduced motion or paused motion, the tab is visible and the carousel is in view; it
|
|
18
|
+
* pauses on hover and stops for good on focus inside, a pointer press or a swipe; its rotation
|
|
19
|
+
* control (first in Tab order, shown only where motion may play) stops and restarts it; the
|
|
20
|
+
* live region is silent while it plays.
|
|
21
|
+
* No scroll hijacking: swipe and wheel stay native.
|
|
22
|
+
*/
|
|
23
|
+
export declare const CAROUSEL_SCRIPT: {
|
|
24
|
+
readonly path: "/_cloudhal/carousel.3.js";
|
|
25
|
+
readonly code: string;
|
|
26
|
+
};
|
|
27
|
+
/** Earlier names, still asked for by cached pages: they get the current code. */
|
|
28
|
+
export declare const CAROUSEL_SCRIPT_ALIASES: readonly ["/_cloudhal/carousel.1.js", "/_cloudhal/carousel.2.js"];
|