@cloudhal/astro-renderer 0.3.9 → 0.3.11

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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Workers Cache keys by path, not hostname, and answers before the Worker runs (#62). Every host
3
+ * routed to the site Worker — a custom domain, its workers.dev name, a redirect host (#49), the
4
+ * other sites of a multi-site Worker (RFC-0034) — would otherwise share one entry per path. `Vary:
5
+ * Host` makes it keep one variant per host.
6
+ *
7
+ * Worker-safe: no imports.
8
+ */
9
+ export declare function varyByHost(response: Response): Response;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Workers Cache keys by path, not hostname, and answers before the Worker runs (#62). Every host
3
+ * routed to the site Worker — a custom domain, its workers.dev name, a redirect host (#49), the
4
+ * other sites of a multi-site Worker (RFC-0034) — would otherwise share one entry per path. `Vary:
5
+ * Host` makes it keep one variant per host.
6
+ *
7
+ * Worker-safe: no imports.
8
+ */
9
+ export function varyByHost(response ) {
10
+ const vary = response.headers.get("vary") ?? "";
11
+ if (vary.trim() === "*" || /(^|,)\s*host\s*(,|$)/i.test(vary)) return response;
12
+ // A redirect's or a WebSocket's headers can be immutable; copy them into a fresh response.
13
+ const headers = new Headers(response.headers);
14
+ headers.set("vary", vary.trim() ? `${vary}, Host` : "Host");
15
+ return new Response(response.body, {
16
+ status: response.status,
17
+ statusText: response.statusText,
18
+ headers,
19
+ });
20
+ }
@@ -54,6 +54,7 @@ import {
54
54
  SiteAnalytics,
55
55
  } from "./analytics.js";
56
56
  import { isCloudhalCacheTag } from "./cache-tags.js";
57
+ import { varyByHost } from "./cache-vary.js";
57
58
  import { isCommentsPath, SiteComments } from "./comments.js";
58
59
  import { SITE_CSP } from "./csp.js";
59
60
  import { EMBED_HEADER, withEmbedFrames } from "./embed-client.js";
@@ -529,21 +530,25 @@ async function serveSite(
529
530
 
530
531
  export function createSiteWorker(options = {}) {
531
532
  const searchLimiter = new SearchLimiter();
533
+ async function route(request , env , ctx ) {
534
+ const url = new URL(request.url);
535
+ if (url.pathname === "/__cloudhal/purge") return purge(request, env, options.siteId);
536
+ if (url.pathname === "/__cloudhal/features") return features(request, env);
537
+ const moved = hostRedirect(request, env);
538
+ if (moved) return moved;
539
+ // RFC-0034 §4: the hostname picks the site on a multi-site Worker; everything the request
540
+ // runs (Astro's render included) then sees that site.
541
+ const choice = await siteDispatch(env, options.siteId).choose(request);
542
+ if (choice.kind === "unknown") return unknownHost();
543
+ const siteId = choice.siteId;
544
+ const run = () => serveSite({ request, env, ctx }, siteId, searchLimiter);
545
+ const response = siteId ? await withRequestSite(siteId, run) : await run();
546
+ return choice.noindex ? withNoindex(response) : response;
547
+ }
532
548
  return {
533
549
  async fetch(request , env , ctx ) {
534
- const url = new URL(request.url);
535
- if (url.pathname === "/__cloudhal/purge") return purge(request, env, options.siteId);
536
- if (url.pathname === "/__cloudhal/features") return features(request, env);
537
- const moved = hostRedirect(request, env);
538
- if (moved) return moved;
539
- // RFC-0034 §4: the hostname picks the site on a multi-site Worker; everything the request
540
- // runs (Astro's render included) then sees that site.
541
- const choice = await siteDispatch(env, options.siteId).choose(request);
542
- if (choice.kind === "unknown") return unknownHost();
543
- const siteId = choice.siteId;
544
- const run = () => serveSite({ request, env, ctx }, siteId, searchLimiter);
545
- const response = siteId ? await withRequestSite(siteId, run) : await run();
546
- return choice.noindex ? withNoindex(response) : response;
550
+ // #62: the edge cache is shared by every host this Worker answers on, unless told to vary.
551
+ return varyByHost(await route(request, env, ctx));
547
552
  },
548
553
  };
549
554
  }
@@ -27,6 +27,7 @@
27
27
  */
28
28
  import { type Protection, type RenderPage } from "@cloudhal/comments";
29
29
  import type { ContentEntry } from "@cloudhal/core-contracts";
30
+ import { type PermalinkSite } from "@cloudhal/core-ts";
30
31
  import type { CloudhalRendererConfig } from "./integration.js";
31
32
  export { type CommentStrings, commentStrings, commentsHtml } from "./comments-html.js";
32
33
  /** What `<Comments />` renders. */
@@ -65,4 +66,6 @@ export declare function commentsJsonLd(view: CommentsView | undefined, origin: s
65
66
  export declare function loadComments(config: CloudhalRendererConfig, astro: CommentsAstro, entry: ContentEntry, options?: {
66
67
  readonly locale?: string;
67
68
  readonly now?: Date;
69
+ /** The site's collection permalinks (RFC-0038), for the entry's path. */
70
+ readonly site?: PermalinkSite;
68
71
  }): Promise<CommentsView | undefined>;
@@ -35,10 +35,10 @@ import {
35
35
  withoutScriptAllowed,
36
36
  } from "@cloudhal/comments";
37
37
 
38
+ import { entryPath, } from "@cloudhal/core-ts";
38
39
  import { addCacheTags, commentsCacheTag } from "./cache-tags.js";
39
40
  import { turnstileCsp } from "./csp.js";
40
41
 
41
- import { entryPath } from "./routing.js";
42
42
 
43
43
  export { commentStrings, commentsHtml } from "./comments-html.js";
44
44
 
@@ -107,7 +107,12 @@ export async function loadComments(
107
107
  config ,
108
108
  astro ,
109
109
  entry ,
110
- options = {},
110
+ options
111
+
112
+
113
+
114
+
115
+ = {},
111
116
  ) {
112
117
  const backend = await commentsBackend(config);
113
118
  if (!backend) return undefined;
@@ -115,7 +120,7 @@ export async function loadComments(
115
120
  addCacheTags(headers, [commentsCacheTag(entry.id)]);
116
121
  const base = {
117
122
  nodeId: entry.id,
118
- path: entryPath(entry),
123
+ path: entryPath(options.site, entry),
119
124
  locale: options.locale ?? entry.locale,
120
125
  ...(config.commentsScript ? { script: config.commentsScript } : {}),
121
126
  };
@@ -38,7 +38,7 @@ import {
38
38
  } from "@cloudhal/comments";
39
39
 
40
40
 
41
- import { entryPath } from "./routing.js";
41
+ import { entryPath } from "@cloudhal/core-ts";
42
42
 
43
43
 
44
44
  export const COMMENTS_PATH = "/__cloudhal/comments";
@@ -146,7 +146,7 @@ export class SiteComments {
146
146
  return {
147
147
  nodeId: entry.id,
148
148
  collection: entry.collection,
149
- path: entryPath(entry),
149
+ path: entryPath(await source.site(), entry),
150
150
  publishedAt: entry.publishedAt ?? null,
151
151
  };
152
152
  }
@@ -1,12 +1,15 @@
1
1
  ---
2
2
  import type { ContentEntry, ContentListSection } from "@cloudhal/core-contracts";
3
+ import { entryPath } from "@cloudhal/core-ts";
4
+ import type { MediaContext } from "../media.js";
3
5
 
4
6
  interface Props {
5
7
  section: ContentListSection;
6
8
  entries: ContentEntry[];
9
+ media?: MediaContext | undefined;
7
10
  hrefFor?: (entry: ContentEntry) => string;
8
11
  }
9
- const { section, entries, hrefFor = (e) => `/${e.collection}/${e.slug}` } = Astro.props;
12
+ const { section, entries, media, hrefFor = (e) => entryPath(media?.permalinks, e) } = Astro.props;
10
13
  const sorted = [...entries]
11
14
  .sort((a, b) =>
12
15
  section.sort === "title"
package/dist/src/feeds.js CHANGED
@@ -4,11 +4,11 @@
4
4
  * published only, noindex respected, canonical elsewhere excluded — live in one tested place.
5
5
  */
6
6
 
7
+ import { entryPath } from "@cloudhal/core-ts";
7
8
 
8
9
  import { markdownText, renderBody } from "./markdown.js";
9
10
 
10
11
  import { notFoundPageIds } from "./not-found.js";
11
- import { entryPath } from "./routing.js";
12
12
  import { absoluteUrl } from "./seo.js";
13
13
  import { entryTaxonomy, } from "./taxonomy.js";
14
14
 
@@ -75,7 +75,7 @@ export function rssXml(options ) {
75
75
  const items = published(options.entries)
76
76
  .slice(0, FEED_LIMIT)
77
77
  .map((e) => {
78
- const url = `${base}${entryPath(e)}`;
78
+ const url = `${base}${entryPath(site, e)}`;
79
79
  const date = new Date(e.publishedAt ?? e.createdAt).toUTCString();
80
80
  const cover = e.coverImage?.assetId ? options.assets?.get(e.coverImage.assetId) : undefined;
81
81
  const image = cover
@@ -181,7 +181,7 @@ export function sitemapUrls(
181
181
  urls.push({ loc: own, lastmod: page.updatedAt });
182
182
  }
183
183
  for (const entry of published(entries)) {
184
- const path = entryPath(entry);
184
+ const path = entryPath(site, entry);
185
185
  if (entry.locale !== site.defaultLocale || seen.has(path)) continue;
186
186
  seen.add(path);
187
187
  urls.push({ loc: `${origin}${path}`, lastmod: entry.updatedAt });
@@ -27,6 +27,8 @@ export function hostRedirect(request , env )
27
27
  headers: {
28
28
  location: `https://${to}${url.pathname}${url.search}`,
29
29
  "cache-control": "public, max-age=86400",
30
+ // Never in the edge cache (#62): it is shared with the hosts this one redirects to.
31
+ "cloudflare-cdn-cache-control": "no-store",
30
32
  },
31
33
  });
32
34
  }
@@ -4,17 +4,17 @@
4
4
  * single-locale functions in `feeds.ts`; this module only loops over locales and localizes URLs.
5
5
  */
6
6
 
7
+ import { entryPath, } from "@cloudhal/core-ts";
7
8
  import { archiveSummaries } from "./archive.js";
8
9
  import { FEED_LIMIT, rssXml, sitemapUrls } from "./feeds.js";
9
10
  import { hostLocale, localeUrl } from "./locales.js";
10
11
  import { loadAssetIndex } from "./media.js";
11
12
  import { notFoundPageIds } from "./not-found.js";
12
- import { entryPath } from "./routing.js";
13
13
 
14
14
  import { loadTaxonomyIndex } from "./taxonomy.js";
15
15
 
16
16
 
17
- const pathOf = (n ) => ("path" in n ? n.path : entryPath(n));
17
+ const pathOf = (site , n ) => ("path" in n ? n.path : entryPath(site, n));
18
18
 
19
19
  /** The locales a host serves: its own one, or every locale without a domain of its own. */
20
20
  export function hostLocales(site , host ) {
@@ -46,7 +46,7 @@ function alternateIndex(site , nodes , origin )
46
46
  const out = members
47
47
  .filter((m) => site.locales.includes(m.locale))
48
48
  .sort((a, b) => site.locales.indexOf(a.locale) - site.locales.indexOf(b.locale))
49
- .map((m) => ({ locale: m.locale, href: localeUrl(site, m.locale, pathOf(m), origin) }));
49
+ .map((m) => ({ locale: m.locale, href: localeUrl(site, m.locale, pathOf(site, m), origin) }));
50
50
  const fallback = out.find((a) => a.locale === site.defaultLocale);
51
51
  return fallback ? [...out, { locale: "x-default", href: fallback.href }] : out;
52
52
  };
@@ -72,7 +72,9 @@ export async function localizedSitemap(
72
72
  const archives = archiveSummaries(await loadTaxonomyIndex(source, locale), entries);
73
73
  // `sitemapUrls` lists the site's default locale: view the site as if `locale` were it.
74
74
  const urls = sitemapUrls({ ...site, defaultLocale: locale }, pages, entries, origin, archives);
75
- const byPath = new Map(nodes.filter((n) => n.locale === locale).map((n) => [pathOf(n), n]));
75
+ const byPath = new Map(
76
+ nodes.filter((n) => n.locale === locale).map((n) => [pathOf(site, n), n]),
77
+ );
76
78
  for (const u of urls) {
77
79
  const path = u.loc.slice(origin.length) || "/";
78
80
  const node = byPath.get(path);
@@ -127,7 +129,7 @@ export async function llmsTxt(
127
129
  const entries = (await source.allEntries(locale)).filter(visible).slice(0, FEED_LIMIT * 4);
128
130
  const line = (n ) => {
129
131
  const summary = "summary" in n && n.summary ? `: ${n.summary.replace(/\s+/g, " ")}` : "";
130
- return `- [${n.title}](${localeUrl(site, locale, pathOf(n), origin)})${summary}`;
132
+ return `- [${n.title}](${localeUrl(site, locale, pathOf(site, n), origin)})${summary}`;
131
133
  };
132
134
  const others = site.locales.filter((l) => l !== locale);
133
135
  const description = home?.seo?.description ?? site.name;
@@ -7,7 +7,7 @@
7
7
  * links to the same locale. Worker-safe.
8
8
  */
9
9
 
10
- import { termSlug } from "@cloudhal/core-ts";
10
+ import { entryPath, termSlug } from "@cloudhal/core-ts";
11
11
 
12
12
 
13
13
 
@@ -114,7 +114,7 @@ export function localeUrl(site , locale , path , origin
114
114
 
115
115
 
116
116
 
117
- const pathOf = (n ) => ("path" in n ? n.path : `/${n.collection}/${n.slug}`);
117
+ const pathOf = (site , n ) => ("path" in n ? n.path : entryPath(site, n));
118
118
 
119
119
  /** The visible members of `group` in this source (pages, or entries in the site's locales). */
120
120
  async function groupMembers(
@@ -159,7 +159,7 @@ export async function alternatesFor(
159
159
  );
160
160
  const out = own.map((m) => ({
161
161
  locale: m.locale,
162
- href: localeUrl(site, m.locale, pathOf(m), origin),
162
+ href: localeUrl(site, m.locale, pathOf(site, m), origin),
163
163
  current: m.id === node.id,
164
164
  ...(m.id === group ? { original: true } : {}),
165
165
  }));
@@ -169,7 +169,7 @@ export async function alternatesFor(
169
169
  if (peerSite.locales.includes(m.locale) && !out.some((a) => a.locale === m.locale))
170
170
  out.push({
171
171
  locale: m.locale,
172
- href: localeUrl(peerSite, m.locale, pathOf(m), peer.origin),
172
+ href: localeUrl(peerSite, m.locale, pathOf(peerSite, m), peer.origin),
173
173
  current: false,
174
174
  ...(m.id === group ? { original: true } : {}),
175
175
  });
@@ -222,7 +222,7 @@ export async function linkLocalizer(
222
222
  const map = new Map ();
223
223
  for (const n of [...pages.filter((p) => p.locale === def), ...entries]) {
224
224
  const twin = byGroup.get(`${"path" in n ? "p" : "e"}:${n.translation?.group ?? n.id}`);
225
- map.set(pathOf(n), twin ? here(pathOf(twin)) : home(pathOf(n)));
225
+ map.set(pathOf(site, n), twin ? here(pathOf(site, twin)) : home(pathOf(site, n)));
226
226
  }
227
227
  const archive = archiveLocalizer(taxonomies, terms, locale, def);
228
228
  return (path) => map.get(path) ?? (archive(path) ? here(archive(path) ) : here(path));
@@ -9,6 +9,7 @@
9
9
  * static builds, previews, workers.dev) is a passthrough: the original URL, no `srcset`.
10
10
  */
11
11
  import type { Asset, ImageRef } from "@cloudhal/core-contracts";
12
+ import type { PermalinkSite } from "@cloudhal/core-ts";
12
13
  import type { BlockRegistry } from "@cloudhal/core-ts/blocks";
13
14
  import type { IconSet } from "@cloudhal/core-ts/icons";
14
15
  export type ImageTransform = "cdn-cgi" | "none";
@@ -37,6 +38,8 @@ export interface MediaContext {
37
38
  } | undefined;
38
39
  /** RFC-0028 §4: the page's placeholder allowance, shared by every image it draws. */
39
40
  readonly budget?: PlaceholderBudget | undefined;
41
+ /** RFC-0038: the site's collection permalinks, for links to entries (`entryPath`). */
42
+ readonly permalinks?: PermalinkSite | undefined;
40
43
  }
41
44
  export interface ImageAttributeOptions {
42
45
  locale: string;
package/dist/src/media.js CHANGED
@@ -10,6 +10,7 @@
10
10
  */
11
11
 
12
12
 
13
+
13
14
 
14
15
 
15
16
  import { assetUrl, formatBytes, MEDIA_TYPES, mediaPath } from "@cloudhal/core-ts/media";
@@ -45,6 +46,8 @@ export const WIDTH_LADDER = [320, 640, 960, 1280, 1600, 1920,
45
46
 
46
47
   
47
48
 
49
+
50
+
48
51
 
49
52
 
50
53
 
@@ -63,8 +63,9 @@ export interface LookupData {
63
63
  /**
64
64
  * A `MenuLookup` over a site's nodes (§7.1 table). Term items follow `archiveState` (200 only when
65
65
  * the archive lists entries the site serves in the locale); a collection index comes from the theme
66
- * hook, else the first served page (in `Site.pageIds` order) of the locale with an unfiltered
67
- * `contentList` of that collection (answer 5).
66
+ * hook, else a served page at the collection's permalink prefix (RFC-0038 §5), else the first
67
+ * served page (in `Site.pageIds` order) of the locale with an unfiltered `contentList` of that
68
+ * collection (answer 5).
68
69
  */
69
70
  export declare function menuLookup(data: LookupData): MenuLookup;
70
71
  /** The shown part of a resolved menu. */
@@ -19,7 +19,13 @@
19
19
 
20
20
 
21
21
 
22
- import { normalisePath, termName } from "@cloudhal/core-ts";
22
+ import {
23
+ collectionPermalink,
24
+ entryPath,
25
+ normalisePath,
26
+ permalinkPrefix,
27
+ termName,
28
+ } from "@cloudhal/core-ts";
23
29
  import {
24
30
 
25
31
 
@@ -79,14 +85,12 @@ import { archiveMembers, archivePath, taxonomyIndex } from "./taxonomy.js";
79
85
 
80
86
 
81
87
 
82
- /** `/<collection>/<slug>`. */
83
- const entryHref = (e ) => `/${e.collection}/${e.slug}`;
84
-
85
88
  /**
86
89
  * A `MenuLookup` over a site's nodes (§7.1 table). Term items follow `archiveState` (200 only when
87
90
  * the archive lists entries the site serves in the locale); a collection index comes from the theme
88
- * hook, else the first served page (in `Site.pageIds` order) of the locale with an unfiltered
89
- * `contentList` of that collection (answer 5).
91
+ * hook, else a served page at the collection's permalink prefix (RFC-0038 §5), else the first
92
+ * served page (in `Site.pageIds` order) of the locale with an unfiltered `contentList` of that
93
+ * collection (answer 5).
90
94
  */
91
95
  export function menuLookup(data ) {
92
96
  const served = (status ) =>
@@ -124,7 +128,7 @@ export function menuLookup(data ) {
124
128
  },
125
129
  entry: (id) => {
126
130
  const e = entries.get(id);
127
- return e ? node(e, entryHref(e)) : undefined;
131
+ return e ? node(e, entryPath(data.site, e)) : undefined;
128
132
  },
129
133
  term: (id, locale) => {
130
134
  const term = terms.get(id);
@@ -141,14 +145,19 @@ export function menuLookup(data ) {
141
145
  collectionIndex: (collection, locale) => {
142
146
  const hooked = data.collectionIndex?.(collection, locale);
143
147
  if (hooked !== undefined) return hooked;
144
- return [...data.pages]
148
+ const shown = [...data.pages]
145
149
  .filter((p) => p.locale === locale && served(p.status))
146
- .sort((a, b) => (order.get(a.id) ?? 1e9) - (order.get(b.id) ?? 1e9))
147
- .find((p) =>
150
+ .sort((a, b) => (order.get(a.id) ?? 1e9) - (order.get(b.id) ?? 1e9));
151
+ // RFC-0038 §5: a page at the template's fixed prefix (`/docs` for `/docs/{slug}`) first.
152
+ const prefix = permalinkPrefix(collectionPermalink(data.site, collection));
153
+ return (
154
+ shown.find((p) => p.path === prefix) ??
155
+ shown.find((p) =>
148
156
  p.sections.some(
149
157
  (s) => s.kind === "contentList" && s.collection === collection && !s.filter,
150
158
  ),
151
- )?.path;
159
+ )
160
+ )?.path;
152
161
  },
153
162
  };
154
163
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
 
9
9
 
10
+ import { entryPath } from "@cloudhal/core-ts";
10
11
  import {
11
12
 
12
13
 
@@ -19,7 +20,6 @@ import { renderComponentSection } from "./blocks.js";
19
20
  import { gateNotice } from "./gates.js";
20
21
  import { renderBody, renderEntryArticle, renderMarkdown, safeHref, safeSrc } from "./markdown.js";
21
22
  import { assetCaption, imageAttributes, imgHtml, } from "./media.js";
22
- import { entryPath } from "./routing.js";
23
23
  import { archiveHead, siteOrigin } from "./seo.js";
24
24
  import { pickEntries, renderSurface, surfaceSources } from "./surfaces.js";
25
25
  import {
@@ -126,7 +126,7 @@ export function renderSectionHtml(
126
126
  const items = list
127
127
  .map(
128
128
  (e) =>
129
- `<li><a href="/${esc(e.collection)}/${esc(e.slug)}">${esc(e.title)}</a>${e.summary ? `<p>${esc(e.summary)}</p>` : ""}</li>`,
129
+ `<li><a href="${esc(entryPath(media?.permalinks, e))}">${esc(e.title)}</a>${e.summary ? `<p>${esc(e.summary)}</p>` : ""}</li>`,
130
130
  )
131
131
  .join("");
132
132
  return `<section class="ch-contentlist" data-section-id="${esc(section.id)}" data-kind="contentList" data-collection="${esc(section.collection)}">${
@@ -142,7 +142,10 @@ export function renderSectionHtml(
142
142
  // filter is applied on the site; a preview shows the collection's newest).
143
143
  case "surface": {
144
144
  const sources = Object.fromEntries(
145
- surfaceSources(section).map((q) => [q.key, pickEntries(entries[q.collection] ?? [], q)]),
145
+ surfaceSources(section).map((q) => [
146
+ q.key,
147
+ pickEntries(entries[q.collection] ?? [], q, media?.permalinks),
148
+ ]),
146
149
  );
147
150
  return renderSurface(section, { ...(media ? { media } : {}), sources, preview: true });
148
151
  }
@@ -210,7 +213,13 @@ export function renderPagePreview(
210
213
 
211
214
  /** Previews resolve `asset:` references and asset-backed images, never through transformations. */
212
215
  function previewMedia(site , media ) {
213
- return { locale: site.defaultLocale, defaultLocale: site.defaultLocale, ...media, preview: true };
216
+ return {
217
+ locale: site.defaultLocale,
218
+ defaultLocale: site.defaultLocale,
219
+ permalinks: site,
220
+ ...media,
221
+ preview: true,
222
+ };
214
223
  }
215
224
 
216
225
  /**
@@ -228,7 +237,7 @@ export function renderEntryPreview(
228
237
  renderEntryArticle(entry, site.defaultLocale, previewMedia(site, media));
229
238
  return {
230
239
  title: entry.title,
231
- path: `/${entry.collection}/${entry.slug}`,
240
+ path: entryPath(site, entry),
232
241
  html: document(site, entry.title, entry.summary, body),
233
242
  };
234
243
  }
@@ -418,7 +427,7 @@ export function renderArchivePreview(
418
427
  : `<ul class="ch-entrylist">${view.entries
419
428
  .map(
420
429
  (e) =>
421
- `<li><a href="${esc(entryPath(e))}">${esc(e.title)}</a>${e.summary ? `<p>${esc(e.summary)}</p>` : ""}${
430
+ `<li><a href="${esc(entryPath(site, e))}">${esc(e.title)}</a>${e.summary ? `<p>${esc(e.summary)}</p>` : ""}${
422
431
  e.publishedAt
423
432
  ? `<time datetime="${esc(e.publishedAt)}">${esc(date(e.publishedAt))}</time>`
424
433
  : ""
@@ -1,16 +1,19 @@
1
1
  /**
2
2
  * How URLs map onto the graph, shared by the starter's routes, sitemaps, feeds and previews: a
3
- * Page owns its `path`; an entry lives at `/<collection>/<slug>`; a term archive at
3
+ * Page owns its `path`; an entry lives at its collection's permalink (core-ts `entryPath`,
4
+ * `/<collection>/<slug>` by default, RFC-0038); a term archive at
4
5
  * `<basePath>/<slug>[/page/<n>|/rss.xml]` (RFC-0002 §7). Pages win when several could answer, so a
5
6
  * page at `/posts/x` is never shadowed by an article. Anything else asks the site's redirects
6
7
  * before it is a 404 (or a 410 for a retired term).
7
8
  */
8
9
  import type { ContentEntry, Page, Redirect, Site } from "@cloudhal/core-contracts";
10
+ import { entryAt, entryPath } from "@cloudhal/core-ts";
9
11
  import { type ArchiveSummary, type ArchiveView } from "./archive.js";
10
12
  import { type SearchView } from "./search.js";
11
13
  import type { GraphSource } from "./source.js";
12
14
  import { type TaxonomyIndex } from "./taxonomy.js";
13
- export declare function entryPath(entry: Pick<ContentEntry, "collection" | "slug">): string;
15
+ /** Themes link entries with core-ts's `entryPath(site, entry)`; re-exported for them. */
16
+ export { entryAt, entryPath };
14
17
  export type Resolved = {
15
18
  kind: "page";
16
19
  page: Page;
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * How URLs map onto the graph, shared by the starter's routes, sitemaps, feeds and previews: a
3
- * Page owns its `path`; an entry lives at `/<collection>/<slug>`; a term archive at
3
+ * Page owns its `path`; an entry lives at its collection's permalink (core-ts `entryPath`,
4
+ * `/<collection>/<slug>` by default, RFC-0038); a term archive at
4
5
  * `<basePath>/<slug>[/page/<n>|/rss.xml]` (RFC-0002 §7). Pages win when several could answer, so a
5
6
  * page at `/posts/x` is never shadowed by an article. Anything else asks the site's redirects
6
7
  * before it is a 404 (or a 410 for a retired term).
7
8
  */
8
9
 
9
- import { normalisePath, SEARCH_PATH, termName } from "@cloudhal/core-ts";
10
+ import { entryAt, entryPath, normalisePath, SEARCH_PATH, termName } from "@cloudhal/core-ts";
10
11
  import {
11
12
 
12
13
 
@@ -31,33 +32,46 @@ import {
31
32
  taxonomyIndex,
32
33
  } from "./taxonomy.js";
33
34
 
34
- export function entryPath(entry ) {
35
- return `/${entry.collection}/${entry.slug}`;
36
- }
35
+ /** Themes link entries with core-ts's `entryPath(site, entry)`; re-exported for them. */
36
+ export { entryAt, entryPath };
37
37
 
38
38
 
39
39
 
40
+ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
41
+
40
42
  /** The page or entry at `path` (leading slash, no trailing slash except "/") in `locale`, if any. */
41
43
  export async function resolvePath(
42
44
  source ,
43
45
  path ,
44
46
  locale ,
45
47
  ) {
46
- const page = await source.pageByPath(path, locale);
48
+ return resolveIn(source, path, { locale });
49
+ }
50
+
51
+ /** `resolvePath` with the site already loaded (`resolveRoute` has it). */
52
+ async function resolveIn(
53
+ source ,
54
+ path ,
55
+ options ,
56
+ ) {
57
+ const page = await source.pageByPath(path, options.locale);
47
58
  if (page) return { kind: "page", page };
48
- const m = /^\/([a-z0-9]+(?:-[a-z0-9]+)*)\/([a-z0-9]+(?:-[a-z0-9]+)*)$/.exec(path);
49
- if (!m) return undefined;
50
- const entry = await source.entryBySlug(m[1] , m[2] , locale);
59
+ const at = entryAt(options.site ?? (await source.site()), path);
60
+ if (!at || !SLUG.test(at.collection) || !SLUG.test(at.slug)) return undefined;
61
+ const entry = await source.entryBySlug(at.collection, at.slug, options.locale);
51
62
  return entry ? { kind: "entry", entry } : undefined;
52
63
  }
53
64
 
54
65
  /** Every page and entry path of a locale (default: the site's), as graph paths without prefix. */
55
66
  export async function routablePaths(source , locale ) {
56
67
  const pages = await source.pages();
57
- const loc = locale ?? (await source.site()).defaultLocale;
68
+ const site = await source.site();
69
+ const loc = locale ?? site.defaultLocale;
58
70
  const pagePaths = pages.filter((p) => p.locale === loc).map((p) => p.path);
59
71
  const taken = new Set(pagePaths);
60
- const entryPaths = (await source.allEntries(loc)).map(entryPath).filter((p) => !taken.has(p));
72
+ const entryPaths = (await source.allEntries(loc))
73
+ .map((e) => entryPath(site, e))
74
+ .filter((p) => !taken.has(p));
61
75
  return [...pagePaths, ...entryPaths];
62
76
  }
63
77
 
@@ -148,7 +162,7 @@ export async function resolveRoute(
148
162
  const path = normalisePath(requestPath);
149
163
  const site = await source.site();
150
164
  const locale = options.locale ?? site.defaultLocale;
151
- const resolved = await resolvePath(source, path, locale);
165
+ const resolved = await resolveIn(source, path, { locale, site });
152
166
  if (resolved) return resolved;
153
167
  if (path === SEARCH_PATH && source.search) {
154
168
  const { query, page } = searchRequest(options.search ?? "");
package/dist/src/seo.js CHANGED
@@ -4,10 +4,10 @@
4
4
  * gets the same, tested output and themes only decide where to render `<SeoHead>`.
5
5
  */
6
6
 
7
+ import { entryPath } from "@cloudhal/core-ts";
7
8
 
8
9
  import { inlineMarkdownText, markdownText, safeSrc } from "./markdown.js";
9
10
  import { assetAlt, imageObject, socialImageUrl } from "./media.js";
10
- import { entryPath } from "./routing.js";
11
11
  import { entryTaxonomy, } from "./taxonomy.js";
12
12
 
13
13
 
@@ -227,7 +227,7 @@ export function entryHead(
227
227
  media ,
228
228
  comments ,
229
229
  ) {
230
- const url = `${origin}${entryPath(entry)}`;
230
+ const url = `${origin}${entryPath(site, entry)}`;
231
231
  const description = clip(entry.summary);
232
232
  const image = cardImage(entry.coverImage, origin, entry.locale, media);
233
233
  const title = `${entry.title} · ${site.name}`;
@@ -384,7 +384,7 @@ export function archiveHead(
384
384
  itemListElement: view.entries.map((e, i) => ({
385
385
  "@type": "ListItem",
386
386
  position: (view.page - 1) * view.perPage + i + 1,
387
- url: `${origin}${entryPath(e)}`,
387
+ url: `${origin}${entryPath(site, e)}`,
388
388
  })),
389
389
  },
390
390
  },
@@ -255,6 +255,7 @@ export class LiveSource {
255
255
  const rows = searchDocuments({
256
256
  locales: [locale],
257
257
  defaultLocale: site.defaultLocale,
258
+ site,
258
259
  entries,
259
260
  pages: pages.filter((p) => p.locale === locale),
260
261
  taxonomies,
@@ -4,6 +4,7 @@
4
4
  * out. Worker-safe.
5
5
  */
6
6
  import type { ContentEntry, SurfaceSection } from "@cloudhal/core-contracts";
7
+ import { type PermalinkSite } from "@cloudhal/core-ts";
7
8
  import type { BlockRegistry } from "@cloudhal/core-ts/blocks";
8
9
  import { type CatalogEntry } from "@cloudhal/core-ts/surfaces";
9
10
  import type { MediaContext } from "../media.js";
@@ -58,7 +59,7 @@ export interface SurfaceEntryCard {
58
59
  published?: string;
59
60
  collection: string;
60
61
  }
61
- export declare function surfaceEntryCard(e: ContentEntry): SurfaceEntryCard;
62
+ export declare function surfaceEntryCard(site: PermalinkSite | undefined, e: ContentEntry): SurfaceEntryCard;
62
63
  /** The entry queries in a surface's data, by data key (`$source: "entries"`). */
63
64
  export declare function surfaceSources(section: SurfaceSection): {
64
65
  key: string;
@@ -71,7 +72,7 @@ export declare function surfaceSources(section: SurfaceSection): {
71
72
  export declare function pickEntries(entries: readonly ContentEntry[], q: {
72
73
  sort: string;
73
74
  limit: number;
74
- }): SurfaceEntryCard[];
75
+ }, site?: PermalinkSite): SurfaceEntryCard[];
75
76
  export interface SurfaceContext {
76
77
  readonly media?: MediaContext | undefined;
77
78
  /** The deployment's registry; defaults to `media.blocks`, else the built-ins. */
@@ -95,6 +96,7 @@ export declare function surfaceProblems(section: SurfaceSection, fenceIssues?: r
95
96
  export declare function surfaceTree(section: SurfaceSection, ctx?: SurfaceContext): SurfaceTree;
96
97
  /** What a page's source offers for entry sources (`GraphSource`). */
97
98
  export interface SurfaceEntrySource {
99
+ site(): Promise<PermalinkSite>;
98
100
  entries(collection: string): Promise<ContentEntry[]>;
99
101
  entriesByFilter(filter: string): Promise<ContentEntry[]>;
100
102
  }
@@ -4,6 +4,7 @@
4
4
  * out. Worker-safe.
5
5
  */
6
6
 
7
+ import { entryPath, } from "@cloudhal/core-ts";
7
8
 
8
9
  import {
9
10
 
@@ -69,10 +70,13 @@ import { motionAttrs } from "./motion.js";
69
70
 
70
71
 
71
72
 
72
- export function surfaceEntryCard(e ) {
73
+ export function surfaceEntryCard(
74
+ site ,
75
+ e ,
76
+ ) {
73
77
  return {
74
78
  id: e.id,
75
- href: `/${e.collection}/${e.slug}`,
79
+ href: entryPath(site, e),
76
80
  title: e.title,
77
81
  collection: e.collection,
78
82
  ...(e.summary ? { summary: e.summary } : {}),
@@ -104,6 +108,7 @@ export function surfaceSources(
104
108
  export function pickEntries(
105
109
  entries ,
106
110
  q ,
111
+ site ,
107
112
  ) {
108
113
  const at = (e ) => e.publishedAt ?? e.createdAt;
109
114
  // The page's source already holds only what this response may show (published, or the draft
@@ -117,7 +122,7 @@ export function pickEntries(
117
122
  : at(b).localeCompare(at(a)),
118
123
  )
119
124
  .slice(0, q.limit)
120
- .map(surfaceEntryCard);
125
+ .map((e) => surfaceEntryCard(site, e));
121
126
  }
122
127
 
123
128
 
@@ -290,6 +295,7 @@ export function surfaceTree(section , ctx = {})
290
295
 
291
296
  /** What a page's source offers for entry sources (`GraphSource`). */
292
297
 
298
+
293
299
 
294
300
 
295
301
 
@@ -303,6 +309,7 @@ export async function loadSurfaceSources(
303
309
  sections ,
304
310
  ) {
305
311
  const out = {};
312
+ const site = sections.some((s) => s.kind === "surface") ? await source.site() : undefined;
306
313
  for (const s of sections) {
307
314
  if (s.kind !== "surface") continue;
308
315
  const section = s ;
@@ -313,7 +320,7 @@ export async function loadSurfaceSources(
313
320
  .entriesByFilter(`collection:${q.collection}+${q.filter}`)
314
321
  .catch(() => [] )
315
322
  : await source.entries(q.collection);
316
- loaded[q.key] = pickEntries(list, q);
323
+ loaded[q.key] = pickEntries(list, q, site);
317
324
  }
318
325
  out[section.id] = loaded;
319
326
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudhal/astro-renderer",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "Render a Cloudhal Site Graph with Astro: data sources (live/snapshot), section components and the cloudhal() integration",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://cloudhal.dev",
@@ -179,14 +179,14 @@
179
179
  "README.md"
180
180
  ],
181
181
  "dependencies": {
182
- "@cloudhal/core-contracts": "0.3.9",
183
- "@cloudhal/core-ts": "0.3.9",
184
- "@cloudhal/storage": "0.3.9",
182
+ "@cloudhal/core-contracts": "0.3.11",
183
+ "@cloudhal/core-ts": "0.3.11",
184
+ "@cloudhal/storage": "0.3.11",
185
185
  "marked": "^18.1.0",
186
186
  "parse5": "8.0.1",
187
- "@cloudhal/analytics": "0.3.9",
187
+ "@cloudhal/analytics": "0.3.11",
188
188
  "vite": "^8.3.3",
189
- "@cloudhal/comments": "0.3.9"
189
+ "@cloudhal/comments": "0.3.11"
190
190
  },
191
191
  "peerDependencies": {
192
192
  "astro": "^7.3.0",