@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
package/dist/index.mjs
CHANGED
|
@@ -1,120 +1,24 @@
|
|
|
1
|
-
import { i as isHydratable, n as findHydratableComponents, r as hasHydratableComponents, t as serializeProps } from "./serialize-props-
|
|
2
|
-
import { t as withHydration } from "./withHydration-
|
|
3
|
-
import { t as
|
|
1
|
+
import { i as isHydratable, n as findHydratableComponents, r as hasHydratableComponents, t as serializeProps } from "./serialize-props-BHoNpzH6.mjs";
|
|
2
|
+
import { t as withHydration } from "./withHydration-C256ox_6.mjs";
|
|
3
|
+
import { n as localesFromStarlight, t as localesFromAstroI18n } from "./locales-helpers-qiwh7nxS.mjs";
|
|
4
|
+
import { defineMdxComponents, readStringAttribute, writeStringAttribute } from "@conloca/cms-spa/mdx-components";
|
|
5
|
+
import { definePageSchema } from "@conloca/cms-spa/page-schemas";
|
|
4
6
|
import { blockMetaSchema, pageMetaSchema } from "@conloca/content-api/schemas";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import viteReact from "@vitejs/plugin-react";
|
|
12
|
-
import { searchForWorkspaceRoot } from "vite";
|
|
13
|
-
|
|
14
|
-
//#region src/lib/hydration-scanner.ts
|
|
15
|
-
const HYDRATION_IMPORT_PATTERN = /import\s+\{[^}]*withHydration[^}]*\}\s+from\s+['"]@conloca\/astro-cms(?:\/hydration)?['"]/;
|
|
16
|
-
const HYDRATION_PATTERN = /withHydration\s*\(\s*\w+\s*,\s*['"](\w+)['"]\s*\)/g;
|
|
17
|
-
const VALID_STRATEGIES = new Set([
|
|
18
|
-
"load",
|
|
19
|
-
"visible",
|
|
20
|
-
"idle"
|
|
21
|
-
]);
|
|
22
|
-
/**
|
|
23
|
-
* Derives component scan paths from puckConfigPath.
|
|
24
|
-
*
|
|
25
|
-
* Convention: puckConfigPath directory + '/components/puck'
|
|
26
|
-
* Example: './src/puck.config.tsx' -> './src/components/puck'
|
|
27
|
-
*
|
|
28
|
-
* If explicitPaths provided, they extend (not replace) the auto-discovered path.
|
|
29
|
-
*
|
|
30
|
-
* @param puckConfigPath - Path to the puck config (e.g., './src/puck.config.tsx')
|
|
31
|
-
* @param explicitPaths - Optional additional paths to scan
|
|
32
|
-
* @returns Array of paths to scan for hydratable components
|
|
33
|
-
*/
|
|
34
|
-
function deriveComponentPaths(puckConfigPath, explicitPaths) {
|
|
35
|
-
const defaultScanPath = join(dirname(puckConfigPath), "components", "puck");
|
|
36
|
-
if (explicitPaths && explicitPaths.length > 0) return [defaultScanPath, ...explicitPaths];
|
|
37
|
-
return [defaultScanPath];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Derives a PascalCase component name from a file path.
|
|
41
|
-
*
|
|
42
|
-
* @param filePath - Absolute path to the component file
|
|
43
|
-
* @returns Component name in PascalCase
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* deriveComponentName('/src/components/puck/TestimonialGrid.tsx')
|
|
47
|
-
* // => 'TestimonialGrid'
|
|
48
|
-
*
|
|
49
|
-
* deriveComponentName('/src/components/puck/blog-post-grid.tsx')
|
|
50
|
-
* // => 'BlogPostGrid'
|
|
51
|
-
*/
|
|
52
|
-
function deriveComponentName(filePath) {
|
|
53
|
-
const filename = basename(filePath, extname(filePath));
|
|
54
|
-
if (filename.includes("-")) return filename.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
55
|
-
return filename.charAt(0).toUpperCase() + filename.slice(1);
|
|
7
|
+
//#region src/lib/route-utils.ts
|
|
8
|
+
function toDate(value) {
|
|
9
|
+
if (!value) return;
|
|
10
|
+
if (value instanceof Date) return value;
|
|
11
|
+
const parsed = new Date(value);
|
|
12
|
+
return Number.isNaN(parsed.getTime()) ? void 0 : parsed;
|
|
56
13
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* @param projectRoot - Absolute path to the project root
|
|
65
|
-
* @returns Array of discovered hydratable components with their strategies
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const discoveries = await scanForHydratableComponents(
|
|
70
|
-
* ['src/components/puck'],
|
|
71
|
-
* '/path/to/project'
|
|
72
|
-
* )
|
|
73
|
-
* // => [{ componentName: 'TestimonialGrid', filePath: '...', strategy: 'visible' }]
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
async function scanForHydratableComponents(componentPaths, projectRoot) {
|
|
77
|
-
const discoveries = [];
|
|
78
|
-
const seenNames = /* @__PURE__ */ new Map();
|
|
79
|
-
for (const scanPath of componentPaths) {
|
|
80
|
-
const files = await fg("**/*.tsx", {
|
|
81
|
-
cwd: resolve(projectRoot, scanPath),
|
|
82
|
-
absolute: true,
|
|
83
|
-
onlyFiles: true
|
|
84
|
-
});
|
|
85
|
-
for (const filePath of files) try {
|
|
86
|
-
const content = await readFile(filePath, "utf-8");
|
|
87
|
-
if (!HYDRATION_IMPORT_PATTERN.test(content)) continue;
|
|
88
|
-
const matches = [...content.matchAll(HYDRATION_PATTERN)];
|
|
89
|
-
if (matches.length === 0) continue;
|
|
90
|
-
if (matches.length > 1) console.warn(`[Conloca Hydration] Multiple withHydration calls in ${filePath}. Consider splitting into separate component files. Using first call.`);
|
|
91
|
-
const rawStrategy = matches[0][1];
|
|
92
|
-
if (!VALID_STRATEGIES.has(rawStrategy)) {
|
|
93
|
-
console.warn(`[Conloca Hydration] Invalid strategy '${rawStrategy}' in ${filePath}. Valid options: ${[...VALID_STRATEGIES].join(", ")}. Skipping component.`);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const strategy = rawStrategy;
|
|
97
|
-
const componentName = deriveComponentName(filePath);
|
|
98
|
-
const existingPath = seenNames.get(componentName);
|
|
99
|
-
if (existingPath) {
|
|
100
|
-
console.warn(`[Conloca Hydration] Duplicate component name '${componentName}'. Found in: ${existingPath} and ${filePath}. Using first occurrence.`);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
seenNames.set(componentName, filePath);
|
|
104
|
-
discoveries.push({
|
|
105
|
-
componentName,
|
|
106
|
-
filePath,
|
|
107
|
-
strategy
|
|
108
|
-
});
|
|
109
|
-
} catch (err) {
|
|
110
|
-
console.warn(`[Conloca Hydration] Error reading ${filePath}:`, err);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return discoveries;
|
|
14
|
+
function isPublished(data) {
|
|
15
|
+
const now = /* @__PURE__ */ new Date();
|
|
16
|
+
const publishAt = toDate(data.publishAt);
|
|
17
|
+
const unpublishAt = toDate(data.unpublishAt);
|
|
18
|
+
if (publishAt && publishAt > now) return false;
|
|
19
|
+
if (unpublishAt && unpublishAt <= now) return false;
|
|
20
|
+
return true;
|
|
114
21
|
}
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/lib/route-utils.ts
|
|
118
22
|
/**
|
|
119
23
|
* Extract slug from pathname given a route pattern.
|
|
120
24
|
*
|
|
@@ -157,689 +61,7 @@ function pathnameFromSlug(slug, pattern) {
|
|
|
157
61
|
if (!slug) return prefix || "/";
|
|
158
62
|
return `${prefix}/${slug}`;
|
|
159
63
|
}
|
|
160
|
-
|
|
161
|
-
//#endregion
|
|
162
|
-
//#region src/lib/routing-config.ts
|
|
163
|
-
/**
|
|
164
|
-
* Normalize routing config input to full RoutingConfig.
|
|
165
|
-
*
|
|
166
|
-
* Handles the `routing: true` shorthand, boolean values, and top-level layout option.
|
|
167
|
-
*
|
|
168
|
-
* @param input - The routing config input (boolean, object, or undefined)
|
|
169
|
-
* @param topLevelLayout - Optional top-level layout path (enables routing when provided)
|
|
170
|
-
* @returns Normalized RoutingConfig or undefined if not enabled
|
|
171
|
-
*/
|
|
172
|
-
function normalizeRoutingConfig(input, topLevelLayout) {
|
|
173
|
-
if (input === void 0 && topLevelLayout) return {
|
|
174
|
-
enabled: true,
|
|
175
|
-
routes: { pages: {
|
|
176
|
-
pattern: "/[...slug]",
|
|
177
|
-
collection: "pages",
|
|
178
|
-
layout: topLevelLayout,
|
|
179
|
-
prerender: true
|
|
180
|
-
} },
|
|
181
|
-
fallback: "404",
|
|
182
|
-
onConflict: "warn"
|
|
183
|
-
};
|
|
184
|
-
if (input === void 0) return;
|
|
185
|
-
if (input === true) return {
|
|
186
|
-
enabled: true,
|
|
187
|
-
routes: { pages: {
|
|
188
|
-
pattern: "/[...slug]",
|
|
189
|
-
collection: "pages",
|
|
190
|
-
prerender: true
|
|
191
|
-
} },
|
|
192
|
-
fallback: "404",
|
|
193
|
-
onConflict: "warn"
|
|
194
|
-
};
|
|
195
|
-
if (input === false) return { enabled: false };
|
|
196
|
-
return input;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Apply defaults to a RouteConfig.
|
|
200
|
-
*
|
|
201
|
-
* Fills in missing optional fields with their default values.
|
|
202
|
-
*
|
|
203
|
-
* @param config - Partial route configuration
|
|
204
|
-
* @returns Complete route configuration with all fields
|
|
205
|
-
*/
|
|
206
|
-
function resolveRouteConfig(config) {
|
|
207
|
-
return {
|
|
208
|
-
pattern: config.pattern,
|
|
209
|
-
collection: config.collection ?? "pages",
|
|
210
|
-
layout: config.layout ?? "",
|
|
211
|
-
prerender: config.prerender ?? true,
|
|
212
|
-
meta: config.meta ?? {},
|
|
213
|
-
dataBindings: config.dataBindings ?? { collections: [] }
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/lib/virtual-module-generators.ts
|
|
219
|
-
/**
|
|
220
|
-
* Generate the virtual:conloca-routing-config module.
|
|
221
|
-
*
|
|
222
|
-
* Returns a module that exports the resolved routing configuration as default.
|
|
223
|
-
*
|
|
224
|
-
* @param config - Resolved routing configuration with all defaults applied
|
|
225
|
-
* @returns JavaScript module code as a string
|
|
226
|
-
*/
|
|
227
|
-
function generateRoutingConfigModule(config) {
|
|
228
|
-
return `export default ${JSON.stringify(config, null, 2)};`;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Generate the virtual:conloca-layout module.
|
|
232
|
-
*
|
|
233
|
-
* Returns a module that re-exports the layout component or exports undefined
|
|
234
|
-
* if no layout is configured.
|
|
235
|
-
*
|
|
236
|
-
* Currently uses the first route's layout. Multi-layout support is future work.
|
|
237
|
-
*
|
|
238
|
-
* @param routing - Routing configuration (may be undefined if routing disabled)
|
|
239
|
-
* @returns JavaScript module code as a string
|
|
240
|
-
*/
|
|
241
|
-
function generateLayoutModule(routing) {
|
|
242
|
-
const routes = routing?.routes || {};
|
|
243
|
-
const layoutPath = Object.values(routes)[0]?.layout;
|
|
244
|
-
if (layoutPath) return `export { default } from '${layoutPath.startsWith(".") ? `/${layoutPath.slice(2)}` : layoutPath}';`;
|
|
245
|
-
return "export default undefined;";
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Generate the virtual:conloca-page-api module.
|
|
249
|
-
*
|
|
250
|
-
* Returns a module that provides page loading functions wrapping ContentAPI:
|
|
251
|
-
* - getAllPages(collection?) - For getStaticPaths()
|
|
252
|
-
* - getPage(pathname, collection?) - For page data loading
|
|
253
|
-
* - pageExists(pathname, collection?) - For 404 checks
|
|
254
|
-
* - contentOptions - Configuration for ContentAPI (for MDX evaluation)
|
|
255
|
-
*
|
|
256
|
-
* @param options - Configuration for ContentAPI initialization
|
|
257
|
-
* @returns JavaScript module code as a string
|
|
258
|
-
*/
|
|
259
|
-
function generatePageApiModule(options) {
|
|
260
|
-
return `
|
|
261
|
-
import { createContentAPI } from '@conloca/content-api/node';
|
|
262
|
-
|
|
263
|
-
// Export content options for MDX evaluation and other ContentAPI uses
|
|
264
|
-
export const contentOptions = {
|
|
265
|
-
contentRoot: '${options.contentRoot}',
|
|
266
|
-
canvasDir: '${options.canvasDir}',
|
|
267
|
-
siteName: '${options.siteName}',
|
|
268
|
-
locale: '${options.locale}',
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
// Initialize ContentAPI with configured paths
|
|
272
|
-
const contentApi = await createContentAPI({
|
|
273
|
-
contentRoot: contentOptions.contentRoot,
|
|
274
|
-
canvasDir: contentOptions.canvasDir,
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// Get site instance for page operations (configured via routing.siteName)
|
|
278
|
-
const site = contentApi.getSite(contentOptions.siteName);
|
|
279
|
-
const locale = contentOptions.locale; // Configured via routing.locale
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Get all pages for static path generation.
|
|
283
|
-
* @param collection - Optional collection filter
|
|
284
|
-
*/
|
|
285
|
-
export async function getAllPages(collection) {
|
|
286
|
-
const pages = [];
|
|
287
|
-
|
|
288
|
-
// listPages is a generator that yields ContentManifest objects
|
|
289
|
-
for (const manifest of site.listPages(locale)) {
|
|
290
|
-
// Get the localized data for pathname/title
|
|
291
|
-
const localeData = manifest.locales[locale];
|
|
292
|
-
if (!localeData) continue;
|
|
293
|
-
|
|
294
|
-
const pathname = localeData.pathname || '/' + manifest.id.replace(/^index$/, '');
|
|
295
|
-
|
|
296
|
-
// Collection resolution: explicit collection in manifest, or default 'pages'
|
|
297
|
-
const resolvedCollection = manifest.collection || 'pages';
|
|
298
|
-
|
|
299
|
-
// Filter by requested collection
|
|
300
|
-
if (collection && resolvedCollection !== collection) continue;
|
|
301
|
-
|
|
302
|
-
pages.push({
|
|
303
|
-
id: manifest.id,
|
|
304
|
-
pathname: pathname,
|
|
305
|
-
title: localeData.meta?.title || manifest.id,
|
|
306
|
-
collection: resolvedCollection,
|
|
307
|
-
meta: localeData.meta || {},
|
|
308
|
-
timestamps: {
|
|
309
|
-
created: localeData.created,
|
|
310
|
-
modified: localeData.modified,
|
|
311
|
-
},
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return pages;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Get pages matching a path prefix.
|
|
320
|
-
* @param prefix - Path prefix to match (e.g., '/blog/')
|
|
321
|
-
* @param options - Optional sort and limit settings
|
|
322
|
-
* @returns Array of PageReference objects
|
|
323
|
-
*/
|
|
324
|
-
export async function getPagesByPrefix(prefix, options = {}) {
|
|
325
|
-
const allPages = await getAllPages();
|
|
326
|
-
|
|
327
|
-
let filtered = allPages.filter(page =>
|
|
328
|
-
page.pathname.startsWith(prefix) &&
|
|
329
|
-
page.pathname !== prefix && // Exclude the listing page itself
|
|
330
|
-
page.pathname !== prefix.slice(0, -1) // Exclude without trailing slash
|
|
331
|
-
);
|
|
332
|
-
|
|
333
|
-
// Sort by date (newest first by default)
|
|
334
|
-
if (options.sort === 'date-desc' || !options.sort) {
|
|
335
|
-
filtered.sort((a, b) => {
|
|
336
|
-
const dateA = a.timestamps?.modified || a.timestamps?.created || new Date(0);
|
|
337
|
-
const dateB = b.timestamps?.modified || b.timestamps?.created || new Date(0);
|
|
338
|
-
return new Date(dateB).getTime() - new Date(dateA).getTime();
|
|
339
|
-
});
|
|
340
|
-
} else if (options.sort === 'date-asc') {
|
|
341
|
-
filtered.sort((a, b) => {
|
|
342
|
-
const dateA = a.timestamps?.modified || a.timestamps?.created || new Date(0);
|
|
343
|
-
const dateB = b.timestamps?.modified || b.timestamps?.created || new Date(0);
|
|
344
|
-
return new Date(dateA).getTime() - new Date(dateB).getTime();
|
|
345
|
-
});
|
|
346
|
-
} else if (options.sort === 'title') {
|
|
347
|
-
filtered.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (options.limit && options.limit > 0) {
|
|
351
|
-
filtered = filtered.slice(0, options.limit);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
return filtered;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Load full page data for rendering.
|
|
359
|
-
* @param pathname - URL pathname (e.g., '/about')
|
|
360
|
-
* @param collection - Optional collection to search in
|
|
361
|
-
*/
|
|
362
|
-
export async function getPage(pathname, collection) {
|
|
363
|
-
// Use site.getByPathname which returns ContentManifest (metadata only)
|
|
364
|
-
const manifest = site.getByPathname(pathname, locale);
|
|
365
|
-
|
|
366
|
-
if (!manifest) {
|
|
367
|
-
const error = new Error(\`Page not found: \${pathname}\`);
|
|
368
|
-
error.code = 'PAGE_NOT_FOUND';
|
|
369
|
-
throw error;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// Optionally filter by collection
|
|
373
|
-
if (collection && manifest.collection !== collection) {
|
|
374
|
-
const error = new Error(\`Page not found: \${pathname}\`);
|
|
375
|
-
error.code = 'PAGE_NOT_FOUND';
|
|
376
|
-
throw error;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Get the full content with locale data
|
|
380
|
-
const content = await contentApi.getLocalized(manifest.id, locale);
|
|
381
|
-
|
|
382
|
-
if (!content) {
|
|
383
|
-
const error = new Error(\`Page not found: \${pathname}\`);
|
|
384
|
-
error.code = 'PAGE_NOT_FOUND';
|
|
385
|
-
throw error;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const localeData = content.localized;
|
|
389
|
-
const meta = localeData.meta || {};
|
|
390
|
-
|
|
391
|
-
return {
|
|
392
|
-
id: manifest.id,
|
|
393
|
-
title: meta.title || manifest.id,
|
|
394
|
-
description: meta.description,
|
|
395
|
-
pathname: pathname,
|
|
396
|
-
puckData: localeData.content?.puckData,
|
|
397
|
-
collection: manifest.collection || collection || 'pages',
|
|
398
|
-
route: {
|
|
399
|
-
name: 'pages', // Will be set by caller
|
|
400
|
-
pattern: '/[...slug]',
|
|
401
|
-
meta: {},
|
|
402
|
-
},
|
|
403
|
-
meta: meta,
|
|
404
|
-
timestamps: {
|
|
405
|
-
created: localeData.created,
|
|
406
|
-
modified: localeData.modified,
|
|
407
|
-
},
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Check if a page exists without loading full data.
|
|
413
|
-
* @param pathname - URL pathname
|
|
414
|
-
* @param collection - Optional collection filter
|
|
415
|
-
*/
|
|
416
|
-
export function pageExists(pathname, collection) {
|
|
417
|
-
// getByPathname is synchronous - returns ContentManifest | null
|
|
418
|
-
const manifest = site.getByPathname(pathname, locale);
|
|
419
|
-
|
|
420
|
-
if (!manifest) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// If collection filter specified, verify it matches
|
|
425
|
-
if (collection && manifest.collection !== collection) {
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
return true;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Get all entries from a data collection.
|
|
434
|
-
* @param collection - Data collection name
|
|
435
|
-
* @param localeOverride - Optional locale override (defaults to configured locale)
|
|
436
|
-
* @returns Array of DataCollectionEntry objects
|
|
437
|
-
*/
|
|
438
|
-
export async function getDataCollection(collection, localeOverride) {
|
|
439
|
-
const targetLocale = localeOverride || locale;
|
|
440
|
-
const entries = [];
|
|
441
|
-
|
|
442
|
-
// List all manifests in the collection
|
|
443
|
-
for (const manifest of contentApi.data.listContent({ collection })) {
|
|
444
|
-
// Get localized data for each entry
|
|
445
|
-
const localized = await contentApi.getLocalized(manifest.id, targetLocale);
|
|
446
|
-
if (localized) {
|
|
447
|
-
entries.push({
|
|
448
|
-
id: manifest.id,
|
|
449
|
-
name: manifest.name,
|
|
450
|
-
data: localized.content?.data || {},
|
|
451
|
-
meta: manifest.meta || {},
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return entries;
|
|
457
|
-
}
|
|
458
|
-
`;
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Generate the virtual:conloca-puck-config module.
|
|
462
|
-
*
|
|
463
|
-
* Returns a module that re-exports the Puck configuration.
|
|
464
|
-
* This is separate from the HMR-enabled puck-entry.js used by the CMS SPA.
|
|
465
|
-
*
|
|
466
|
-
* @param puckConfigPath - Path to the puck config module
|
|
467
|
-
* @returns JavaScript module code as a string
|
|
468
|
-
*/
|
|
469
|
-
function generatePuckConfigModule(puckConfigPath) {
|
|
470
|
-
return `export { default } from '${puckConfigPath.startsWith(".") ? `/${puckConfigPath.slice(2)}` : puckConfigPath}';`;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
64
|
//#endregion
|
|
474
|
-
|
|
475
|
-
if (typeof viteReact.preambleCode !== "string") throw new Error("@vitejs/plugin-react internal API changed: viteReact.preambleCode is no longer a string. This is an undocumented API used by @conloca/astro-cms for React Fast Refresh in virtual modules. Check @vitejs/plugin-react release notes and update the preamble injection logic.");
|
|
476
|
-
const reactRefreshPreamble = viteReact.preambleCode.replace("__BASE__", "/");
|
|
477
|
-
const PAGE_HANDLER_PATH = join(dirname(fileURLToPath(import.meta.url)), "handlers", "page-handler.astro");
|
|
478
|
-
const VIRTUAL_CONFIG_MODULE = "virtual:conloca-config";
|
|
479
|
-
const RESOLVED_VIRTUAL_CONFIG = `\0${VIRTUAL_CONFIG_MODULE}`;
|
|
480
|
-
const VIRTUAL_ROUTING_CONFIG = "virtual:conloca-routing-config";
|
|
481
|
-
const VIRTUAL_LAYOUT = "virtual:conloca-layout";
|
|
482
|
-
const VIRTUAL_PAGE_API = "virtual:conloca-page-api";
|
|
483
|
-
const VIRTUAL_PUCK_CONFIG = "virtual:conloca-puck-config";
|
|
484
|
-
const RESOLVED_ROUTING_CONFIG = `\0${VIRTUAL_ROUTING_CONFIG}`;
|
|
485
|
-
const RESOLVED_LAYOUT = `\0${VIRTUAL_LAYOUT}`;
|
|
486
|
-
const RESOLVED_PAGE_API = `\0${VIRTUAL_PAGE_API}`;
|
|
487
|
-
const RESOLVED_PUCK_CONFIG = `\0${VIRTUAL_PUCK_CONFIG}`;
|
|
488
|
-
const VIRTUAL_HYDRATION_REGISTRY = "virtual:conloca-hydration-registry";
|
|
489
|
-
const VIRTUAL_HYDRATION_ENTRY = "virtual:conloca-hydration-entry";
|
|
490
|
-
const RESOLVED_HYDRATION_REGISTRY = `\0${VIRTUAL_HYDRATION_REGISTRY}`;
|
|
491
|
-
const RESOLVED_HYDRATION_ENTRY = `\0${VIRTUAL_HYDRATION_ENTRY}`;
|
|
492
|
-
const VIRTUAL_CMS_SPA_ENTRY = "virtual:conloca-cms-spa-entry";
|
|
493
|
-
const RESOLVED_CMS_SPA_ENTRY = `\0${VIRTUAL_CMS_SPA_ENTRY}`;
|
|
494
|
-
const contentChangeListener = () => {
|
|
495
|
-
return `
|
|
496
|
-
// Content change listener that uses Vite HMR
|
|
497
|
-
if (import.meta.hot) {
|
|
498
|
-
import.meta.hot.on('conloca:content-update', (data) => {
|
|
499
|
-
console.log('[Conloca CMS] Content updated, invalidating cache:', data);
|
|
500
|
-
|
|
501
|
-
// Get the query client from the global scope and invalidate
|
|
502
|
-
if (window.__QUERY_CLIENT__) {
|
|
503
|
-
window.__QUERY_CLIENT__.invalidateQueries();
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
export default {};
|
|
509
|
-
`;
|
|
510
|
-
};
|
|
511
|
-
const puckConfigLoader = (absolutePuckPath) => {
|
|
512
|
-
return `
|
|
513
|
-
// Import and execute React refresh preamble first (from @vitejs/plugin-react)
|
|
514
|
-
${reactRefreshPreamble}
|
|
515
|
-
|
|
516
|
-
// Import the setPuckConfig function from cms-spa
|
|
517
|
-
import { setPuckConfig } from '@conloca/cms-spa/puck-config';
|
|
518
|
-
|
|
519
|
-
// Now dynamically import the config after preamble is ready
|
|
520
|
-
const puckConfigPromise = import('${absolutePuckPath}');
|
|
521
|
-
|
|
522
|
-
// Handle the initial load
|
|
523
|
-
puckConfigPromise.then(module => {
|
|
524
|
-
const puckConfig = module.default;
|
|
525
|
-
setPuckConfig(puckConfig);
|
|
526
|
-
|
|
527
|
-
// Hook into React Fast Refresh to detect component updates
|
|
528
|
-
if (window.__registerBeforePerformReactRefresh) {
|
|
529
|
-
window.__registerBeforePerformReactRefresh(async () => {
|
|
530
|
-
// Re-import the config module to get updated components
|
|
531
|
-
const newModule = await import('${absolutePuckPath}');
|
|
532
|
-
setPuckConfig(newModule.default);
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
});
|
|
65
|
+
export { blockMetaSchema, defineMdxComponents, definePageSchema, extractSlugFromPathname, findHydratableComponents, hasHydratableComponents, isHydratable, isPublished, localesFromAstroI18n, localesFromStarlight, pageMetaSchema, pathnameFromSlug, readStringAttribute, serializeProps, toDate, withHydration, writeStringAttribute };
|
|
536
66
|
|
|
537
|
-
// Accept HMR for this module itself
|
|
538
|
-
if (import.meta.hot) {
|
|
539
|
-
import.meta.hot.accept();
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
// Export the promise so the module has a default export
|
|
543
|
-
export default puckConfigPromise.then(m => m.default);
|
|
544
|
-
`;
|
|
545
|
-
};
|
|
546
|
-
const schemasLoader = (absoluteSchemasPath) => {
|
|
547
|
-
return `
|
|
548
|
-
import { setPageSchemas } from '@conloca/cms-spa/page-schemas';
|
|
549
|
-
import * as schemas from '${absoluteSchemasPath}';
|
|
550
|
-
|
|
551
|
-
if (schemas.pageSchemas) {
|
|
552
|
-
setPageSchemas(schemas.pageSchemas);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (import.meta.hot) {
|
|
556
|
-
import.meta.hot.accept('${absoluteSchemasPath}', async (newModule) => {
|
|
557
|
-
if (newModule?.pageSchemas) {
|
|
558
|
-
setPageSchemas(newModule.pageSchemas);
|
|
559
|
-
}
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
export default schemas;
|
|
564
|
-
`;
|
|
565
|
-
};
|
|
566
|
-
function conlocaCMS(options) {
|
|
567
|
-
const cmsRoute = options.route || "/__cms";
|
|
568
|
-
const routingConfig = normalizeRoutingConfig(options.routing, options.layout);
|
|
569
|
-
const hydrationDiscoveriesPromise = scanForHydratableComponents(deriveComponentPaths(options.puckConfigPath, options.componentPaths), process.cwd()).then((discoveries) => {
|
|
570
|
-
if (discoveries.length > 0) console.log(`[Conloca] Found ${discoveries.length} hydratable component(s)`);
|
|
571
|
-
return discoveries;
|
|
572
|
-
});
|
|
573
|
-
let resolvedRoutingConfig;
|
|
574
|
-
if (routingConfig?.enabled !== false && routingConfig) {
|
|
575
|
-
const resolvedRoutes = {};
|
|
576
|
-
for (const [name, config] of Object.entries(routingConfig.routes || {})) resolvedRoutes[name] = resolveRouteConfig(config);
|
|
577
|
-
resolvedRoutingConfig = {
|
|
578
|
-
enabled: routingConfig.enabled ?? true,
|
|
579
|
-
routes: resolvedRoutes,
|
|
580
|
-
fallback: routingConfig.fallback ?? "404",
|
|
581
|
-
onConflict: routingConfig.onConflict ?? "warn",
|
|
582
|
-
siteName: routingConfig.siteName ?? "default",
|
|
583
|
-
locale: routingConfig.locale ?? "en"
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
const spaConfig = {
|
|
587
|
-
basename: cmsRoute,
|
|
588
|
-
apiBaseUrl: `${cmsRoute}/api`,
|
|
589
|
-
siteBaseUrl: options.siteBaseUrl,
|
|
590
|
-
enableDevtools: options.enableDevtools ?? true,
|
|
591
|
-
queryClientOptions: options.queryClientOptions,
|
|
592
|
-
schemasPath: options.schemasPath,
|
|
593
|
-
projectRoot: process.cwd(),
|
|
594
|
-
templates: options.templates
|
|
595
|
-
};
|
|
596
|
-
return {
|
|
597
|
-
name: "@conloca/astro-cms",
|
|
598
|
-
hooks: {
|
|
599
|
-
"astro:config:setup": ({ updateConfig, injectRoute, command, logger }) => {
|
|
600
|
-
const astroRoot = process.cwd();
|
|
601
|
-
const contentAbsolute = resolve(options.contentRoot);
|
|
602
|
-
if (command === "dev" && !contentAbsolute.startsWith(astroRoot)) {
|
|
603
|
-
logger.info(`Auto-allowing contentRoot in Vite fs.allow: ${options.contentRoot}`);
|
|
604
|
-
updateConfig({ vite: { server: { fs: { allow: [searchForWorkspaceRoot(process.cwd()), contentAbsolute] } } } });
|
|
605
|
-
}
|
|
606
|
-
updateConfig({ vite: {
|
|
607
|
-
ssr: {
|
|
608
|
-
noExternal: [/^@conloca\//, "@puckeditor/core"],
|
|
609
|
-
external: ["@node-rs/xxhash"]
|
|
610
|
-
},
|
|
611
|
-
plugins: [{
|
|
612
|
-
name: "conloca-routing-virtual-modules",
|
|
613
|
-
resolveId(id) {
|
|
614
|
-
if (id === VIRTUAL_ROUTING_CONFIG) return RESOLVED_ROUTING_CONFIG;
|
|
615
|
-
if (id === VIRTUAL_LAYOUT) return RESOLVED_LAYOUT;
|
|
616
|
-
if (id === VIRTUAL_PAGE_API) return RESOLVED_PAGE_API;
|
|
617
|
-
if (id === VIRTUAL_PUCK_CONFIG) return RESOLVED_PUCK_CONFIG;
|
|
618
|
-
if (id === VIRTUAL_HYDRATION_REGISTRY) return RESOLVED_HYDRATION_REGISTRY;
|
|
619
|
-
if (id === VIRTUAL_HYDRATION_ENTRY) return RESOLVED_HYDRATION_ENTRY;
|
|
620
|
-
return null;
|
|
621
|
-
},
|
|
622
|
-
async load(id) {
|
|
623
|
-
if (id === RESOLVED_ROUTING_CONFIG) {
|
|
624
|
-
if (resolvedRoutingConfig) return generateRoutingConfigModule(resolvedRoutingConfig);
|
|
625
|
-
return "export default { enabled: false, routes: {}, fallback: \"404\", onConflict: \"warn\" };";
|
|
626
|
-
}
|
|
627
|
-
if (id === RESOLVED_LAYOUT) return generateLayoutModule(routingConfig);
|
|
628
|
-
if (id === RESOLVED_PAGE_API) return generatePageApiModule({
|
|
629
|
-
contentRoot: options.contentRoot,
|
|
630
|
-
canvasDir: options.canvasDir || "./canvas",
|
|
631
|
-
siteName: resolvedRoutingConfig?.siteName ?? "default",
|
|
632
|
-
locale: resolvedRoutingConfig?.locale ?? "en"
|
|
633
|
-
});
|
|
634
|
-
if (id === RESOLVED_PUCK_CONFIG) return generatePuckConfigModule(options.puckConfigPath);
|
|
635
|
-
if (id === RESOLVED_HYDRATION_REGISTRY) {
|
|
636
|
-
const discoveries = await hydrationDiscoveriesPromise;
|
|
637
|
-
if (discoveries.length > 0) return `// Generated by @conloca/astro-cms scanner
|
|
638
|
-
export const componentRegistry = {
|
|
639
|
-
${discoveries.map((d) => {
|
|
640
|
-
const relativePath = d.filePath.replace(process.cwd(), "");
|
|
641
|
-
return ` '${d.componentName}': {
|
|
642
|
-
loader: () => import('${relativePath}').then(m => m.${d.componentName}.render),
|
|
643
|
-
strategy: '${d.strategy}',
|
|
644
|
-
}`;
|
|
645
|
-
}).join(",\n")}
|
|
646
|
-
};`;
|
|
647
|
-
return "export const componentRegistry = {};";
|
|
648
|
-
}
|
|
649
|
-
if (id === RESOLVED_HYDRATION_ENTRY) return `import { initHydration } from '@conloca/astro-cms/lib/hydration-script'
|
|
650
|
-
import { componentRegistry } from 'virtual:conloca-hydration-registry'
|
|
651
|
-
|
|
652
|
-
// Auto-initialize hydration when this module loads
|
|
653
|
-
initHydration(componentRegistry)
|
|
654
|
-
`;
|
|
655
|
-
return null;
|
|
656
|
-
}
|
|
657
|
-
}]
|
|
658
|
-
} });
|
|
659
|
-
if (resolvedRoutingConfig?.enabled) for (const [routeName, routeConfig] of Object.entries(resolvedRoutingConfig.routes)) {
|
|
660
|
-
logger.info(`Injecting content route: ${routeConfig.pattern} (${routeName})`);
|
|
661
|
-
injectRoute({
|
|
662
|
-
pattern: routeConfig.pattern,
|
|
663
|
-
entrypoint: PAGE_HANDLER_PATH,
|
|
664
|
-
prerender: routeConfig.prerender
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
if (command !== "dev") return;
|
|
668
|
-
updateConfig({ vite: {
|
|
669
|
-
define: {
|
|
670
|
-
"import.meta.env.CONLOCA_CONTENT_ROOT": JSON.stringify(options.contentRoot),
|
|
671
|
-
"import.meta.env.CONLOCA_CANVAS_DIR": JSON.stringify(options.canvasDir || "./canvas"),
|
|
672
|
-
"import.meta.env.CONLOCA_PUCK_CONFIG_PATH": JSON.stringify(options.puckConfigPath),
|
|
673
|
-
"import.meta.env.CONLOCA_ASSETS_PATH": JSON.stringify(options.assetsPath || "")
|
|
674
|
-
},
|
|
675
|
-
resolve: {
|
|
676
|
-
dedupe: [
|
|
677
|
-
"react",
|
|
678
|
-
"react-dom",
|
|
679
|
-
"react/jsx-runtime",
|
|
680
|
-
"react/jsx-dev-runtime",
|
|
681
|
-
"@puckeditor/core",
|
|
682
|
-
"@tanstack/react-query"
|
|
683
|
-
],
|
|
684
|
-
preserveSymlinks: true
|
|
685
|
-
},
|
|
686
|
-
optimizeDeps: {
|
|
687
|
-
exclude: [options.puckConfigPath],
|
|
688
|
-
include: [
|
|
689
|
-
"react",
|
|
690
|
-
"react-dom",
|
|
691
|
-
"react-dom/client",
|
|
692
|
-
"react/jsx-runtime",
|
|
693
|
-
"react/jsx-dev-runtime",
|
|
694
|
-
"@mdxeditor/editor",
|
|
695
|
-
"@puckeditor/core",
|
|
696
|
-
"@tanstack/react-query",
|
|
697
|
-
"@tanstack/react-query-devtools",
|
|
698
|
-
"react-router-dom",
|
|
699
|
-
"@radix-ui/react-dialog",
|
|
700
|
-
"@radix-ui/react-select",
|
|
701
|
-
"lucide-react",
|
|
702
|
-
"clsx",
|
|
703
|
-
"tailwind-merge",
|
|
704
|
-
"zod",
|
|
705
|
-
"yaml",
|
|
706
|
-
"nanoid",
|
|
707
|
-
"sort-keys",
|
|
708
|
-
"@mdx-js/mdx",
|
|
709
|
-
"remark-frontmatter",
|
|
710
|
-
"remark-gfm",
|
|
711
|
-
"remark-mdx-frontmatter"
|
|
712
|
-
]
|
|
713
|
-
},
|
|
714
|
-
plugins: [
|
|
715
|
-
{
|
|
716
|
-
name: "conloca-resolve-normalizer",
|
|
717
|
-
enforce: "pre",
|
|
718
|
-
async resolveId(source, importer) {
|
|
719
|
-
if (!source.startsWith("@conloca/")) return null;
|
|
720
|
-
if (!importer || importer.startsWith(astroRoot)) return null;
|
|
721
|
-
if (importer.startsWith("\0")) return null;
|
|
722
|
-
return await this.resolve(source, join(astroRoot, "_resolveAnchor.js"), { skipSelf: true });
|
|
723
|
-
}
|
|
724
|
-
},
|
|
725
|
-
{
|
|
726
|
-
name: "conloca-dev-virtual-modules",
|
|
727
|
-
resolveId(id) {
|
|
728
|
-
if (id === VIRTUAL_CONFIG_MODULE) return RESOLVED_VIRTUAL_CONFIG;
|
|
729
|
-
if (id === `${cmsRoute}/puck-entry.js`) return id;
|
|
730
|
-
if (id === `${cmsRoute}/content-listener.js`) return id;
|
|
731
|
-
if (id === `${cmsRoute}/schemas-entry.js`) return id;
|
|
732
|
-
if (id === VIRTUAL_CMS_SPA_ENTRY) return RESOLVED_CMS_SPA_ENTRY;
|
|
733
|
-
if (id === `${cmsRoute}/cms-spa-entry.js`) return RESOLVED_CMS_SPA_ENTRY;
|
|
734
|
-
return null;
|
|
735
|
-
},
|
|
736
|
-
load(id) {
|
|
737
|
-
if (id === RESOLVED_VIRTUAL_CONFIG) return `export default ${JSON.stringify(spaConfig)};`;
|
|
738
|
-
if (id === `${cmsRoute}/puck-entry.js`) return puckConfigLoader(options.puckConfigPath.startsWith(".") ? `/${options.puckConfigPath.slice(2)}` : options.puckConfigPath);
|
|
739
|
-
if (id === `${cmsRoute}/content-listener.js`) return contentChangeListener();
|
|
740
|
-
if (id === `${cmsRoute}/schemas-entry.js`) {
|
|
741
|
-
if (options.schemasPath) return schemasLoader(options.schemasPath.startsWith(".") ? `/${options.schemasPath.slice(2)}` : options.schemasPath);
|
|
742
|
-
return "export default {};";
|
|
743
|
-
}
|
|
744
|
-
if (id === RESOLVED_CMS_SPA_ENTRY) {
|
|
745
|
-
let cmsSpaImport;
|
|
746
|
-
try {
|
|
747
|
-
const cmsSpaPackageJsonPath = import.meta.resolve("@conloca/cms-spa/package.json");
|
|
748
|
-
const srcMainPath = join(dirname(cmsSpaPackageJsonPath.startsWith("file://") ? fileURLToPath(cmsSpaPackageJsonPath) : cmsSpaPackageJsonPath), "src", "main.tsx");
|
|
749
|
-
if (existsSync(srcMainPath)) cmsSpaImport = `import '${srcMainPath}';`;
|
|
750
|
-
else cmsSpaImport = "import '@conloca/cms-spa/main';";
|
|
751
|
-
} catch {
|
|
752
|
-
cmsSpaImport = "import '@conloca/cms-spa/main';";
|
|
753
|
-
}
|
|
754
|
-
return `
|
|
755
|
-
// Import and execute React refresh preamble first (from @vitejs/plugin-react)
|
|
756
|
-
${reactRefreshPreamble}
|
|
757
|
-
|
|
758
|
-
// Import cms-spa through Vite
|
|
759
|
-
// Vite will resolve React from its pre-bundled deps (same instance as puck.config.tsx)
|
|
760
|
-
${cmsSpaImport}
|
|
761
|
-
|
|
762
|
-
// Accept HMR
|
|
763
|
-
if (import.meta.hot) {
|
|
764
|
-
import.meta.hot.accept();
|
|
765
|
-
}
|
|
766
|
-
`;
|
|
767
|
-
}
|
|
768
|
-
return null;
|
|
769
|
-
}
|
|
770
|
-
},
|
|
771
|
-
{
|
|
772
|
-
name: "conloca-content-watcher",
|
|
773
|
-
async configureServer(server) {
|
|
774
|
-
const contentApi = await createContentAPI({
|
|
775
|
-
contentRoot: options.contentRoot,
|
|
776
|
-
canvasDir: options.canvasDir || "./canvas"
|
|
777
|
-
});
|
|
778
|
-
const { resolve } = await import("node:path");
|
|
779
|
-
const astroRoot = process.cwd();
|
|
780
|
-
const contentAbsolute = resolve(options.contentRoot);
|
|
781
|
-
const canvasAbsolute = resolve(options.canvasDir || "./canvas");
|
|
782
|
-
const foldersToWatch = [];
|
|
783
|
-
if (!contentAbsolute.startsWith(astroRoot)) {
|
|
784
|
-
console.log(`[Astro Integration] Content outside project, adding to watcher: ${options.contentRoot}`);
|
|
785
|
-
foldersToWatch.push(options.contentRoot);
|
|
786
|
-
} else console.log(`[Astro Integration] Content inside project, Vite will watch automatically: ${options.contentRoot}`);
|
|
787
|
-
if (!canvasAbsolute.startsWith(astroRoot)) {
|
|
788
|
-
console.log(`[Astro Integration] Canvas outside project, adding to watcher: ${options.canvasDir || "./canvas"}`);
|
|
789
|
-
foldersToWatch.push(options.canvasDir || "./canvas");
|
|
790
|
-
} else console.log(`[Astro Integration] Canvas inside project, Vite will watch automatically: ${options.canvasDir || "./canvas"}`);
|
|
791
|
-
if (foldersToWatch.length > 0) server.watcher.add(foldersToWatch);
|
|
792
|
-
const handlers = createContentWatchHandlers(contentApi, {
|
|
793
|
-
contentRoot: options.contentRoot,
|
|
794
|
-
canvasDir: options.canvasDir || "./canvas"
|
|
795
|
-
}, server.ws);
|
|
796
|
-
server.watcher.on("change", handlers.onChange);
|
|
797
|
-
server.watcher.on("add", handlers.onAdd);
|
|
798
|
-
server.watcher.on("unlink", handlers.onUnlink);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
]
|
|
802
|
-
} });
|
|
803
|
-
injectRoute({
|
|
804
|
-
pattern: `${cmsRoute}/[...path]`,
|
|
805
|
-
entrypoint: "@conloca/astro-cms/cms-handler",
|
|
806
|
-
prerender: false
|
|
807
|
-
});
|
|
808
|
-
injectRoute({
|
|
809
|
-
pattern: cmsRoute,
|
|
810
|
-
entrypoint: "@conloca/astro-cms/cms-handler",
|
|
811
|
-
prerender: false
|
|
812
|
-
});
|
|
813
|
-
},
|
|
814
|
-
"astro:server:setup": ({ logger }) => {
|
|
815
|
-
logger.info(`Conloca CMS available at ${cmsRoute}`);
|
|
816
|
-
},
|
|
817
|
-
"astro:routes:resolved": ({ routes, logger }) => {
|
|
818
|
-
if (!resolvedRoutingConfig?.enabled) return;
|
|
819
|
-
const injectedPatterns = new Set(Object.values(resolvedRoutingConfig.routes).map((r) => r.pattern));
|
|
820
|
-
const conflicts = [];
|
|
821
|
-
for (const route of routes) {
|
|
822
|
-
if (route.origin === "internal") continue;
|
|
823
|
-
const entrypoint = route.entrypoint || "";
|
|
824
|
-
if (entrypoint.includes("page-handler.astro")) continue;
|
|
825
|
-
const pattern = route.pattern;
|
|
826
|
-
if (injectedPatterns.has(pattern)) conflicts.push({
|
|
827
|
-
injected: pattern,
|
|
828
|
-
fileBased: entrypoint || pattern
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
if (conflicts.length === 0) return;
|
|
832
|
-
const onConflict = resolvedRoutingConfig.onConflict;
|
|
833
|
-
for (const conflict of conflicts) {
|
|
834
|
-
const message = `Route conflict: '${conflict.injected}' is defined both in ${conflict.fileBased} and injected by Conloca routing. Conloca route will take precedence.`;
|
|
835
|
-
if (onConflict === "error") throw new Error(`[Conloca] ${message}`);
|
|
836
|
-
if (onConflict === "warn") logger.warn(message);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
//#endregion
|
|
844
|
-
export { blockMetaSchema, conlocaCMS, conlocaLoader, extractSlugFromPathname, findHydratableComponents, hasHydratableComponents, isHydratable, pageMetaSchema, pathnameFromSlug, scanForHydratableComponents, serializeProps, withHydration };
|
|
845
67
|
//# sourceMappingURL=index.mjs.map
|