@conloca/astro-cms 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -5
- package/dist/collections-Bd7EME4b.mjs +129 -0
- package/dist/collections-Bd7EME4b.mjs.map +1 -0
- package/dist/collections.d.mts +3 -3
- package/dist/collections.d.mts.map +1 -1
- package/dist/collections.mjs +2 -56
- package/dist/components.d.mts +6 -31
- package/dist/components.d.mts.map +1 -1
- package/dist/components.mjs +100 -45
- package/dist/components.mjs.map +1 -1
- package/dist/hydration.d.mts +2 -2
- package/dist/hydration.mjs +2 -3
- package/dist/index.d.mts +12 -88
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +19 -797
- package/dist/index.mjs.map +1 -1
- package/dist/internal/acorn-default.mjs +29 -0
- package/dist/{cms-handler.d.mts → internal/cms-handler.d.mts} +0 -1
- package/dist/internal/cms-handler.d.mts.map +1 -0
- package/dist/{cms-handler.mjs → internal/cms-handler.mjs} +57 -8
- package/dist/internal/cms-handler.mjs.map +1 -0
- package/dist/internal/page-handler.astro +541 -0
- package/dist/lib/hydration-script.d.mts +1 -2
- package/dist/lib/hydration-script.d.mts.map +1 -1
- package/dist/lib/hydration-script.mjs +1 -2
- package/dist/lib/hydration-script.mjs.map +1 -1
- package/dist/locales-helpers-BvYYqnJ5.d.mts +64 -0
- package/dist/locales-helpers-BvYYqnJ5.d.mts.map +1 -0
- package/dist/locales-helpers-qiwh7nxS.mjs +54 -0
- package/dist/locales-helpers-qiwh7nxS.mjs.map +1 -0
- package/dist/node/content.d.mts +18 -0
- package/dist/node/content.d.mts.map +1 -0
- package/dist/node/content.d.ts +3 -0
- package/dist/node/content.d.ts.map +1 -0
- package/dist/node/content.js +2 -0
- package/dist/node/content.mjs +2 -0
- package/dist/node/index.d.mts +200 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +3 -0
- package/dist/node/index.mjs +2513 -0
- package/dist/node/index.mjs.map +1 -0
- package/dist/{serialize-props-DqfDQeFl.mjs → serialize-props-BHoNpzH6.mjs} +4 -5
- package/dist/{serialize-props-DqfDQeFl.mjs.map → serialize-props-BHoNpzH6.mjs.map} +1 -1
- package/dist/src/cms-handler.d.ts +19 -0
- package/dist/src/cms-handler.d.ts.map +1 -0
- package/dist/src/cms-handler.js +366 -0
- package/dist/src/collections.d.ts +32 -0
- package/dist/src/collections.d.ts.map +1 -0
- package/dist/src/collections.js +50 -0
- package/dist/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/src/components/HydrationWrapper.js +21 -0
- package/dist/src/components/RenderWithBlocks.d.ts +23 -0
- package/dist/src/components/RenderWithBlocks.d.ts.map +1 -0
- package/dist/src/components/RenderWithBlocks.js +129 -0
- package/dist/src/components/RenderWithHydration.d.ts +17 -0
- package/dist/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/src/components/RenderWithHydration.js +36 -0
- package/dist/src/components.d.ts +4 -0
- package/dist/src/components.d.ts.map +1 -0
- package/dist/src/components.js +3 -0
- package/dist/src/discovery/astro-frontmatter.d.ts +18 -0
- package/dist/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/src/discovery/astro-frontmatter.js +24 -0
- package/dist/src/discovery/extract-props-ts.d.ts +41 -0
- package/dist/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/src/discovery/extract-props-ts.js +231 -0
- package/dist/src/discovery/merge-registry.d.ts +58 -0
- package/dist/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/src/discovery/merge-registry.js +332 -0
- package/dist/src/discovery/registry-endpoint.d.ts +42 -0
- package/dist/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/src/discovery/registry-endpoint.js +81 -0
- package/dist/src/discovery/scan-components.d.ts +98 -0
- package/dist/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/src/discovery/scan-components.js +399 -0
- package/dist/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/src/discovery/scan-mdx.js +112 -0
- package/dist/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/src/discovery/scan-overrides.js +33 -0
- package/dist/src/hydration.d.ts +4 -0
- package/dist/src/hydration.d.ts.map +1 -0
- package/dist/src/hydration.js +4 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +25 -0
- package/dist/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/src/lib/hydration-scanner.js +135 -0
- package/dist/src/lib/hydration-script.d.ts +28 -0
- package/dist/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/src/lib/hydration-script.js +88 -0
- package/dist/src/lib/hydration-utils.d.ts +51 -0
- package/dist/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/src/lib/hydration-utils.js +83 -0
- package/dist/src/lib/page-api.d.ts +77 -0
- package/dist/src/lib/page-api.d.ts.map +1 -0
- package/dist/src/lib/page-api.js +121 -0
- package/dist/src/lib/route-utils.d.ts +41 -0
- package/dist/src/lib/route-utils.d.ts.map +1 -0
- package/dist/src/lib/route-utils.js +78 -0
- package/dist/src/lib/routing-config.d.ts +32 -0
- package/dist/src/lib/routing-config.d.ts.map +1 -0
- package/dist/src/lib/routing-config.js +93 -0
- package/dist/src/lib/serialize-props.d.ts +6 -0
- package/dist/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/src/lib/serialize-props.js +7 -0
- package/dist/src/lib/virtual-module-generators.d.ts +57 -0
- package/dist/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/src/lib/virtual-module-generators.js +263 -0
- package/dist/src/lib/withHydration.d.ts +51 -0
- package/dist/src/lib/withHydration.d.ts.map +1 -0
- package/dist/src/lib/withHydration.js +49 -0
- package/dist/src/loader.d.ts +14 -0
- package/dist/src/loader.d.ts.map +1 -0
- package/dist/src/loader.js +89 -0
- package/dist/src/locales-helpers.d.ts +61 -0
- package/dist/src/locales-helpers.d.ts.map +1 -0
- package/dist/src/locales-helpers.js +49 -0
- package/dist/src/mime-types.d.ts +3 -0
- package/dist/src/mime-types.d.ts.map +1 -0
- package/dist/src/mime-types.js +19 -0
- package/dist/src/path-validation.d.ts +8 -0
- package/dist/src/path-validation.d.ts.map +1 -0
- package/dist/src/path-validation.js +12 -0
- package/dist/src/plugin-spa.d.ts +164 -0
- package/dist/src/plugin-spa.d.ts.map +1 -0
- package/dist/src/plugin-spa.js +972 -0
- package/dist/src/safe-json-stringify.d.ts +13 -0
- package/dist/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/src/safe-json-stringify.js +6 -0
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts +76 -0
- package/dist/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/content-wrapper-endpoint.js +227 -0
- package/dist/src/site-styles/render-endpoint.d.ts +55 -0
- package/dist/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/render-endpoint.js +263 -0
- package/dist/src/site-styles/styles-endpoint.d.ts +61 -0
- package/dist/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/src/site-styles/styles-endpoint.js +158 -0
- package/dist/src/types.d.ts +627 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1 -0
- package/dist/{types-Bsd_qENn.d.mts → types-CS9neadI.d.mts} +193 -3
- package/dist/types-CS9neadI.d.mts.map +1 -0
- package/dist/virtual-modules.d.ts +155 -0
- package/dist/{withHydration-692fMySA.mjs → withHydration-C256ox_6.mjs} +6 -2
- package/dist/withHydration-C256ox_6.mjs.map +1 -0
- package/dist/{withHydration-BGgQDE-H.d.mts → withHydration-DkKpkmzJ.d.mts} +5 -2
- package/dist/withHydration-DkKpkmzJ.d.mts.map +1 -0
- package/package.json +106 -40
- package/dist/cms-handler.d.mts.map +0 -1
- package/dist/cms-handler.mjs.map +0 -1
- package/dist/collections.mjs.map +0 -1
- package/dist/handlers/page-handler.astro +0 -299
- package/dist/loader-W3i9kf3p.mjs +0 -61
- package/dist/loader-W3i9kf3p.mjs.map +0 -1
- package/dist/types-Bsd_qENn.d.mts.map +0 -1
- package/dist/withHydration-692fMySA.mjs.map +0 -1
- package/dist/withHydration-BGgQDE-H.d.mts.map +0 -1
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Page Handler Component
|
|
4
|
+
*
|
|
5
|
+
* This Astro component is injected via injectRoute() to handle content pages.
|
|
6
|
+
* It implements getStaticPaths() for static page generation and renders
|
|
7
|
+
* content using the Puck Render component with an optional Layout wrapper.
|
|
8
|
+
*
|
|
9
|
+
* MDX blocks are evaluated at build time and rendered as React components.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { getCollection } from 'astro:content'
|
|
13
|
+
import type { GetStaticPaths } from 'astro'
|
|
14
|
+
import { Render, resolveAllData, type Data } from '@puckeditor/core'
|
|
15
|
+
import React from 'react'
|
|
16
|
+
import type { ComponentType } from 'react'
|
|
17
|
+
|
|
18
|
+
import { createPageRendererWithBlocks, RenderWithHydration } from '@conloca/astro-cms/components'
|
|
19
|
+
import { hasHydratableComponents, extractSlugFromPathname, isPublished, toDate } from '@conloca/astro-cms'
|
|
20
|
+
import type { DataCollectionEntry, DataContext, PageData, PageReference, ResolvedRoutingConfig } from '@conloca/astro-cms'
|
|
21
|
+
import { ALL_BLOCKS_COLLECTION } from '@conloca/astro-cms/node/content'
|
|
22
|
+
|
|
23
|
+
import routingConfig from 'virtual:conloca-routing-config'
|
|
24
|
+
import Layout from 'virtual:conloca-layout'
|
|
25
|
+
import puckConfig from 'virtual:conloca-puck-config'
|
|
26
|
+
|
|
27
|
+
// prerender is controlled by injectRoute({ prerender }) in plugin-spa.ts
|
|
28
|
+
// Do not hardcode here — it overrides the route-level config
|
|
29
|
+
|
|
30
|
+
type AstroCollectionEntry = Awaited<ReturnType<typeof getCollection>>[number]
|
|
31
|
+
|
|
32
|
+
interface BaseEntryData {
|
|
33
|
+
id: string
|
|
34
|
+
locale: string
|
|
35
|
+
title?: string
|
|
36
|
+
description?: string
|
|
37
|
+
created?: string | Date
|
|
38
|
+
modified?: string | Date
|
|
39
|
+
publishAt?: string | Date | null
|
|
40
|
+
unpublishAt?: string | Date | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface PageEntryData extends BaseEntryData {
|
|
44
|
+
pathname?: string
|
|
45
|
+
puckData?: Data
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface BlockEntryData extends BaseEntryData {
|
|
49
|
+
name?: string
|
|
50
|
+
mdx?: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface DataEntryData extends BaseEntryData {
|
|
54
|
+
name?: string
|
|
55
|
+
data?: Record<string, unknown>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Merge component defaultProps with stored sparse props.
|
|
60
|
+
*
|
|
61
|
+
* Mirrors the editor's mergeDefaultProps in PageEditorWrapper.tsx.
|
|
62
|
+
* Without this, new top-level fields added to a component after content was saved
|
|
63
|
+
* would render as undefined in production (Puck's Render doesn't apply defaultProps).
|
|
64
|
+
*/
|
|
65
|
+
function mergeDefaultProps(data: Data, config: typeof puckConfig): Data {
|
|
66
|
+
if (!data?.content || !config?.components) return data
|
|
67
|
+
|
|
68
|
+
const mergeComponentProps = (item: Data['content'][0]): Data['content'][0] => {
|
|
69
|
+
const componentConfig = config.components[item.type]
|
|
70
|
+
if (!componentConfig?.defaultProps) return item
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
...item,
|
|
74
|
+
props: {
|
|
75
|
+
...componentConfig.defaultProps,
|
|
76
|
+
...item.props,
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const mergedContent = data.content.map(mergeComponentProps)
|
|
82
|
+
|
|
83
|
+
let mergedZones = data.zones
|
|
84
|
+
if (data.zones) {
|
|
85
|
+
mergedZones = {}
|
|
86
|
+
for (const [zoneKey, zoneContent] of Object.entries(data.zones)) {
|
|
87
|
+
mergedZones[zoneKey] = zoneContent.map(mergeComponentProps)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
...data,
|
|
93
|
+
content: mergedContent,
|
|
94
|
+
...(mergedZones && { zones: mergedZones }),
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const collectionCache = new Map<string, Promise<AstroCollectionEntry[]>>()
|
|
99
|
+
let evaluateMDXToComponentPromise: Promise<typeof import('@conloca/mdx/node').evaluateMDXToComponent> | undefined
|
|
100
|
+
|
|
101
|
+
async function loadEvaluateMDXToComponent() {
|
|
102
|
+
evaluateMDXToComponentPromise ??= import('@conloca/mdx/node').then((module) => module.evaluateMDXToComponent)
|
|
103
|
+
|
|
104
|
+
return evaluateMDXToComponentPromise
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function getCollectionEntries(collectionName: string) {
|
|
108
|
+
return (getCollection(collectionName as never) as Promise<AstroCollectionEntry[]>).catch((error) => {
|
|
109
|
+
if (error instanceof Error && error.message.includes(`The collection "${collectionName}" does not exist or is empty`)) {
|
|
110
|
+
return []
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throw error
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function loadCollectionEntries(collectionName: string) {
|
|
118
|
+
if (import.meta.env.DEV) {
|
|
119
|
+
return getCollectionEntries(collectionName)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let entriesPromise = collectionCache.get(collectionName)
|
|
123
|
+
|
|
124
|
+
if (!entriesPromise) {
|
|
125
|
+
entriesPromise = getCollectionEntries(collectionName)
|
|
126
|
+
collectionCache.set(collectionName, entriesPromise)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return entriesPromise
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function getPageEntries(collectionName: string, locale: string) {
|
|
133
|
+
const entries = await loadCollectionEntries(collectionName)
|
|
134
|
+
|
|
135
|
+
return entries
|
|
136
|
+
.map((entry) => ({ entry, data: entry.data as Partial<PageEntryData> }))
|
|
137
|
+
.filter(({ data }) => data.locale === locale && typeof data.pathname === 'string' && isPublished(data as BaseEntryData))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function toPageReference(data: PageEntryData, collection: string): PageReference {
|
|
141
|
+
return {
|
|
142
|
+
id: data.id,
|
|
143
|
+
pathname: data.pathname || '/',
|
|
144
|
+
title: data.title,
|
|
145
|
+
collection,
|
|
146
|
+
meta: {
|
|
147
|
+
title: data.title,
|
|
148
|
+
description: data.description,
|
|
149
|
+
},
|
|
150
|
+
timestamps: {
|
|
151
|
+
created: toDate(data.created),
|
|
152
|
+
modified: toDate(data.modified),
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function getPagesByPrefix(prefix: string, locale: string, config: ResolvedRoutingConfig, options?: { sort?: 'date-desc' | 'date-asc' | 'title'; limit?: number }) {
|
|
158
|
+
const pageCollections = Array.from(new Set(Object.values(config.routes).map((route) => route.collection)))
|
|
159
|
+
const pages = (
|
|
160
|
+
await Promise.all(
|
|
161
|
+
pageCollections.map(async (collectionName) => {
|
|
162
|
+
const entries = await getPageEntries(collectionName, locale)
|
|
163
|
+
|
|
164
|
+
return entries.map(({ data }) => toPageReference(data as PageEntryData, collectionName))
|
|
165
|
+
}),
|
|
166
|
+
)
|
|
167
|
+
).flat()
|
|
168
|
+
|
|
169
|
+
let filtered = pages.filter((page) => page.pathname.startsWith(prefix) && page.pathname !== prefix && page.pathname !== prefix.slice(0, -1))
|
|
170
|
+
|
|
171
|
+
if (options?.sort === 'date-asc') {
|
|
172
|
+
filtered.sort((a, b) => (a.timestamps?.modified || a.timestamps?.created || new Date(0)).getTime() - (b.timestamps?.modified || b.timestamps?.created || new Date(0)).getTime())
|
|
173
|
+
} else if (options?.sort === 'title') {
|
|
174
|
+
filtered.sort((a, b) => (a.title || '').localeCompare(b.title || ''))
|
|
175
|
+
} else {
|
|
176
|
+
filtered.sort((a, b) => (b.timestamps?.modified || b.timestamps?.created || new Date(0)).getTime() - (a.timestamps?.modified || a.timestamps?.created || new Date(0)).getTime())
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (options?.limit && options.limit > 0) {
|
|
180
|
+
filtered = filtered.slice(0, options.limit)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return filtered
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function getDataCollectionEntries(collectionName: string, locale: string) {
|
|
187
|
+
const entries = await loadCollectionEntries(collectionName)
|
|
188
|
+
|
|
189
|
+
return entries
|
|
190
|
+
.map((entry) => ({ entry, data: entry.data as Partial<DataEntryData> }))
|
|
191
|
+
.filter(({ data }) => data.locale === locale && typeof data.name === 'string' && isPublished(data as BaseEntryData))
|
|
192
|
+
.map(({ data }) => ({
|
|
193
|
+
id: data.id || '',
|
|
194
|
+
name: data.name || '',
|
|
195
|
+
data: data.data || {},
|
|
196
|
+
meta: {
|
|
197
|
+
title: data.title,
|
|
198
|
+
description: data.description,
|
|
199
|
+
},
|
|
200
|
+
})) satisfies DataCollectionEntry[]
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function loadMdxComponents(locale: string) {
|
|
204
|
+
const evaluateMDXToComponent = await loadEvaluateMDXToComponent()
|
|
205
|
+
const entries = (await loadCollectionEntries(ALL_BLOCKS_COLLECTION)).map((entry) => ({ entry, data: entry.data as Partial<BlockEntryData> }))
|
|
206
|
+
|
|
207
|
+
return Promise.all(
|
|
208
|
+
entries
|
|
209
|
+
.filter(({ data }) => data.locale === locale && typeof data.id === 'string' && isPublished(data as BaseEntryData))
|
|
210
|
+
.map(async ({ data }) => {
|
|
211
|
+
const title = data.title || data.name || data.id
|
|
212
|
+
const mdx = data.mdx
|
|
213
|
+
|
|
214
|
+
if (!mdx) {
|
|
215
|
+
if (import.meta.env.DEV) {
|
|
216
|
+
console.warn(`[Conloca] No MDX content found for block: ${title}`)
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
id: data.id || title,
|
|
220
|
+
title,
|
|
221
|
+
Component: () => null,
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const { Component, error } = await evaluateMDXToComponent(mdx)
|
|
226
|
+
|
|
227
|
+
if (!Component || error) {
|
|
228
|
+
const errorMessage = error?.message || 'MDX evaluation failed'
|
|
229
|
+
console.error(`[Conloca] MDX compilation error in block "${title}": ${errorMessage}`)
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
id: data.id || title,
|
|
233
|
+
title,
|
|
234
|
+
Component: import.meta.env.DEV
|
|
235
|
+
? () =>
|
|
236
|
+
React.createElement(
|
|
237
|
+
'div',
|
|
238
|
+
{ className: 'p-4 bg-red-50 border border-red-200 rounded text-red-600' },
|
|
239
|
+
React.createElement('p', { className: 'font-semibold mb-2' }, 'MDX Compilation Error'),
|
|
240
|
+
React.createElement('p', { className: 'text-sm' }, `Block: ${title}`),
|
|
241
|
+
React.createElement('p', { className: 'text-xs mt-2' }, errorMessage),
|
|
242
|
+
)
|
|
243
|
+
: () => null,
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
id: data.id || title,
|
|
249
|
+
title,
|
|
250
|
+
Component,
|
|
251
|
+
}
|
|
252
|
+
}),
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export const getStaticPaths: GetStaticPaths = async () => {
|
|
257
|
+
const config = routingConfig as ResolvedRoutingConfig
|
|
258
|
+
const paths: {
|
|
259
|
+
params: { slug: string | undefined }
|
|
260
|
+
props: { routeName: string; collection: string; pathname: string }
|
|
261
|
+
}[] = []
|
|
262
|
+
|
|
263
|
+
if (!config.enabled) {
|
|
264
|
+
return paths
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
for (const [routeName, routeConfig] of Object.entries(config.routes)) {
|
|
268
|
+
try {
|
|
269
|
+
const pages = (await getCollection(routeConfig.collection as never) as AstroCollectionEntry[])
|
|
270
|
+
.map((entry) => entry.data as Partial<PageEntryData>)
|
|
271
|
+
.filter((data) => {
|
|
272
|
+
if (data.locale !== config.locale || typeof data.pathname !== 'string') {
|
|
273
|
+
return false
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return isPublished(data as BaseEntryData)
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
for (const data of pages) {
|
|
280
|
+
const pathname = data.pathname || '/'
|
|
281
|
+
const slug = extractSlugFromPathname(pathname, routeConfig.pattern)
|
|
282
|
+
|
|
283
|
+
paths.push({
|
|
284
|
+
params: { slug },
|
|
285
|
+
props: {
|
|
286
|
+
routeName,
|
|
287
|
+
collection: routeConfig.collection,
|
|
288
|
+
pathname,
|
|
289
|
+
},
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
} catch (error) {
|
|
293
|
+
console.error(`[Conloca] Error loading pages for route '${routeName}':`, error)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (import.meta.env.DEV) {
|
|
298
|
+
if (paths.length === 0) {
|
|
299
|
+
console.warn(
|
|
300
|
+
'[Conloca] getStaticPaths returned 0 pages. '
|
|
301
|
+
+ 'Check that content collections are populated and pages have locale/pathname fields.',
|
|
302
|
+
)
|
|
303
|
+
} else {
|
|
304
|
+
console.debug(`[Conloca] getStaticPaths: ${paths.length} page(s)`)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return paths
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
interface Props {
|
|
312
|
+
routeName: string
|
|
313
|
+
collection: string
|
|
314
|
+
pathname: string
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const config = routingConfig as ResolvedRoutingConfig
|
|
318
|
+
|
|
319
|
+
// In prerender mode, props come from getStaticPaths().
|
|
320
|
+
// In SSR mode (prerender: false), derive from the request URL.
|
|
321
|
+
const propsFromStaticPaths = Astro.props as Partial<Props>
|
|
322
|
+
let routeName = propsFromStaticPaths.routeName
|
|
323
|
+
let collection = propsFromStaticPaths.collection
|
|
324
|
+
let pathname = propsFromStaticPaths.pathname
|
|
325
|
+
|
|
326
|
+
if (!routeName || !collection || !pathname) {
|
|
327
|
+
// SSR fallback: match URL against configured routes
|
|
328
|
+
const requestPath = Astro.url.pathname
|
|
329
|
+
for (const [name, routeConfig] of Object.entries(config.routes)) {
|
|
330
|
+
const prefix = routeConfig.pattern.replace(/\[.*$/, '').replace(/\/$/, '')
|
|
331
|
+
if (requestPath === prefix || requestPath.startsWith(prefix + '/') || prefix === '') {
|
|
332
|
+
routeName = name
|
|
333
|
+
collection = routeConfig.collection
|
|
334
|
+
pathname = requestPath
|
|
335
|
+
break
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
let page: PageData | undefined
|
|
341
|
+
let loadError: Error | undefined
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
const entries = await getPageEntries(collection, config.locale)
|
|
345
|
+
const matchedPage = entries.find(({ data }) => data.pathname === pathname)
|
|
346
|
+
|
|
347
|
+
if (!matchedPage) {
|
|
348
|
+
const error = new Error(`Page not found: ${pathname}`) as Error & { code?: string }
|
|
349
|
+
error.code = 'PAGE_NOT_FOUND'
|
|
350
|
+
throw error
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const data = matchedPage.data as PageEntryData
|
|
354
|
+
const routeConfig = config.routes[routeName]
|
|
355
|
+
|
|
356
|
+
page = {
|
|
357
|
+
id: data.id,
|
|
358
|
+
title: data.title || data.id,
|
|
359
|
+
description: data.description,
|
|
360
|
+
pathname,
|
|
361
|
+
puckData: data.puckData as Data,
|
|
362
|
+
collection,
|
|
363
|
+
route: {
|
|
364
|
+
name: routeName,
|
|
365
|
+
pattern: routeConfig.pattern,
|
|
366
|
+
meta: routeConfig.meta,
|
|
367
|
+
},
|
|
368
|
+
meta: {
|
|
369
|
+
title: data.title,
|
|
370
|
+
description: data.description,
|
|
371
|
+
},
|
|
372
|
+
timestamps: {
|
|
373
|
+
created: toDate(data.created),
|
|
374
|
+
modified: toDate(data.modified),
|
|
375
|
+
published: toDate(data.publishAt),
|
|
376
|
+
},
|
|
377
|
+
}
|
|
378
|
+
} catch (error) {
|
|
379
|
+
loadError = error as Error
|
|
380
|
+
|
|
381
|
+
if ((error as { code?: string }).code === 'PAGE_NOT_FOUND') {
|
|
382
|
+
if (config.fallback === 'passthrough') {
|
|
383
|
+
return Astro.redirect('/404', 307)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return new Response('Page not found', { status: 404 })
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
throw error
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
let dataContext: DataContext | undefined
|
|
393
|
+
|
|
394
|
+
const routeConfig = config.routes[routeName]
|
|
395
|
+
const hasCollections = routeConfig?.dataBindings?.collections?.length
|
|
396
|
+
const hasPages = routeConfig?.dataBindings?.pages?.prefix
|
|
397
|
+
|
|
398
|
+
if (hasCollections || hasPages) {
|
|
399
|
+
const collections: Record<string, DataCollectionEntry[]> = {}
|
|
400
|
+
let pages: PageReference[] | undefined
|
|
401
|
+
|
|
402
|
+
if (hasCollections) {
|
|
403
|
+
for (const collectionName of routeConfig.dataBindings.collections) {
|
|
404
|
+
try {
|
|
405
|
+
const locale = routeConfig.dataBindings.locale ?? config.locale
|
|
406
|
+
collections[collectionName] = await getDataCollectionEntries(collectionName, locale)
|
|
407
|
+
} catch (error) {
|
|
408
|
+
console.error(`[Conloca] Failed to fetch collection '${collectionName}':`, error)
|
|
409
|
+
collections[collectionName] = []
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (hasPages) {
|
|
415
|
+
try {
|
|
416
|
+
const pagesConfig = routeConfig.dataBindings.pages
|
|
417
|
+
pages = await getPagesByPrefix(pagesConfig.prefix, routeConfig.dataBindings.locale ?? config.locale, config, {
|
|
418
|
+
sort: pagesConfig.sort,
|
|
419
|
+
limit: pagesConfig.limit,
|
|
420
|
+
})
|
|
421
|
+
} catch (error) {
|
|
422
|
+
console.error(`[Conloca] Failed to fetch pages with prefix '${routeConfig.dataBindings.pages.prefix}':`, error)
|
|
423
|
+
pages = []
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
dataContext = {
|
|
428
|
+
collections,
|
|
429
|
+
pages,
|
|
430
|
+
locale: routeConfig.dataBindings.locale ?? config.locale,
|
|
431
|
+
siteName: config.siteName,
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const hasPuckData = !!page?.puckData && Object.keys(page.puckData).length > 0
|
|
436
|
+
let resolvedPuckData = page?.puckData
|
|
437
|
+
|
|
438
|
+
if (hasPuckData && page) {
|
|
439
|
+
const mergedData = mergeDefaultProps(page.puckData, puckConfig)
|
|
440
|
+
try {
|
|
441
|
+
resolvedPuckData = await resolveAllData(
|
|
442
|
+
mergedData,
|
|
443
|
+
puckConfig,
|
|
444
|
+
dataContext ? { metadata: dataContext } : undefined,
|
|
445
|
+
)
|
|
446
|
+
} catch (error) {
|
|
447
|
+
console.error('[Conloca] resolveAllData failed:', error)
|
|
448
|
+
resolvedPuckData = mergedData
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const needsHydration = hasPuckData && resolvedPuckData && hasHydratableComponents(resolvedPuckData, puckConfig)
|
|
453
|
+
|
|
454
|
+
let PageRenderer: ComponentType | undefined
|
|
455
|
+
|
|
456
|
+
if (hasPuckData && page && resolvedPuckData) {
|
|
457
|
+
try {
|
|
458
|
+
const mdxComponents = await loadMdxComponents(config.locale)
|
|
459
|
+
PageRenderer = createPageRendererWithBlocks(puckConfig, resolvedPuckData, mdxComponents)
|
|
460
|
+
} catch (error) {
|
|
461
|
+
console.error('[Conloca] MDX evaluation failed, falling back to plain render:', error)
|
|
462
|
+
PageRenderer = undefined
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
{Layout && page ? (
|
|
469
|
+
<Layout title={page.title ?? 'Page'} description={page.description}>
|
|
470
|
+
{hasPuckData && PageRenderer ? (
|
|
471
|
+
<PageRenderer />
|
|
472
|
+
) : hasPuckData && resolvedPuckData ? (
|
|
473
|
+
needsHydration ? (
|
|
474
|
+
<RenderWithHydration config={puckConfig} data={resolvedPuckData} />
|
|
475
|
+
) : (
|
|
476
|
+
<Render config={puckConfig} data={resolvedPuckData} />
|
|
477
|
+
)
|
|
478
|
+
) : (
|
|
479
|
+
<div class="conloca-empty-page">
|
|
480
|
+
<p>This page has no content yet.</p>
|
|
481
|
+
</div>
|
|
482
|
+
)}
|
|
483
|
+
</Layout>
|
|
484
|
+
) : page ? (
|
|
485
|
+
<html lang={config.locale || 'en'}>
|
|
486
|
+
<head>
|
|
487
|
+
<meta charset="UTF-8" />
|
|
488
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
489
|
+
<title>{page.title || 'Untitled'}</title>
|
|
490
|
+
{page.description && <meta name="description" content={page.description} />}
|
|
491
|
+
{needsHydration && <script>import 'virtual:conloca-hydration-entry'</script>}
|
|
492
|
+
</head>
|
|
493
|
+
<body>
|
|
494
|
+
{hasPuckData && PageRenderer ? (
|
|
495
|
+
<PageRenderer />
|
|
496
|
+
) : hasPuckData && resolvedPuckData ? (
|
|
497
|
+
needsHydration ? (
|
|
498
|
+
<RenderWithHydration config={puckConfig} data={resolvedPuckData} />
|
|
499
|
+
) : (
|
|
500
|
+
<Render config={puckConfig} data={resolvedPuckData} />
|
|
501
|
+
)
|
|
502
|
+
) : (
|
|
503
|
+
<div class="conloca-empty-page">
|
|
504
|
+
<p>This page has no content yet.</p>
|
|
505
|
+
</div>
|
|
506
|
+
)}
|
|
507
|
+
</body>
|
|
508
|
+
</html>
|
|
509
|
+
) : (
|
|
510
|
+
<html lang="en">
|
|
511
|
+
<head>
|
|
512
|
+
<meta charset="UTF-8" />
|
|
513
|
+
<title>Error</title>
|
|
514
|
+
</head>
|
|
515
|
+
<body>
|
|
516
|
+
<div class="conloca-error">
|
|
517
|
+
<h1>Error Loading Page</h1>
|
|
518
|
+
<p>{import.meta.env.DEV ? (loadError?.message || 'An unknown error occurred.') : 'An error occurred while loading this page.'}</p>
|
|
519
|
+
</div>
|
|
520
|
+
</body>
|
|
521
|
+
</html>
|
|
522
|
+
)}
|
|
523
|
+
|
|
524
|
+
{Layout && needsHydration && <script>import 'virtual:conloca-hydration-entry'</script>}
|
|
525
|
+
|
|
526
|
+
<style>
|
|
527
|
+
.conloca-empty-page {
|
|
528
|
+
padding: 2rem;
|
|
529
|
+
text-align: center;
|
|
530
|
+
color: #666;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
.conloca-error {
|
|
534
|
+
padding: 2rem;
|
|
535
|
+
text-align: center;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
.conloca-error h1 {
|
|
539
|
+
color: #c00;
|
|
540
|
+
}
|
|
541
|
+
</style>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration-script.d.mts","names":[],"sources":["../../src/lib/hydration-script.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hydration-script.d.mts","names":[],"sources":["../../src/lib/hydration-script.ts"],"mappings":";;;;;;KASK,wBAAwB,QAAQ,MAAM;;;;;UAMjC;EACR,QAAQ;EACR,UAAU;;;;;;KAOA,oBAAoB,eAAe;;;;;;;iBAuE/B,cAAc,UAAU"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createElement } from "react";
|
|
2
2
|
import { hydrateRoot } from "react-dom/client";
|
|
3
|
-
|
|
4
3
|
//#region src/lib/hydration-script.ts
|
|
5
4
|
/**
|
|
6
5
|
* Hydrate a single element with its corresponding React component.
|
|
@@ -79,7 +78,7 @@ function initHydration(registry) {
|
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
|
-
|
|
83
81
|
//#endregion
|
|
84
82
|
export { initHydration };
|
|
83
|
+
|
|
85
84
|
//# sourceMappingURL=hydration-script.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydration-script.mjs","names":[],"sources":["../../src/lib/hydration-script.ts"],"sourcesContent":["import { createElement } from 'react'
|
|
1
|
+
{"version":3,"file":"hydration-script.mjs","names":[],"sources":["../../src/lib/hydration-script.ts"],"sourcesContent":["import { createElement } from 'react';\nimport { hydrateRoot } from 'react-dom/client';\n\nimport type { HydrationStrategy } from '../types.js';\n\n/**\n * Async loader that returns a React component.\n * The registry generator handles extraction from ComponentConfig at build time.\n */\ntype ComponentLoader = () => Promise<React.ComponentType<unknown>>;\n\n/**\n * Registry entry with loader and strategy.\n * Generated by the scanner from withHydration metadata.\n */\ninterface ComponentRegistryEntry {\n loader: ComponentLoader;\n strategy: HydrationStrategy;\n}\n\n/**\n * Registry mapping component names to their loaders and strategies.\n * Generated by virtual:conloca-hydration-registry at build time.\n */\nexport type ComponentRegistry = Record<string, ComponentRegistryEntry>;\n\n/**\n * Hydrate a single element with its corresponding React component.\n */\nasync function hydrateElement(element: HTMLElement, entry: ComponentRegistryEntry): Promise<void> {\n const componentName = element.dataset.hydrate;\n const propsJson = element.dataset.props || '{}';\n\n if (!componentName) {\n console.warn('[Conloca Hydration] Element missing data-hydrate attribute');\n return;\n }\n\n try {\n const props = JSON.parse(propsJson);\n const Component = await entry.loader();\n hydrateRoot(element, createElement(Component, props));\n\n // Clean up data attributes after successful hydration\n delete element.dataset.hydrate;\n delete element.dataset.hydrateStrategy;\n delete element.dataset.props;\n } catch (error) {\n console.error(`[Conloca Hydration] Failed to hydrate ${componentName}:`, error);\n }\n}\n\n/**\n * Hydrate immediately on page load.\n */\nfunction hydrateOnLoad(element: HTMLElement, entry: ComponentRegistryEntry): void {\n hydrateElement(element, entry);\n}\n\n/**\n * Hydrate when element becomes visible in viewport.\n */\nfunction hydrateOnVisible(element: HTMLElement, entry: ComponentRegistryEntry): void {\n const observer = new IntersectionObserver(\n (entries, obs) => {\n for (const ioEntry of entries) {\n if (ioEntry.isIntersecting) {\n obs.unobserve(ioEntry.target);\n hydrateElement(ioEntry.target as HTMLElement, entry);\n }\n }\n },\n { rootMargin: '50px' },\n );\n observer.observe(element);\n}\n\n/**\n * Hydrate when browser is idle.\n * Uses requestIdleCallback with setTimeout fallback for Safari.\n */\nfunction hydrateOnIdle(element: HTMLElement, entry: ComponentRegistryEntry): void {\n const scheduleIdle =\n window.requestIdleCallback ??\n ((cb: IdleRequestCallback) => window.setTimeout(() => cb({ didTimeout: false, timeRemaining: () => 50 }), 1));\n\n scheduleIdle(() => hydrateElement(element, entry), { timeout: 2000 });\n}\n\n/**\n * Initialize hydration for all marked components on the page.\n *\n * Finds all elements with [data-hydrate] attribute and hydrates them\n * according to their strategy from the registry.\n */\nexport function initHydration(registry: ComponentRegistry): void {\n const elements = document.querySelectorAll<HTMLElement>('[data-hydrate]');\n\n for (const element of elements) {\n const componentName = element.dataset.hydrate;\n if (!componentName) continue;\n\n const entry = registry[componentName];\n if (!entry) {\n console.warn(`[Conloca Hydration] Unknown component: ${componentName}`);\n continue;\n }\n\n // Use strategy from registry (set at build time via withHydration)\n const strategy = entry.strategy;\n\n switch (strategy) {\n case 'load':\n hydrateOnLoad(element, entry);\n break;\n case 'visible':\n hydrateOnVisible(element, entry);\n break;\n case 'idle':\n hydrateOnIdle(element, entry);\n break;\n default:\n hydrateOnLoad(element, entry);\n }\n }\n}\n"],"mappings":";;;;;;AA6BA,eAAe,eAAe,SAAsB,OAA8C;CAChG,MAAM,gBAAgB,QAAQ,QAAQ;CACtC,MAAM,YAAY,QAAQ,QAAQ,SAAS;CAE3C,IAAI,CAAC,eAAe;EAClB,QAAQ,KAAK,4DAA4D;EACzE;CACF;CAEA,IAAI;EACF,MAAM,QAAQ,KAAK,MAAM,SAAS;EAElC,YAAY,SAAS,cAAc,MADX,MAAM,OAAO,GACS,KAAK,CAAC;EAGpD,OAAO,QAAQ,QAAQ;EACvB,OAAO,QAAQ,QAAQ;EACvB,OAAO,QAAQ,QAAQ;CACzB,SAAS,OAAO;EACd,QAAQ,MAAM,yCAAyC,cAAc,IAAI,KAAK;CAChF;AACF;;;;AAKA,SAAS,cAAc,SAAsB,OAAqC;CAChF,eAAe,SAAS,KAAK;AAC/B;;;;AAKA,SAAS,iBAAiB,SAAsB,OAAqC;CAYnF,IAXqB,sBAClB,SAAS,QAAQ;EAChB,KAAK,MAAM,WAAW,SACpB,IAAI,QAAQ,gBAAgB;GAC1B,IAAI,UAAU,QAAQ,MAAM;GAC5B,eAAe,QAAQ,QAAuB,KAAK;EACrD;CAEJ,GACA,EAAE,YAAY,OAAO,CAEhB,CAAC,CAAC,QAAQ,OAAO;AAC1B;;;;;AAMA,SAAS,cAAc,SAAsB,OAAqC;CAKhF,CAHE,OAAO,yBACL,OAA4B,OAAO,iBAAiB,GAAG;EAAE,YAAY;EAAO,qBAAqB;CAAG,CAAC,GAAG,CAAC,GAAA,OAE1F,eAAe,SAAS,KAAK,GAAG,EAAE,SAAS,IAAK,CAAC;AACtE;;;;;;;AAQA,SAAgB,cAAc,UAAmC;CAC/D,MAAM,WAAW,SAAS,iBAA8B,gBAAgB;CAExE,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,gBAAgB,QAAQ,QAAQ;EACtC,IAAI,CAAC,eAAe;EAEpB,MAAM,QAAQ,SAAS;EACvB,IAAI,CAAC,OAAO;GACV,QAAQ,KAAK,0CAA0C,eAAe;GACtE;EACF;EAKA,QAFiB,MAAM,UAEvB;GACE,KAAK;IACH,cAAc,SAAS,KAAK;IAC5B;GACF,KAAK;IACH,iBAAiB,SAAS,KAAK;IAC/B;GACF,KAAK;IACH,cAAc,SAAS,KAAK;IAC5B;GACF,SACE,cAAc,SAAS,KAAK;EAChC;CACF;AACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/locales-helpers.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Conloca's view of a site's locales.
|
|
4
|
+
*
|
|
5
|
+
* `list` is the full set of locales the site supports; `defaultLocale`
|
|
6
|
+
* is the one that lives at the root in the `'directory'` mdx-pages
|
|
7
|
+
* strategy. Pass this shape into `conlocaCMS({ locales })`.
|
|
8
|
+
*/
|
|
9
|
+
interface ConlocaLocales {
|
|
10
|
+
list: string[];
|
|
11
|
+
defaultLocale: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Translate Astro's native `i18n` config into Conloca's locale shape.
|
|
15
|
+
*
|
|
16
|
+
* Astro 4+ accepts both bare strings and `{ codes, path }` objects in
|
|
17
|
+
* its `locales` array — this helper flattens both forms.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { conlocaCMS, localesFromAstroI18n } from '@conloca/astro-cms/node';
|
|
22
|
+
* const i18n = { defaultLocale: 'en', locales: ['en', 'de'] };
|
|
23
|
+
* defineConfig({
|
|
24
|
+
* i18n,
|
|
25
|
+
* integrations: [conlocaCMS({ locales: localesFromAstroI18n(i18n) })],
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function localesFromAstroI18n(i18n: {
|
|
30
|
+
defaultLocale: string;
|
|
31
|
+
locales: ReadonlyArray<string | {
|
|
32
|
+
codes: string[];
|
|
33
|
+
path: string;
|
|
34
|
+
}>;
|
|
35
|
+
}): ConlocaLocales;
|
|
36
|
+
/**
|
|
37
|
+
* Translate Starlight's i18n config into Conloca's locale shape.
|
|
38
|
+
*
|
|
39
|
+
* Starlight shape: `{ defaultLocale: 'en', locales: { en: { label, lang? }, de: { ... } } }`.
|
|
40
|
+
* The default locale falls back to the first key in `locales` if unset,
|
|
41
|
+
* then to `'en'`.
|
|
42
|
+
*
|
|
43
|
+
* Usage:
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { conlocaCMS, localesFromStarlight } from '@conloca/astro-cms/node';
|
|
46
|
+
* const starlightConfig = { defaultLocale: 'en', locales: { en: { label: 'English' } } };
|
|
47
|
+
* defineConfig({
|
|
48
|
+
* integrations: [
|
|
49
|
+
* starlight(starlightConfig),
|
|
50
|
+
* conlocaCMS({ locales: localesFromStarlight(starlightConfig) }),
|
|
51
|
+
* ],
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function localesFromStarlight(starlight: {
|
|
56
|
+
defaultLocale?: string;
|
|
57
|
+
locales?: Record<string, {
|
|
58
|
+
label?: string;
|
|
59
|
+
lang?: string;
|
|
60
|
+
}>;
|
|
61
|
+
}): ConlocaLocales;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { localesFromAstroI18n as n, localesFromStarlight as r, ConlocaLocales as t };
|
|
64
|
+
//# sourceMappingURL=locales-helpers-BvYYqnJ5.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales-helpers-BvYYqnJ5.d.mts","names":[],"sources":["../src/locales-helpers.ts"],"mappings":";;;;;;;;UAOiB;EACf;EACA;;;;;;;;;;;;;;;;;;iBAmBc,qBAAqB;EACnC;EACA,SAAS;IAAyB;IAAiB;;IACjD;;;;;;;;;;;;;;;;;;;;iBA0BY,qBAAqB;EACnC;EACA,UAAU;IAAiB;IAAgB;;IACzC"}
|