@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,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HeroSection } from "@cloudhal/core-contracts";
|
|
3
|
+
import { safeHref, safeSrc } from "../markdown.js";
|
|
4
|
+
import { imageAttributes, type MediaContext } from "../media.js";
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
section: HeroSection;
|
|
8
|
+
/** Assets of the page's source, transform and locale (RFC-0004 §7.5). */
|
|
9
|
+
media?: MediaContext;
|
|
10
|
+
}
|
|
11
|
+
const { section, media } = Astro.props;
|
|
12
|
+
const asset = section.image?.assetId ? media?.assets?.get(section.image.assetId) : undefined;
|
|
13
|
+
const defaultLocale = media?.defaultLocale ?? media?.locale ?? "en";
|
|
14
|
+
const attrs =
|
|
15
|
+
asset && section.image
|
|
16
|
+
? imageAttributes(asset, section.image, {
|
|
17
|
+
locale: media?.locale ?? defaultLocale,
|
|
18
|
+
defaultLocale,
|
|
19
|
+
transform: media?.transform ?? "none",
|
|
20
|
+
...(media?.budget ? { budget: media.budget } : {}),
|
|
21
|
+
sizes: "100vw",
|
|
22
|
+
priority: true,
|
|
23
|
+
...(media?.preview ? { preview: true } : {}),
|
|
24
|
+
})
|
|
25
|
+
: undefined;
|
|
26
|
+
// Section fields can be written by agents: only safe URL schemes reach the page.
|
|
27
|
+
const imageSrc = !attrs && section.image ? safeSrc(section.image.src) : undefined;
|
|
28
|
+
const ctaHref = section.cta ? safeHref(section.cta.href) : undefined;
|
|
29
|
+
---
|
|
30
|
+
<section class="ch-hero" data-section-id={section.id} data-kind="hero">
|
|
31
|
+
<h1>{section.heading}</h1>
|
|
32
|
+
{section.subheading && <p class="ch-hero__sub">{section.subheading}</p>}
|
|
33
|
+
{attrs && <img src={attrs.src} srcset={attrs.srcset} sizes={attrs.sizes} alt={attrs.alt} width={attrs.width || undefined} height={attrs.height || undefined} loading={attrs.loading} decoding={attrs.decoding} fetchpriority={attrs.fetchpriority} style={attrs.style} />}
|
|
34
|
+
{section.image && imageSrc && <img src={imageSrc} alt={section.image.alt} width={section.image.width} height={section.image.height} />}
|
|
35
|
+
{section.cta && ctaHref && <a class="ch-hero__cta" href={ctaHref} rel={section.cta.external ? "noopener noreferrer" : undefined}>{section.cta.label}</a>}
|
|
36
|
+
</section>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { ImageSection } from "@cloudhal/core-contracts";
|
|
3
|
+
import { safeSrc } from "../markdown.js";
|
|
4
|
+
import { assetCaption, imageAttributes, type MediaContext } from "../media.js";
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
section: ImageSection;
|
|
8
|
+
/** Assets of the page's source, transform and locale (RFC-0004 §7.5). */
|
|
9
|
+
media?: MediaContext;
|
|
10
|
+
}
|
|
11
|
+
const { section, media } = Astro.props;
|
|
12
|
+
// An `assetId` resolves through the source; otherwise (or for a reader without media) `src` is used.
|
|
13
|
+
const asset = section.image.assetId ? media?.assets?.get(section.image.assetId) : undefined;
|
|
14
|
+
const defaultLocale = media?.defaultLocale ?? media?.locale ?? "en";
|
|
15
|
+
const locale = media?.locale ?? defaultLocale;
|
|
16
|
+
const attrs = asset
|
|
17
|
+
? imageAttributes(asset, section.image, {
|
|
18
|
+
locale,
|
|
19
|
+
defaultLocale,
|
|
20
|
+
transform: media?.transform ?? "none",
|
|
21
|
+
...(media?.budget ? { budget: media.budget } : {}),
|
|
22
|
+
sizes: "(min-width: 48rem) 48rem, 100vw",
|
|
23
|
+
...(media?.preview ? { preview: true } : {}),
|
|
24
|
+
})
|
|
25
|
+
: undefined;
|
|
26
|
+
// Section fields can be written by agents: only safe URL schemes reach the page.
|
|
27
|
+
const src = attrs ? undefined : safeSrc(section.image.src);
|
|
28
|
+
const caption = asset
|
|
29
|
+
? assetCaption(asset, locale, defaultLocale, section.caption)
|
|
30
|
+
: section.caption;
|
|
31
|
+
---
|
|
32
|
+
<figure class="ch-image" data-section-id={section.id} data-kind="image">
|
|
33
|
+
{attrs && <img src={attrs.src} srcset={attrs.srcset} sizes={attrs.sizes} alt={attrs.alt} width={attrs.width || undefined} height={attrs.height || undefined} loading={attrs.loading} decoding={attrs.decoding} style={attrs.style} />}
|
|
34
|
+
{src && <img src={src} alt={section.image.alt} width={section.image.width} height={section.image.height} />}
|
|
35
|
+
{caption && <figcaption>{caption}</figcaption>}
|
|
36
|
+
</figure>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { RichTextSection } from "@cloudhal/core-contracts";
|
|
3
|
+
import type { BlockType } from "@cloudhal/core-ts/blocks";
|
|
4
|
+
import type { MediaContext } from "../media.js";
|
|
5
|
+
import Body from "./Body.astro";
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
section: RichTextSection;
|
|
9
|
+
/** Resolves `asset:<id>` in the markdown (RFC-0004 §7.6). */
|
|
10
|
+
media?: MediaContext;
|
|
11
|
+
/** The theme's block components and types (RFC-0015 §5), for blocks inside the text. */
|
|
12
|
+
blocks?: Record<string, unknown>;
|
|
13
|
+
blockTypes?: readonly BlockType[];
|
|
14
|
+
}
|
|
15
|
+
const { section, media, blocks, blockTypes } = Astro.props;
|
|
16
|
+
---
|
|
17
|
+
<section class="ch-richtext" data-section-id={section.id} data-kind="richText">
|
|
18
|
+
<Body body={{ format: section.format, value: section.body }} media={media} blocks={blocks} blockTypes={blockTypes} />
|
|
19
|
+
</section>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Renders a page's sections by `kind`. Themes override any component through `components`;
|
|
4
|
+
* `entries` supplies collection data for contentList sections, keyed by collection name — or by
|
|
5
|
+
* section id for a section with a `filter`, whose entries the page resolved on their own. `media`
|
|
6
|
+
* resolves assets in image, hero and rich-text sections (RFC-0004). Component sections (RFC-0015)
|
|
7
|
+
* render through `Block.astro`: the theme's `blocks` map, else Cloudhal's built-in markup; rich
|
|
8
|
+
* text places the theme's block components inside the text too (`Body.astro`).
|
|
9
|
+
*/
|
|
10
|
+
import type { ContentEntry, Section } from "@cloudhal/core-contracts";
|
|
11
|
+
import type { BlockType } from "@cloudhal/core-ts/blocks";
|
|
12
|
+
import type { MediaContext } from "../media.js";
|
|
13
|
+
import type { SurfaceEntryCard } from "../surfaces.js";
|
|
14
|
+
import Block from "./Block.astro";
|
|
15
|
+
import ContentList from "./ContentList.astro";
|
|
16
|
+
import Hero from "./Hero.astro";
|
|
17
|
+
import Image from "./Image.astro";
|
|
18
|
+
import RichText from "./RichText.astro";
|
|
19
|
+
import Surface from "./Surface.astro";
|
|
20
|
+
|
|
21
|
+
export type SectionComponents = Partial<
|
|
22
|
+
Record<Exclude<Section["kind"], "component" | "surface">, unknown>
|
|
23
|
+
>;
|
|
24
|
+
/** A theme's components for block types (RFC-0015), by type name. */
|
|
25
|
+
export type BlockComponents = Record<string, unknown>;
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
sections: Section[];
|
|
29
|
+
entries?: Record<string, ContentEntry[]>;
|
|
30
|
+
components?: SectionComponents;
|
|
31
|
+
blocks?: BlockComponents;
|
|
32
|
+
/** The theme's block types (`src/blocks.ts`): checked before its components render them. */
|
|
33
|
+
blockTypes?: readonly BlockType[];
|
|
34
|
+
media?: MediaContext;
|
|
35
|
+
/** Surfaces' entry sources by section id, then data key (`loadSurfaceSources`, RFC-0020 §3). */
|
|
36
|
+
surfaceSources?: Record<string, Record<string, SurfaceEntryCard[]>>;
|
|
37
|
+
}
|
|
38
|
+
const {
|
|
39
|
+
sections,
|
|
40
|
+
entries = {},
|
|
41
|
+
components = {},
|
|
42
|
+
blocks = {},
|
|
43
|
+
blockTypes,
|
|
44
|
+
media,
|
|
45
|
+
surfaceSources = {},
|
|
46
|
+
} = Astro.props;
|
|
47
|
+
const defaults = { hero: Hero, richText: RichText, image: Image, contentList: ContentList };
|
|
48
|
+
type AnyComponent = (props: never) => unknown;
|
|
49
|
+
const resolved = { ...defaults, ...components } as Record<
|
|
50
|
+
Exclude<Section["kind"], "component" | "surface">,
|
|
51
|
+
AnyComponent | undefined
|
|
52
|
+
>;
|
|
53
|
+
---
|
|
54
|
+
{sections.map((section) => {
|
|
55
|
+
if (section.kind === "component")
|
|
56
|
+
return <Block section={section} blocks={blocks} blockTypes={blockTypes} {...(media ? { media } : {})} />;
|
|
57
|
+
if (section.kind === "surface")
|
|
58
|
+
return <Surface section={section} blocks={blocks} blockTypes={blockTypes} sources={surfaceSources[section.id]} {...(media ? { media } : {})} />;
|
|
59
|
+
const Component = resolved[section.kind];
|
|
60
|
+
if (!Component) return <div data-unknown-section={section.kind} />;
|
|
61
|
+
return section.kind === "contentList"
|
|
62
|
+
? <Component section={section} entries={entries[section.id] ?? entries[section.collection] ?? []} media={media} />
|
|
63
|
+
: section.kind === "richText"
|
|
64
|
+
? <Component section={section} media={media} blocks={blocks} blockTypes={blockTypes} />
|
|
65
|
+
: <Component section={section} media={media} />;
|
|
66
|
+
})}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Everything search engines and link previews read from `<head>` (see `seo.ts`). Put it inside
|
|
4
|
+
* the layout's `<head>`; themes decide layout, not SEO rules.
|
|
5
|
+
*/
|
|
6
|
+
import type { HeadMeta } from "../seo.js";
|
|
7
|
+
import { jsonLdText } from "../seo.js";
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
meta: HeadMeta;
|
|
11
|
+
}
|
|
12
|
+
const { meta } = Astro.props;
|
|
13
|
+
---
|
|
14
|
+
<title>{meta.title}</title>
|
|
15
|
+
{meta.description && <meta name="description" content={meta.description} />}
|
|
16
|
+
<link rel="canonical" href={meta.canonical} />
|
|
17
|
+
{meta.robots && <meta name="robots" content={meta.robots} />}
|
|
18
|
+
{meta.openGraph.map(([property, content]) => <meta property={property} content={content} />)}
|
|
19
|
+
{meta.twitter.map(([name, content]) => <meta name={name} content={content} />)}
|
|
20
|
+
{meta.feeds.map((f) => <link rel="alternate" type="application/rss+xml" title={f.title} href={f.href} />)}
|
|
21
|
+
{meta.alternates?.map((a) => <link rel="alternate" hreflang={a.locale} href={a.href} />)}
|
|
22
|
+
{meta.jsonLd.map((doc) => <script type="application/ld+json" is:inline set:html={jsonLdText(doc)} />)}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* A surface section (RFC-0020): its tree drawn with the theme's components where it has them and
|
|
4
|
+
* Cloudhal's markup elsewhere. `sources` are the page's loaded entry sources for this surface
|
|
5
|
+
* (`loadSurfaceSources`); unknown, hidden and still-arriving components are left out.
|
|
6
|
+
*/
|
|
7
|
+
import type { SurfaceSection } from "@cloudhal/core-contracts";
|
|
8
|
+
import type { BlockType } from "@cloudhal/core-ts/blocks";
|
|
9
|
+
import { themeRegistry } from "../blocks.js";
|
|
10
|
+
import type { MediaContext } from "../media.js";
|
|
11
|
+
import { type SurfaceEntryCard, surfaceScope, surfaceTree, surfaceWrapper } from "../surfaces.js";
|
|
12
|
+
import SurfaceNode from "./SurfaceNode.astro";
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
section: SurfaceSection;
|
|
16
|
+
blocks?: Record<string, unknown>;
|
|
17
|
+
blockTypes?: readonly BlockType[];
|
|
18
|
+
media?: MediaContext;
|
|
19
|
+
sources?: Record<string, SurfaceEntryCard[]>;
|
|
20
|
+
}
|
|
21
|
+
const { section, blocks = {}, blockTypes, media, sources } = Astro.props;
|
|
22
|
+
const preview = media?.preview === true;
|
|
23
|
+
const tree = surfaceTree(section, { registry: themeRegistry(blockTypes), media, sources, preview });
|
|
24
|
+
const [open, close] = surfaceWrapper(
|
|
25
|
+
section,
|
|
26
|
+
tree.live ? { data: tree.data, locale: media?.locale } : undefined,
|
|
27
|
+
media?.locale,
|
|
28
|
+
);
|
|
29
|
+
---
|
|
30
|
+
{tree.root && (
|
|
31
|
+
<Fragment>
|
|
32
|
+
<Fragment set:html={open} />
|
|
33
|
+
<SurfaceNode node={tree.root} scope={surfaceScope(section)} blocks={blocks} media={media} preview={preview} />
|
|
34
|
+
<Fragment set:html={close} />
|
|
35
|
+
</Fragment>
|
|
36
|
+
)}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* One node of a surface (RFC-0020 §1): the theme's own component when its `blocks` map names the
|
|
4
|
+
* component (primitives included, e.g. `Card`), given `{ props, node, content, contentHtml, media }`
|
|
5
|
+
* with the children in its slot; else Cloudhal's markup around the children.
|
|
6
|
+
*/
|
|
7
|
+
import { renderMarkdown } from "../markdown.js";
|
|
8
|
+
import type { MediaContext } from "../media.js";
|
|
9
|
+
import {
|
|
10
|
+
blockNodeHtml,
|
|
11
|
+
CHILDREN,
|
|
12
|
+
primitiveHtml,
|
|
13
|
+
type SurfaceNode,
|
|
14
|
+
slideWrapper,
|
|
15
|
+
visibilityWrapper,
|
|
16
|
+
withMotion,
|
|
17
|
+
} from "../surfaces.js";
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
node: SurfaceNode;
|
|
21
|
+
scope: string;
|
|
22
|
+
blocks?: Record<string, unknown>;
|
|
23
|
+
media?: MediaContext;
|
|
24
|
+
preview?: boolean;
|
|
25
|
+
}
|
|
26
|
+
const { node, scope, blocks = {}, media, preview } = Astro.props;
|
|
27
|
+
type AnyComponent = (props: never) => unknown;
|
|
28
|
+
const Own = blocks[node.component] as AnyComponent | undefined;
|
|
29
|
+
const content = typeof node.props.content === "string" ? node.props.content : undefined;
|
|
30
|
+
const contentHtml = Own && content !== undefined ? renderMarkdown(content, media) : undefined;
|
|
31
|
+
let leaf = "";
|
|
32
|
+
let open = "";
|
|
33
|
+
let close = "";
|
|
34
|
+
if (!Own) {
|
|
35
|
+
const html = withMotion(
|
|
36
|
+
node.entry.kind === "block"
|
|
37
|
+
? blockNodeHtml(node, media, preview)
|
|
38
|
+
: primitiveHtml(node, scope, media),
|
|
39
|
+
node.motion,
|
|
40
|
+
);
|
|
41
|
+
const at = html.indexOf(CHILDREN);
|
|
42
|
+
if (at < 0) leaf = html;
|
|
43
|
+
else {
|
|
44
|
+
open = html.slice(0, at);
|
|
45
|
+
close = html.slice(at + CHILDREN.length);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const Self = Astro.self;
|
|
49
|
+
// A live surface's conditional component: the runtime hides and shows this wrapper (RFC-0020 §4).
|
|
50
|
+
const [shownOpen, shownClose] = visibilityWrapper(node);
|
|
51
|
+
// RFC-0024: a theme's own component keeps its markup; its motion goes on a wrapper around it.
|
|
52
|
+
const [motionOpen, motionClose] =
|
|
53
|
+
Own && node.motion ? [`<div class="ch-motion"${node.motion}>`, "</div>"] : ["", ""];
|
|
54
|
+
---
|
|
55
|
+
{shownOpen && <Fragment set:html={shownOpen} />}
|
|
56
|
+
{motionOpen && <Fragment set:html={motionOpen} />}
|
|
57
|
+
{Own ? (
|
|
58
|
+
<Own props={node.props} node={node} content={content} contentHtml={contentHtml} media={media}>
|
|
59
|
+
{node.children.map((child) => <Self node={child} scope={scope} blocks={blocks} media={media} preview={preview} />)}
|
|
60
|
+
</Own>
|
|
61
|
+
) : leaf ? (
|
|
62
|
+
<Fragment set:html={leaf} />
|
|
63
|
+
) : (
|
|
64
|
+
open && (
|
|
65
|
+
<Fragment>
|
|
66
|
+
<Fragment set:html={open} />
|
|
67
|
+
{node.children.map((child, i) => {
|
|
68
|
+
const [slideOpen, slideClose] = slideWrapper(node, i, scope, media);
|
|
69
|
+
return (
|
|
70
|
+
<Fragment>
|
|
71
|
+
{slideOpen && <Fragment set:html={slideOpen} />}
|
|
72
|
+
<Self node={child} scope={scope} blocks={blocks} media={media} preview={preview} />
|
|
73
|
+
{slideClose && <Fragment set:html={slideClose} />}
|
|
74
|
+
</Fragment>
|
|
75
|
+
);
|
|
76
|
+
})}
|
|
77
|
+
<Fragment set:html={close} />
|
|
78
|
+
</Fragment>
|
|
79
|
+
)
|
|
80
|
+
)}
|
|
81
|
+
{motionClose && <Fragment set:html={motionClose} />}
|
|
82
|
+
{shownClose && <Fragment set:html={shownClose} />}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { default as Block } from "./Block.astro";
|
|
2
|
+
export { default as Body } from "./Body.astro";
|
|
3
|
+
export { default as Comments } from "./Comments.astro";
|
|
4
|
+
export { default as ContentList } from "./ContentList.astro";
|
|
5
|
+
export { default as EntryArticle } from "./EntryArticle.astro";
|
|
6
|
+
export { default as Hero } from "./Hero.astro";
|
|
7
|
+
export { default as Image } from "./Image.astro";
|
|
8
|
+
export { default as RichText } from "./RichText.astro";
|
|
9
|
+
export { default as Sections } from "./Sections.astro";
|
|
10
|
+
export { default as SeoHead } from "./SeoHead.astro";
|
|
11
|
+
export { default as Surface } from "./Surface.astro";
|
|
12
|
+
export { default as SurfaceNode } from "./SurfaceNode.astro";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { default as Block } from "./Block.astro";
|
|
2
|
+
export { default as Body } from "./Body.astro";
|
|
3
|
+
export { default as Comments } from "./Comments.astro";
|
|
4
|
+
export { default as ContentList } from "./ContentList.astro";
|
|
5
|
+
export { default as EntryArticle } from "./EntryArticle.astro";
|
|
6
|
+
export { default as Hero } from "./Hero.astro";
|
|
7
|
+
export { default as Image } from "./Image.astro";
|
|
8
|
+
export { default as RichText } from "./RichText.astro";
|
|
9
|
+
export { default as Sections } from "./Sections.astro";
|
|
10
|
+
export { default as SeoHead } from "./SeoHead.astro";
|
|
11
|
+
export { default as Surface } from "./Surface.astro";
|
|
12
|
+
export { default as SurfaceNode } from "./SurfaceNode.astro";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site's Content-Security-Policy (set by the Cloudflare Site Worker entry on HTML responses
|
|
3
|
+
* that do not carry their own).
|
|
4
|
+
*
|
|
5
|
+
* Defence in depth for content written by agents: no inline or third-party scripts, no plugins,
|
|
6
|
+
* no foreign framing. The only client scripts a site ships of its own are Cloudhal's first-party
|
|
7
|
+
* scripts under `/_cloudhal/` (hashed, self-hosted, each switchable off): the analytics script
|
|
8
|
+
* (RFC-0006) and, on pages with an open comment form, the comments module and its proof-of-work
|
|
9
|
+
* worker (RFC-0007) — `worker-src` falls back to `script-src 'self'`. They load from 'self' and
|
|
10
|
+
* post to 'self', as Astro islands do.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SITE_CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' https: data:; font-src 'self' https: data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'";
|
|
13
|
+
/** Cloudflare Turnstile's origin (RFC-0007 §7.6). */
|
|
14
|
+
export declare const TURNSTILE_ORIGIN = "https://challenges.cloudflare.com";
|
|
15
|
+
/**
|
|
16
|
+
* The policy of a page that renders an **open** comment form on a site that opted into Turnstile
|
|
17
|
+
* (RFC-0007 §7.6): Turnstile's script and frame are allowed on that page only; every other page
|
|
18
|
+
* keeps `SITE_CSP` (the entry keeps a policy a route set).
|
|
19
|
+
*/
|
|
20
|
+
export declare function turnstileCsp(): string;
|
package/dist/src/csp.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site's Content-Security-Policy (set by the Cloudflare Site Worker entry on HTML responses
|
|
3
|
+
* that do not carry their own).
|
|
4
|
+
*
|
|
5
|
+
* Defence in depth for content written by agents: no inline or third-party scripts, no plugins,
|
|
6
|
+
* no foreign framing. The only client scripts a site ships of its own are Cloudhal's first-party
|
|
7
|
+
* scripts under `/_cloudhal/` (hashed, self-hosted, each switchable off): the analytics script
|
|
8
|
+
* (RFC-0006) and, on pages with an open comment form, the comments module and its proof-of-work
|
|
9
|
+
* worker (RFC-0007) — `worker-src` falls back to `script-src 'self'`. They load from 'self' and
|
|
10
|
+
* post to 'self', as Astro islands do.
|
|
11
|
+
*/
|
|
12
|
+
export const SITE_CSP =
|
|
13
|
+
"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' https: data:; font-src 'self' https: data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'";
|
|
14
|
+
|
|
15
|
+
/** Cloudflare Turnstile's origin (RFC-0007 §7.6). */
|
|
16
|
+
export const TURNSTILE_ORIGIN = "https://challenges.cloudflare.com";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The policy of a page that renders an **open** comment form on a site that opted into Turnstile
|
|
20
|
+
* (RFC-0007 §7.6): Turnstile's script and frame are allowed on that page only; every other page
|
|
21
|
+
* keeps `SITE_CSP` (the entry keeps a policy a route set).
|
|
22
|
+
*/
|
|
23
|
+
export function turnstileCsp() {
|
|
24
|
+
return SITE_CSP.replace("script-src 'self'", `script-src 'self' ${TURNSTILE_ORIGIN}`).replace(
|
|
25
|
+
"object-src 'none'",
|
|
26
|
+
`frame-src ${TURNSTILE_ORIGIN}; object-src 'none'`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The click-to-load video player (RFC-0015 §4): a small first-party module under `/_cloudhal/`,
|
|
3
|
+
* so the site's `script-src 'self'` stays as it is. An `embed` block renders a link card to the
|
|
4
|
+
* video; with this module, following the link swaps the card for the player's iframe, and only
|
|
5
|
+
* then does the reader's browser contact the video host (YouTube's no-cookie domain or Vimeo's
|
|
6
|
+
* player, with Do Not Track). Without JavaScript the link still opens the video page.
|
|
7
|
+
*
|
|
8
|
+
* Worker-safe: the code is a constant, written as a static asset by the build (`integration.ts`)
|
|
9
|
+
* and served from memory by `cloudhal dev` (`embed-middleware.ts`). The file name carries a
|
|
10
|
+
* version (`/_cloudhal/*` is cached as immutable): bump it with any change to the code; a test
|
|
11
|
+
* pins the code's hash to the version.
|
|
12
|
+
*/
|
|
13
|
+
/** The only hosts an `embed` player may load from (also the CSP `frame-src`). */
|
|
14
|
+
export declare const EMBED_FRAME_ORIGINS: readonly ["https://www.youtube-nocookie.com", "https://player.vimeo.com"];
|
|
15
|
+
export declare const EMBED_SCRIPT: {
|
|
16
|
+
readonly path: "/_cloudhal/embed.1.js";
|
|
17
|
+
readonly code: "const ok=/^https:\\/\\/(www\\.youtube-nocookie\\.com\\/embed\\/[A-Za-z0-9_-]{11}|player\\.vimeo\\.com\\/video\\/[0-9]{1,12})(\\?[^\"<>]*)?$/;\ndocument.addEventListener(\"click\",(e)=>{\nconst link=e.target instanceof Element?e.target.closest(\".ch-embed__link\"):null;\nconst fig=link&&link.closest(\"figure[data-embed-src]\");\nconst src=fig&&fig.getAttribute(\"data-embed-src\");\nif(!src||!ok.test(src)||e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;\ne.preventDefault();\nconst f=document.createElement(\"iframe\");\nf.src=src+(src.includes(\"?\")?\"&\":\"?\")+\"autoplay=1\";\nf.title=fig.getAttribute(\"data-embed-title\")||\"\";\nf.allow=\"autoplay; encrypted-media; picture-in-picture; fullscreen\";\nf.allowFullscreen=true;\nf.referrerPolicy=\"strict-origin-when-cross-origin\";\nf.className=\"ch-embed__frame\";\nlink.replaceWith(f);\nf.focus();\n});\n";
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The player's address for a video page, or `undefined`: YouTube (`watch?v=`, `youtu.be/`,
|
|
21
|
+
* `shorts/`, `embed/`, any youtube or youtube-nocookie host) and Vimeo (`vimeo.com/<id>`,
|
|
22
|
+
* `player.vimeo.com/video/<id>`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function embedPlayerSrc(url: string): string | undefined;
|
|
25
|
+
/** A page's CSP with the video players allowed in frames (kept as is when already there). */
|
|
26
|
+
export declare function withEmbedFrames(csp: string): string;
|
|
27
|
+
/** Response header a page sets when it shows a player (the Site Worker widens the CSP, then drops it). */
|
|
28
|
+
export declare const EMBED_HEADER = "x-cloudhal-embeds";
|
|
29
|
+
/** Whether markdown or sections may show a video player (a cheap, generous check). */
|
|
30
|
+
export declare function usesEmbeds(content: {
|
|
31
|
+
markdown?: string | undefined;
|
|
32
|
+
sections?: readonly {
|
|
33
|
+
kind: string;
|
|
34
|
+
type?: string;
|
|
35
|
+
format?: string;
|
|
36
|
+
body?: string;
|
|
37
|
+
}[] | undefined;
|
|
38
|
+
}): boolean;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The click-to-load video player (RFC-0015 §4): a small first-party module under `/_cloudhal/`,
|
|
3
|
+
* so the site's `script-src 'self'` stays as it is. An `embed` block renders a link card to the
|
|
4
|
+
* video; with this module, following the link swaps the card for the player's iframe, and only
|
|
5
|
+
* then does the reader's browser contact the video host (YouTube's no-cookie domain or Vimeo's
|
|
6
|
+
* player, with Do Not Track). Without JavaScript the link still opens the video page.
|
|
7
|
+
*
|
|
8
|
+
* Worker-safe: the code is a constant, written as a static asset by the build (`integration.ts`)
|
|
9
|
+
* and served from memory by `cloudhal dev` (`embed-middleware.ts`). The file name carries a
|
|
10
|
+
* version (`/_cloudhal/*` is cached as immutable): bump it with any change to the code; a test
|
|
11
|
+
* pins the code's hash to the version.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** The only hosts an `embed` player may load from (also the CSP `frame-src`). */
|
|
15
|
+
export const EMBED_FRAME_ORIGINS = [
|
|
16
|
+
"https://www.youtube-nocookie.com",
|
|
17
|
+
"https://player.vimeo.com",
|
|
18
|
+
] ;
|
|
19
|
+
|
|
20
|
+
const code = `const ok=/^https:\\/\\/(www\\.youtube-nocookie\\.com\\/embed\\/[A-Za-z0-9_-]{11}|player\\.vimeo\\.com\\/video\\/[0-9]{1,12})(\\?[^"<>]*)?$/;
|
|
21
|
+
document.addEventListener("click",(e)=>{
|
|
22
|
+
const link=e.target instanceof Element?e.target.closest(".ch-embed__link"):null;
|
|
23
|
+
const fig=link&&link.closest("figure[data-embed-src]");
|
|
24
|
+
const src=fig&&fig.getAttribute("data-embed-src");
|
|
25
|
+
if(!src||!ok.test(src)||e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
const f=document.createElement("iframe");
|
|
28
|
+
f.src=src+(src.includes("?")?"&":"?")+"autoplay=1";
|
|
29
|
+
f.title=fig.getAttribute("data-embed-title")||"";
|
|
30
|
+
f.allow="autoplay; encrypted-media; picture-in-picture; fullscreen";
|
|
31
|
+
f.allowFullscreen=true;
|
|
32
|
+
f.referrerPolicy="strict-origin-when-cross-origin";
|
|
33
|
+
f.className="ch-embed__frame";
|
|
34
|
+
link.replaceWith(f);
|
|
35
|
+
f.focus();
|
|
36
|
+
});
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const EMBED_SCRIPT = { path: "/_cloudhal/embed.1.js", code } ;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The player's address for a video page, or `undefined`: YouTube (`watch?v=`, `youtu.be/`,
|
|
43
|
+
* `shorts/`, `embed/`, any youtube or youtube-nocookie host) and Vimeo (`vimeo.com/<id>`,
|
|
44
|
+
* `player.vimeo.com/video/<id>`).
|
|
45
|
+
*/
|
|
46
|
+
export function embedPlayerSrc(url ) {
|
|
47
|
+
let u ;
|
|
48
|
+
try {
|
|
49
|
+
u = new URL(url);
|
|
50
|
+
} catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (u.protocol !== "https:" && u.protocol !== "http:") return undefined;
|
|
54
|
+
const host = u.hostname.toLowerCase().replace(/^(www|m)\./, "");
|
|
55
|
+
const youtube = (id ) =>
|
|
56
|
+
id && /^[A-Za-z0-9_-]{11}$/.test(id)
|
|
57
|
+
? `https://www.youtube-nocookie.com/embed/${id}`
|
|
58
|
+
: undefined;
|
|
59
|
+
const parts = u.pathname.split("/").filter(Boolean);
|
|
60
|
+
if (host === "youtube.com" || host === "youtube-nocookie.com" || host === "music.youtube.com") {
|
|
61
|
+
if (parts[0] === "watch") return youtube(u.searchParams.get("v"));
|
|
62
|
+
if (parts[0] === "embed" || parts[0] === "shorts" || parts[0] === "live")
|
|
63
|
+
return youtube(parts[1]);
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
if (host === "youtu.be") return youtube(parts[0]);
|
|
67
|
+
const vimeo = (id ) =>
|
|
68
|
+
id && /^[0-9]{1,12}$/.test(id) ? `https://player.vimeo.com/video/${id}?dnt=1` : undefined;
|
|
69
|
+
if (host === "vimeo.com") return vimeo(parts.at(-1));
|
|
70
|
+
if (host === "player.vimeo.com" && parts[0] === "video") return vimeo(parts[1]);
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A page's CSP with the video players allowed in frames (kept as is when already there). */
|
|
75
|
+
export function withEmbedFrames(csp ) {
|
|
76
|
+
const missing = EMBED_FRAME_ORIGINS.filter((o) => !csp.includes(o));
|
|
77
|
+
if (!missing.length) return csp;
|
|
78
|
+
if (/(^|;\s*)frame-src /.test(csp))
|
|
79
|
+
return csp.replace(/((?:^|;\s*)frame-src [^;]*)/, `$1 ${missing.join(" ")}`);
|
|
80
|
+
return csp.replace("object-src", `frame-src ${missing.join(" ")}; object-src`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Response header a page sets when it shows a player (the Site Worker widens the CSP, then drops it). */
|
|
84
|
+
export const EMBED_HEADER = "x-cloudhal-embeds";
|
|
85
|
+
|
|
86
|
+
/** Whether markdown or sections may show a video player (a cheap, generous check). */
|
|
87
|
+
export function usesEmbeds(content
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
) {
|
|
91
|
+
const md = (s ) => !!s && /(^|\n)\s*(?:>\s*)*::embed\b/.test(s);
|
|
92
|
+
if (md(content.markdown)) return true;
|
|
93
|
+
return (content.sections ?? []).some(
|
|
94
|
+
(s) =>
|
|
95
|
+
(s.kind === "component" && s.type === "embed") ||
|
|
96
|
+
(s.kind === "richText" && s.format === "markdown" && md(s.body)),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serves Cloudhal's constant modules in `cloudhal dev`: the click-to-load player (RFC-0015 §4)
|
|
3
|
+
* and the interaction runtime (RFC-0020 §4); builds write them as static assets (`integration.ts`).
|
|
4
|
+
*/
|
|
5
|
+
interface MiddlewareContext {
|
|
6
|
+
request: Request;
|
|
7
|
+
}
|
|
8
|
+
export declare function onRequest(context: MiddlewareContext, next: () => Promise<Response>): Promise<Response>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serves Cloudhal's constant modules in `cloudhal dev`: the click-to-load player (RFC-0015 §4)
|
|
3
|
+
* and the interaction runtime (RFC-0020 §4); builds write them as static assets (`integration.ts`).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AMBIENT_SCRIPT } from "./ambient-client.js";
|
|
7
|
+
import { CAROUSEL_SCRIPT, CAROUSEL_SCRIPT_ALIASES } from "./carousel-client.js";
|
|
8
|
+
import { CHART_SCRIPT } from "./chart.js";
|
|
9
|
+
import { CHROME_SCRIPT, CHROME_SCRIPT_ALIASES } from "./chrome-client.js";
|
|
10
|
+
import { EMBED_SCRIPT } from "./embed-client.js";
|
|
11
|
+
import { MOTION_SCRIPT, MOTION_SCRIPT_ALIASES } from "./motion-client.js";
|
|
12
|
+
import { OVERLAY_SCRIPT } from "./overlay-client.js";
|
|
13
|
+
import { PREFS_SCRIPT } from "./prefs-client.js";
|
|
14
|
+
import { SEARCH_SCRIPT } from "./search-client.js";
|
|
15
|
+
import { SURFACE_SCRIPT, SURFACE_SCRIPT_ALIASES } from "./surface-client.js";
|
|
16
|
+
|
|
17
|
+
/** Cloudhal's constant first-party modules `cloudhal dev` serves (builds write them as files). */
|
|
18
|
+
const SCRIPTS = new Map ([
|
|
19
|
+
[EMBED_SCRIPT.path, EMBED_SCRIPT.code],
|
|
20
|
+
[SURFACE_SCRIPT.path, SURFACE_SCRIPT.code],
|
|
21
|
+
...SURFACE_SCRIPT_ALIASES.map((alias) => [alias, SURFACE_SCRIPT.code] ),
|
|
22
|
+
[CHART_SCRIPT.path, CHART_SCRIPT.code],
|
|
23
|
+
[MOTION_SCRIPT.path, MOTION_SCRIPT.code],
|
|
24
|
+
...MOTION_SCRIPT_ALIASES.map((alias) => [alias, MOTION_SCRIPT.code] ),
|
|
25
|
+
[AMBIENT_SCRIPT.path, AMBIENT_SCRIPT.code],
|
|
26
|
+
[CHROME_SCRIPT.path, CHROME_SCRIPT.code],
|
|
27
|
+
...CHROME_SCRIPT_ALIASES.map((alias) => [alias, CHROME_SCRIPT.code] ),
|
|
28
|
+
[OVERLAY_SCRIPT.path, OVERLAY_SCRIPT.code],
|
|
29
|
+
[CAROUSEL_SCRIPT.path, CAROUSEL_SCRIPT.code],
|
|
30
|
+
...CAROUSEL_SCRIPT_ALIASES.map((alias) => [alias, CAROUSEL_SCRIPT.code] ),
|
|
31
|
+
[PREFS_SCRIPT.path, PREFS_SCRIPT.code],
|
|
32
|
+
// RFC-0029 §6: the search modal, on pages of deployments that answer searches.
|
|
33
|
+
[SEARCH_SCRIPT.path, SEARCH_SCRIPT.code],
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export async function onRequest(
|
|
41
|
+
context ,
|
|
42
|
+
next ,
|
|
43
|
+
) {
|
|
44
|
+
const code = SCRIPTS.get(new URL(context.request.url).pathname);
|
|
45
|
+
if (code === undefined) return next();
|
|
46
|
+
return new Response(code, {
|
|
47
|
+
headers: { "content-type": "text/javascript; charset=utf-8", "cache-control": "no-cache" },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-readable views of the published site: RSS 2.0, `sitemap.xml` and `robots.txt`. Pure
|
|
3
|
+
* functions over graph nodes (the starter's endpoints only fetch and wrap them), so the rules —
|
|
4
|
+
* published only, noindex respected, canonical elsewhere excluded — live in one tested place.
|
|
5
|
+
*/
|
|
6
|
+
import type { ContentEntry, Page, Redirect, Site } from "@cloudhal/core-contracts";
|
|
7
|
+
import type { ArchiveSummary, ArchiveView } from "./archive.js";
|
|
8
|
+
import type { AssetIndex } from "./media.js";
|
|
9
|
+
import { type TaxonomyIndex } from "./taxonomy.js";
|
|
10
|
+
export declare const FEED_LIMIT = 50;
|
|
11
|
+
export interface FeedOptions {
|
|
12
|
+
site: Site;
|
|
13
|
+
origin: string;
|
|
14
|
+
/** Newest first; drafts are dropped here even when a live source includes them. */
|
|
15
|
+
entries: ContentEntry[];
|
|
16
|
+
/** Where the feed itself is served (for `atom:link rel=self`). */
|
|
17
|
+
feedPath?: string;
|
|
18
|
+
/** Channel description (e.g. the home page's SEO description); defaults to the site name. */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Channel title; defaults to the site name. */
|
|
21
|
+
title?: string;
|
|
22
|
+
/** Channel link path (the page the feed mirrors); defaults to the home page. */
|
|
23
|
+
linkPath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The site's terms: each item lists its public category and tag names as `<category>`. Without
|
|
26
|
+
* it (or for an entry not migrated to terms) the deprecated `tags` are the categories.
|
|
27
|
+
*/
|
|
28
|
+
taxonomy?: TaxonomyIndex;
|
|
29
|
+
/** The site's assets: cover images get type, size and dimensions; `asset:` links resolve (RFC-0004 §7.7). */
|
|
30
|
+
assets?: AssetIndex;
|
|
31
|
+
/** The feed's language (RFC-0033); default: the site's default locale. */
|
|
32
|
+
locale?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Where the feed's links start (RFC-0033: `https://host/es` for a prefixed locale, a locale's
|
|
35
|
+
* own domain); default `origin`. Media URLs always use `origin`.
|
|
36
|
+
*/
|
|
37
|
+
linkOrigin?: string;
|
|
38
|
+
}
|
|
39
|
+
/** RSS 2.0 with full content (`content:encoded`), as feed readers and Ghost/WordPress readers expect. */
|
|
40
|
+
export declare function rssXml(options: FeedOptions): string;
|
|
41
|
+
/**
|
|
42
|
+
* A term's feed (`<archive>/rss.xml`, RFC-0002 §7): the archive's published entries, titled after
|
|
43
|
+
* the term, linking to its archive, described by its SEO description or intro.
|
|
44
|
+
*/
|
|
45
|
+
export declare function archiveFeedXml(options: Omit<FeedOptions, "entries" | "feedPath" | "title" | "linkPath" | "description"> & {
|
|
46
|
+
archive: ArchiveView;
|
|
47
|
+
}): string;
|
|
48
|
+
export interface SitemapUrl {
|
|
49
|
+
loc: string;
|
|
50
|
+
lastmod: string;
|
|
51
|
+
/** Every language version of the URL, itself and `x-default` included (RFC-0033). */
|
|
52
|
+
alternates?: ReadonlyArray<{
|
|
53
|
+
locale: string;
|
|
54
|
+
href: string;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* What belongs in `sitemap.xml`: published pages and entries of the default locale, and the
|
|
59
|
+
* indexable term archives (page 1 only, `lastmod` = the later of the newest listed entry and the
|
|
60
|
+
* term; see `archiveSummaries` — pass it published entries). Pages and archives asking for
|
|
61
|
+
* `noindex`, or canonicalised to another URL, are left out (a sitemap lists canonical URLs).
|
|
62
|
+
*/
|
|
63
|
+
export declare function sitemapUrls(site: Site, pages: Page[], entries: ContentEntry[], origin: string, archives?: readonly ArchiveSummary[]): SitemapUrl[];
|
|
64
|
+
/**
|
|
65
|
+
* The site's redirects as a `_redirects` file (Cloudflare Workers/Pages static assets, Netlify):
|
|
66
|
+
* static hosts that read it answer with real 301/302s, where Astro's meta-refresh pages are only a
|
|
67
|
+
* fallback. Exact redirects come first, then prefix redirects as `from` + `from/*` splats, longest
|
|
68
|
+
* first (hosts apply the first match).
|
|
69
|
+
*/
|
|
70
|
+
export declare function redirectsFile(redirects: readonly Redirect[]): string;
|
|
71
|
+
export declare function sitemapXml(urls: SitemapUrl[]): string;
|
|
72
|
+
export declare function robotsTxt(origin: string): string;
|