@cloudhal/astro-renderer 0.3.10 → 0.3.12
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/dist/src/comments-view.d.ts +3 -0
- package/dist/src/comments-view.js +8 -3
- package/dist/src/comments.js +2 -2
- package/dist/src/components/ContentList.astro +4 -1
- package/dist/src/feeds.js +3 -3
- package/dist/src/locale-feeds.js +7 -5
- package/dist/src/locales.d.ts +1 -7
- package/dist/src/locales.js +8 -23
- package/dist/src/media.d.ts +3 -0
- package/dist/src/media.js +3 -0
- package/dist/src/navigation.d.ts +3 -2
- package/dist/src/navigation.js +20 -11
- package/dist/src/preview.js +15 -6
- package/dist/src/routing.d.ts +5 -2
- package/dist/src/routing.js +26 -12
- package/dist/src/seo.js +3 -3
- package/dist/src/source.js +1 -0
- package/dist/src/surfaces/tree.d.ts +4 -2
- package/dist/src/surfaces/tree.js +11 -4
- package/package.json +6 -6
|
@@ -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
|
};
|
package/dist/src/comments.js
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
} from "@cloudhal/comments";
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
import { entryPath } from "
|
|
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) =>
|
|
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 });
|
package/dist/src/locale-feeds.js
CHANGED
|
@@ -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(
|
|
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;
|
package/dist/src/locales.d.ts
CHANGED
|
@@ -11,8 +11,7 @@ import type { HeadMeta } from "./seo.js";
|
|
|
11
11
|
import type { GraphSource } from "./source.js";
|
|
12
12
|
/** `<html dir>` for a locale. Kurdish written in Latin (`ku-Latn`) is the one exception handled. */
|
|
13
13
|
export declare function textDirection(locale: string): "ltr" | "rtl";
|
|
14
|
-
|
|
15
|
-
export declare function localeRouting(site: Site): Routing;
|
|
14
|
+
export { localeRouting, localeUrl, localizedPath } from "@cloudhal/core-ts/locale-paths";
|
|
16
15
|
/** The locale a host serves on its own (`localization.domains`), if any. */
|
|
17
16
|
export declare function hostLocale(site: Site, host: string): string | undefined;
|
|
18
17
|
export interface LocaleRequest {
|
|
@@ -29,10 +28,6 @@ export interface LocaleRequest {
|
|
|
29
28
|
* redirect to the canonical URL; a locale served by its own domain is never a prefix.
|
|
30
29
|
*/
|
|
31
30
|
export declare function localeRequest(site: Site, host: string, path: string): LocaleRequest;
|
|
32
|
-
/** A graph path as a URL path of `locale` on the site's own host (no domain mapping). */
|
|
33
|
-
export declare function localizedPath(site: Site, locale: string, path: string): string;
|
|
34
|
-
/** The absolute URL of a graph path in `locale`: its own domain when it has one. */
|
|
35
|
-
export declare function localeUrl(site: Site, locale: string, path: string, origin: string): string;
|
|
36
31
|
/** One language version of a page or entry for `hreflang` and the language switcher. */
|
|
37
32
|
export interface Alternate {
|
|
38
33
|
/** BCP 47 locale, or `x-default`. */
|
|
@@ -84,4 +79,3 @@ export declare function localizeHead(meta: HeadMeta, site: Site, input: {
|
|
|
84
79
|
alternates: readonly Alternate[];
|
|
85
80
|
translation?: Localized["translation"];
|
|
86
81
|
}): HeadMeta;
|
|
87
|
-
export {};
|
package/dist/src/locales.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
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
|
+
import { localeRouting, localeUrl, localizedPath } from "@cloudhal/core-ts/locale-paths";
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
@@ -36,11 +37,8 @@ export function textDirection(locale ) {
|
|
|
36
37
|
return RTL.has(language) ? "rtl" : "ltr";
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export function localeRouting(site ) {
|
|
42
|
-
return site.localization?.routing ?? "prefix-except-default";
|
|
43
|
-
}
|
|
40
|
+
// The URL helpers live in core-ts (Studio builds the same addresses); re-exported unchanged.
|
|
41
|
+
export { localeRouting, localeUrl, localizedPath } from "@cloudhal/core-ts/locale-paths";
|
|
44
42
|
|
|
45
43
|
/** The locale a host serves on its own (`localization.domains`), if any. */
|
|
46
44
|
export function hostLocale(site , host ) {
|
|
@@ -89,19 +87,6 @@ export function localeRequest(site , host , path )
|
|
|
89
87
|
return { locale: site.defaultLocale, path };
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
/** A graph path as a URL path of `locale` on the site's own host (no domain mapping). */
|
|
93
|
-
export function localizedPath(site , locale , path ) {
|
|
94
|
-
const prefixed = localeRouting(site) === "prefix-all" || locale !== site.defaultLocale;
|
|
95
|
-
if (!prefixed) return path;
|
|
96
|
-
return path === "/" ? `/${locale}` : `/${locale}${path}`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** The absolute URL of a graph path in `locale`: its own domain when it has one. */
|
|
100
|
-
export function localeUrl(site , locale , path , origin ) {
|
|
101
|
-
const domain = site.localization?.domains?.[locale];
|
|
102
|
-
return domain ? `https://${domain}${path}` : `${origin}${localizedPath(site, locale, path)}`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
90
|
/** One language version of a page or entry for `hreflang` and the language switcher. */
|
|
106
91
|
|
|
107
92
|
|
|
@@ -114,7 +99,7 @@ export function localeUrl(site , locale , path , origin
|
|
|
114
99
|
|
|
115
100
|
|
|
116
101
|
|
|
117
|
-
const pathOf = (n ) => ("path" in n ? n.path :
|
|
102
|
+
const pathOf = (site , n ) => ("path" in n ? n.path : entryPath(site, n));
|
|
118
103
|
|
|
119
104
|
/** The visible members of `group` in this source (pages, or entries in the site's locales). */
|
|
120
105
|
async function groupMembers(
|
|
@@ -159,7 +144,7 @@ export async function alternatesFor(
|
|
|
159
144
|
);
|
|
160
145
|
const out = own.map((m) => ({
|
|
161
146
|
locale: m.locale,
|
|
162
|
-
href: localeUrl(site, m.locale, pathOf(m), origin),
|
|
147
|
+
href: localeUrl(site, m.locale, pathOf(site, m), origin),
|
|
163
148
|
current: m.id === node.id,
|
|
164
149
|
...(m.id === group ? { original: true } : {}),
|
|
165
150
|
}));
|
|
@@ -169,7 +154,7 @@ export async function alternatesFor(
|
|
|
169
154
|
if (peerSite.locales.includes(m.locale) && !out.some((a) => a.locale === m.locale))
|
|
170
155
|
out.push({
|
|
171
156
|
locale: m.locale,
|
|
172
|
-
href: localeUrl(peerSite, m.locale, pathOf(m), peer.origin),
|
|
157
|
+
href: localeUrl(peerSite, m.locale, pathOf(peerSite, m), peer.origin),
|
|
173
158
|
current: false,
|
|
174
159
|
...(m.id === group ? { original: true } : {}),
|
|
175
160
|
});
|
|
@@ -222,7 +207,7 @@ export async function linkLocalizer(
|
|
|
222
207
|
const map = new Map ();
|
|
223
208
|
for (const n of [...pages.filter((p) => p.locale === def), ...entries]) {
|
|
224
209
|
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)));
|
|
210
|
+
map.set(pathOf(site, n), twin ? here(pathOf(site, twin)) : home(pathOf(site, n)));
|
|
226
211
|
}
|
|
227
212
|
const archive = archiveLocalizer(taxonomies, terms, locale, def);
|
|
228
213
|
return (path) => map.get(path) ?? (archive(path) ? here(archive(path) ) : here(path));
|
package/dist/src/media.d.ts
CHANGED
|
@@ -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
package/dist/src/navigation.d.ts
CHANGED
|
@@ -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
|
|
67
|
-
* `
|
|
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. */
|
package/dist/src/navigation.js
CHANGED
|
@@ -19,7 +19,13 @@
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
import {
|
|
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
|
|
89
|
-
* `
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
)
|
|
159
|
+
)
|
|
160
|
+
)?.path;
|
|
152
161
|
},
|
|
153
162
|
};
|
|
154
163
|
}
|
package/dist/src/preview.js
CHANGED
|
@@ -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="
|
|
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) => [
|
|
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 {
|
|
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:
|
|
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
|
: ""
|
package/dist/src/routing.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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;
|
package/dist/src/routing.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
|
49
|
-
if (!
|
|
50
|
-
const entry = await source.entryBySlug(
|
|
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
|
|
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))
|
|
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
|
|
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
|
},
|
package/dist/src/source.js
CHANGED
|
@@ -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(
|
|
73
|
+
export function surfaceEntryCard(
|
|
74
|
+
site ,
|
|
75
|
+
e ,
|
|
76
|
+
) {
|
|
73
77
|
return {
|
|
74
78
|
id: e.id,
|
|
75
|
-
href:
|
|
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.
|
|
3
|
+
"version": "0.3.12",
|
|
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.
|
|
183
|
-
"@cloudhal/core-ts": "0.3.
|
|
184
|
-
"@cloudhal/storage": "0.3.
|
|
182
|
+
"@cloudhal/core-contracts": "0.3.12",
|
|
183
|
+
"@cloudhal/core-ts": "0.3.12",
|
|
184
|
+
"@cloudhal/storage": "0.3.12",
|
|
185
185
|
"marked": "^18.1.0",
|
|
186
186
|
"parse5": "8.0.1",
|
|
187
|
-
"@cloudhal/analytics": "0.3.
|
|
187
|
+
"@cloudhal/analytics": "0.3.12",
|
|
188
188
|
"vite": "^8.3.3",
|
|
189
|
-
"@cloudhal/comments": "0.3.
|
|
189
|
+
"@cloudhal/comments": "0.3.12"
|
|
190
190
|
},
|
|
191
191
|
"peerDependencies": {
|
|
192
192
|
"astro": "^7.3.0",
|