@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,121 @@
|
|
|
1
|
+
import { createContentAPI } from '@conloca/content-api/reader';
|
|
2
|
+
/**
|
|
3
|
+
* Error class for page not found scenarios.
|
|
4
|
+
*/
|
|
5
|
+
export class PageNotFoundError extends Error {
|
|
6
|
+
code = 'PAGE_NOT_FOUND';
|
|
7
|
+
constructor(pathname) {
|
|
8
|
+
super(`Page not found: ${pathname}`);
|
|
9
|
+
this.name = 'PageNotFoundError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create a PageAPI instance for loading page data.
|
|
14
|
+
*
|
|
15
|
+
* Wraps ContentAPI with a cleaner interface focused on
|
|
16
|
+
* page rendering needs.
|
|
17
|
+
*
|
|
18
|
+
* @param options - Configuration for ContentAPI initialization
|
|
19
|
+
* @returns PageAPI instance
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const api = await createPageAPI({
|
|
24
|
+
* contentRoot: '../content',
|
|
25
|
+
* canvasDir: './canvas',
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const pages = await api.getAllPages('pages');
|
|
29
|
+
* const page = await api.getPage('/about');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export async function createPageAPI(options) {
|
|
33
|
+
const contentApi = await createContentAPI({
|
|
34
|
+
contentRoot: options.contentRoot,
|
|
35
|
+
canvasDir: options.canvasDir,
|
|
36
|
+
});
|
|
37
|
+
const siteName = options.siteName || 'default';
|
|
38
|
+
const locale = options.locale || 'en';
|
|
39
|
+
// Get the site for page operations
|
|
40
|
+
const site = contentApi.getSite(siteName);
|
|
41
|
+
if (!site) {
|
|
42
|
+
throw new Error(`Site '${siteName}' not found in content configuration`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
async getAllPages(collection) {
|
|
46
|
+
const pages = [];
|
|
47
|
+
// Use site.listPages() generator to get all pages
|
|
48
|
+
for (const manifest of site.listPages(locale)) {
|
|
49
|
+
// Filter by collection if specified
|
|
50
|
+
if (collection && manifest.collection !== collection) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
// Get the localized data for pathname
|
|
54
|
+
const localeData = manifest.locales[locale];
|
|
55
|
+
if (!localeData)
|
|
56
|
+
continue;
|
|
57
|
+
pages.push({
|
|
58
|
+
id: manifest.id,
|
|
59
|
+
pathname: localeData.pathname || `/${manifest.id.replace(/^index$/, '')}`,
|
|
60
|
+
title: localeData.meta?.title || manifest.id,
|
|
61
|
+
collection: manifest.collection || 'pages',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return pages;
|
|
65
|
+
},
|
|
66
|
+
async getPage(pathname, collection) {
|
|
67
|
+
// Use site.getByPathname to find the content by pathname
|
|
68
|
+
const manifest = site.getByPathname(pathname, locale);
|
|
69
|
+
if (!manifest) {
|
|
70
|
+
throw new PageNotFoundError(pathname);
|
|
71
|
+
}
|
|
72
|
+
// Optionally filter by collection
|
|
73
|
+
if (collection && manifest.collection !== collection) {
|
|
74
|
+
throw new PageNotFoundError(pathname);
|
|
75
|
+
}
|
|
76
|
+
// Get the full content with locale data
|
|
77
|
+
const content = await contentApi.getLocalized(manifest.id, locale);
|
|
78
|
+
if (!content) {
|
|
79
|
+
throw new PageNotFoundError(pathname);
|
|
80
|
+
}
|
|
81
|
+
const localeData = content.localized;
|
|
82
|
+
const meta = localeData.meta || {};
|
|
83
|
+
return {
|
|
84
|
+
id: manifest.id,
|
|
85
|
+
title: meta.title || manifest.id,
|
|
86
|
+
description: meta.description,
|
|
87
|
+
pathname,
|
|
88
|
+
puckData: localeData.content.puckData,
|
|
89
|
+
collection: manifest.collection || collection || 'pages',
|
|
90
|
+
route: {
|
|
91
|
+
// These will be overwritten by the caller with actual route info
|
|
92
|
+
name: 'pages',
|
|
93
|
+
pattern: '/[...slug]',
|
|
94
|
+
meta: {},
|
|
95
|
+
},
|
|
96
|
+
meta,
|
|
97
|
+
timestamps: {
|
|
98
|
+
created: localeData.created ? new Date(localeData.created) : undefined,
|
|
99
|
+
modified: localeData.modified ? new Date(localeData.modified) : undefined,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
async pageExists(pathname, collection) {
|
|
104
|
+
try {
|
|
105
|
+
// Use site.getByPathname to check existence
|
|
106
|
+
const manifest = site.getByPathname(pathname, locale);
|
|
107
|
+
if (!manifest) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
// If collection filter specified, verify it matches
|
|
111
|
+
if (collection && manifest.collection !== collection) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare function toDate(value: string | Date | null | undefined): Date | undefined;
|
|
2
|
+
interface PublishSchedule {
|
|
3
|
+
publishAt?: string | Date | null;
|
|
4
|
+
unpublishAt?: string | Date | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function isPublished(data: PublishSchedule): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Extract slug from pathname given a route pattern.
|
|
9
|
+
*
|
|
10
|
+
* The slug is the portion of the pathname that comes after the
|
|
11
|
+
* static prefix of the pattern.
|
|
12
|
+
*
|
|
13
|
+
* @param pathname - URL pathname (e.g., '/about', '/blog/post-1')
|
|
14
|
+
* @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
|
|
15
|
+
* @returns The extracted slug, or undefined for root paths
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* extractSlugFromPathname('/about', '/[...slug]') // 'about'
|
|
19
|
+
* extractSlugFromPathname('/blog/post-1', '/blog/[...slug]') // 'post-1'
|
|
20
|
+
* extractSlugFromPathname('/', '/[...slug]') // undefined
|
|
21
|
+
* extractSlugFromPathname('/blog', '/blog/[...slug]') // undefined
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractSlugFromPathname(pathname: string, pattern: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Convert a slug back to a pathname given a route pattern.
|
|
26
|
+
*
|
|
27
|
+
* The inverse of extractSlugFromPathname.
|
|
28
|
+
*
|
|
29
|
+
* @param slug - The page slug (e.g., 'about', 'post-1'), or undefined for root
|
|
30
|
+
* @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
|
|
31
|
+
* @returns Full URL pathname
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* pathnameFromSlug('about', '/[...slug]') // '/about'
|
|
35
|
+
* pathnameFromSlug('post-1', '/blog/[...slug]') // '/blog/post-1'
|
|
36
|
+
* pathnameFromSlug(undefined, '/[...slug]') // '/'
|
|
37
|
+
* pathnameFromSlug(undefined, '/blog/[...slug]') // '/blog'
|
|
38
|
+
*/
|
|
39
|
+
export declare function pathnameFromSlug(slug: string | undefined, pattern: string): string;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=route-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/route-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,oBAY7D;AAED,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACpC;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,WAchD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiB7F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAYlF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export function toDate(value) {
|
|
2
|
+
if (!value) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
if (value instanceof Date) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
const parsed = new Date(value);
|
|
9
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
10
|
+
}
|
|
11
|
+
export function isPublished(data) {
|
|
12
|
+
const now = new Date();
|
|
13
|
+
const publishAt = toDate(data.publishAt);
|
|
14
|
+
const unpublishAt = toDate(data.unpublishAt);
|
|
15
|
+
if (publishAt && publishAt > now) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (unpublishAt && unpublishAt <= now) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Extract slug from pathname given a route pattern.
|
|
25
|
+
*
|
|
26
|
+
* The slug is the portion of the pathname that comes after the
|
|
27
|
+
* static prefix of the pattern.
|
|
28
|
+
*
|
|
29
|
+
* @param pathname - URL pathname (e.g., '/about', '/blog/post-1')
|
|
30
|
+
* @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
|
|
31
|
+
* @returns The extracted slug, or undefined for root paths
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* extractSlugFromPathname('/about', '/[...slug]') // 'about'
|
|
35
|
+
* extractSlugFromPathname('/blog/post-1', '/blog/[...slug]') // 'post-1'
|
|
36
|
+
* extractSlugFromPathname('/', '/[...slug]') // undefined
|
|
37
|
+
* extractSlugFromPathname('/blog', '/blog/[...slug]') // undefined
|
|
38
|
+
*/
|
|
39
|
+
export function extractSlugFromPathname(pathname, pattern) {
|
|
40
|
+
// Pattern: /[...slug] -> prefix: ''
|
|
41
|
+
// Pattern: /blog/[...slug] -> prefix: '/blog'
|
|
42
|
+
// Pattern: /docs/[...path] -> prefix: '/docs'
|
|
43
|
+
const prefixMatch = pattern.match(/^(.*?)\[/);
|
|
44
|
+
const prefix = prefixMatch ? prefixMatch[1].replace(/\/$/, '') : '';
|
|
45
|
+
// Remove prefix from pathname
|
|
46
|
+
const slugPart = pathname.slice(prefix.length);
|
|
47
|
+
// Remove leading slash
|
|
48
|
+
const slug = slugPart.replace(/^\//, '');
|
|
49
|
+
// Empty string means root page (e.g., /blog for /blog/[...slug])
|
|
50
|
+
// Return undefined for root to match [...slug] behavior
|
|
51
|
+
return slug || undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Convert a slug back to a pathname given a route pattern.
|
|
55
|
+
*
|
|
56
|
+
* The inverse of extractSlugFromPathname.
|
|
57
|
+
*
|
|
58
|
+
* @param slug - The page slug (e.g., 'about', 'post-1'), or undefined for root
|
|
59
|
+
* @param pattern - Route pattern (e.g., '/[...slug]', '/blog/[...slug]')
|
|
60
|
+
* @returns Full URL pathname
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* pathnameFromSlug('about', '/[...slug]') // '/about'
|
|
64
|
+
* pathnameFromSlug('post-1', '/blog/[...slug]') // '/blog/post-1'
|
|
65
|
+
* pathnameFromSlug(undefined, '/[...slug]') // '/'
|
|
66
|
+
* pathnameFromSlug(undefined, '/blog/[...slug]') // '/blog'
|
|
67
|
+
*/
|
|
68
|
+
export function pathnameFromSlug(slug, pattern) {
|
|
69
|
+
// Extract the static prefix before the dynamic segment
|
|
70
|
+
const prefixMatch = pattern.match(/^(.*?)\[/);
|
|
71
|
+
const prefix = prefixMatch ? prefixMatch[1].replace(/\/$/, '') : '';
|
|
72
|
+
if (!slug) {
|
|
73
|
+
// No slug means root of this pattern
|
|
74
|
+
return prefix || '/';
|
|
75
|
+
}
|
|
76
|
+
// Combine prefix and slug
|
|
77
|
+
return `${prefix}/${slug}`;
|
|
78
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RouteConfig, RoutingConfig, RoutingConfigInput } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize routing config input to full RoutingConfig.
|
|
4
|
+
*
|
|
5
|
+
* Handles the `routing: true` shorthand, boolean values, and top-level layout option.
|
|
6
|
+
*
|
|
7
|
+
* @param input - The routing config input (boolean, object, or undefined)
|
|
8
|
+
* @param topLevelLayout - Optional top-level layout path (enables routing when provided)
|
|
9
|
+
* @returns Normalized RoutingConfig or undefined if not enabled
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeRoutingConfig(input: RoutingConfigInput | undefined, topLevelLayout?: string): RoutingConfig | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Apply defaults to a RouteConfig.
|
|
14
|
+
*
|
|
15
|
+
* Fills in missing optional fields with their default values.
|
|
16
|
+
*
|
|
17
|
+
* @param config - Partial route configuration
|
|
18
|
+
* @returns Complete route configuration with all fields
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveRouteConfig(config: RouteConfig): Required<RouteConfig>;
|
|
21
|
+
/**
|
|
22
|
+
* Validate a route pattern.
|
|
23
|
+
*
|
|
24
|
+
* Ensures the pattern is a valid Astro route pattern.
|
|
25
|
+
* Throws descriptive error if invalid.
|
|
26
|
+
*
|
|
27
|
+
* @param pattern - The route pattern to validate
|
|
28
|
+
* @param routeName - Name of the route (for error messages)
|
|
29
|
+
* @throws Error if pattern is invalid
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateRoutePattern(pattern: string, routeName: string): void;
|
|
32
|
+
//# sourceMappingURL=routing-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing-config.d.ts","sourceRoot":"","sources":["../../../src/lib/routing-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAElF;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,kBAAkB,GAAG,SAAS,EACrC,cAAc,CAAC,EAAE,MAAM,GACtB,aAAa,GAAG,SAAS,CA0C3B;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,CAS7E;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAkB7E"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize routing config input to full RoutingConfig.
|
|
3
|
+
*
|
|
4
|
+
* Handles the `routing: true` shorthand, boolean values, and top-level layout option.
|
|
5
|
+
*
|
|
6
|
+
* @param input - The routing config input (boolean, object, or undefined)
|
|
7
|
+
* @param topLevelLayout - Optional top-level layout path (enables routing when provided)
|
|
8
|
+
* @returns Normalized RoutingConfig or undefined if not enabled
|
|
9
|
+
*/
|
|
10
|
+
export function normalizeRoutingConfig(input, topLevelLayout) {
|
|
11
|
+
// If no routing config but layout provided, enable with defaults
|
|
12
|
+
if (input === undefined && topLevelLayout) {
|
|
13
|
+
return {
|
|
14
|
+
enabled: true,
|
|
15
|
+
routes: {
|
|
16
|
+
pages: {
|
|
17
|
+
pattern: '/[...slug]',
|
|
18
|
+
collection: 'pages',
|
|
19
|
+
layout: topLevelLayout,
|
|
20
|
+
prerender: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
fallback: '404',
|
|
24
|
+
onConflict: 'warn',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (input === undefined) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (input === true) {
|
|
31
|
+
return {
|
|
32
|
+
enabled: true,
|
|
33
|
+
routes: {
|
|
34
|
+
pages: {
|
|
35
|
+
pattern: '/[...slug]',
|
|
36
|
+
collection: 'pages',
|
|
37
|
+
prerender: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
fallback: '404',
|
|
41
|
+
onConflict: 'warn',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (input === false) {
|
|
45
|
+
return { enabled: false };
|
|
46
|
+
}
|
|
47
|
+
return input;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Apply defaults to a RouteConfig.
|
|
51
|
+
*
|
|
52
|
+
* Fills in missing optional fields with their default values.
|
|
53
|
+
*
|
|
54
|
+
* @param config - Partial route configuration
|
|
55
|
+
* @returns Complete route configuration with all fields
|
|
56
|
+
*/
|
|
57
|
+
export function resolveRouteConfig(config) {
|
|
58
|
+
return {
|
|
59
|
+
pattern: config.pattern,
|
|
60
|
+
collection: config.collection ?? 'pages',
|
|
61
|
+
layout: config.layout ?? '',
|
|
62
|
+
prerender: config.prerender ?? true,
|
|
63
|
+
meta: config.meta ?? {},
|
|
64
|
+
dataBindings: config.dataBindings ?? { collections: [] },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Validate a route pattern.
|
|
69
|
+
*
|
|
70
|
+
* Ensures the pattern is a valid Astro route pattern.
|
|
71
|
+
* Throws descriptive error if invalid.
|
|
72
|
+
*
|
|
73
|
+
* @param pattern - The route pattern to validate
|
|
74
|
+
* @param routeName - Name of the route (for error messages)
|
|
75
|
+
* @throws Error if pattern is invalid
|
|
76
|
+
*/
|
|
77
|
+
export function validateRoutePattern(pattern, routeName) {
|
|
78
|
+
if (!pattern.startsWith('/')) {
|
|
79
|
+
throw new Error(`Route '${routeName}': pattern must start with '/', got '${pattern}'`);
|
|
80
|
+
}
|
|
81
|
+
// Check for valid Astro route syntax
|
|
82
|
+
// Allow: a-zA-Z0-9, hyphen, underscore, slash, brackets, dots
|
|
83
|
+
const invalidChars = pattern.match(/[^a-zA-Z0-9\-_/[\].]/g);
|
|
84
|
+
if (invalidChars) {
|
|
85
|
+
throw new Error(`Route '${routeName}': pattern contains invalid characters: ${invalidChars.join(', ')}`);
|
|
86
|
+
}
|
|
87
|
+
// Check for balanced brackets
|
|
88
|
+
const openBrackets = (pattern.match(/\[/g) || []).length;
|
|
89
|
+
const closeBrackets = (pattern.match(/\]/g) || []).length;
|
|
90
|
+
if (openBrackets !== closeBrackets) {
|
|
91
|
+
throw new Error(`Route '${routeName}': pattern has unbalanced brackets: '${pattern}'`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-props.d.ts","sourceRoot":"","sources":["../../../src/lib/serialize-props.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAErE"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ResolvedRoutingConfig, RoutingConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate the virtual:conloca-routing-config module.
|
|
4
|
+
*
|
|
5
|
+
* Returns a module that exports the resolved routing configuration as default.
|
|
6
|
+
*
|
|
7
|
+
* @param config - Resolved routing configuration with all defaults applied
|
|
8
|
+
* @returns JavaScript module code as a string
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateRoutingConfigModule(config: ResolvedRoutingConfig): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate the virtual:conloca-layout module.
|
|
13
|
+
*
|
|
14
|
+
* Returns a module that re-exports the layout component or exports undefined
|
|
15
|
+
* if no layout is configured.
|
|
16
|
+
*
|
|
17
|
+
* Currently uses the first route's layout. Multi-layout support is future work.
|
|
18
|
+
*
|
|
19
|
+
* @param routing - Routing configuration (may be undefined if routing disabled)
|
|
20
|
+
* @returns JavaScript module code as a string
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateLayoutModule(routing: RoutingConfig | undefined): string;
|
|
23
|
+
/**
|
|
24
|
+
* Options for generating the page API module.
|
|
25
|
+
*/
|
|
26
|
+
export interface PageApiModuleOptions {
|
|
27
|
+
contentRoot: string;
|
|
28
|
+
canvasDir: string;
|
|
29
|
+
/** Site name for content resolution. @default 'default' */
|
|
30
|
+
siteName: string;
|
|
31
|
+
/** Default locale for content resolution. @default 'en' */
|
|
32
|
+
locale: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generate the virtual:conloca-page-api module.
|
|
36
|
+
*
|
|
37
|
+
* Returns a module that provides page loading functions wrapping ContentAPI:
|
|
38
|
+
* - getAllPages(collection?) - For getStaticPaths()
|
|
39
|
+
* - getPage(pathname, collection?) - For page data loading
|
|
40
|
+
* - pageExists(pathname, collection?) - For 404 checks
|
|
41
|
+
* - contentOptions - Configuration for ContentAPI (for MDX evaluation)
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration for ContentAPI initialization
|
|
44
|
+
* @returns JavaScript module code as a string
|
|
45
|
+
*/
|
|
46
|
+
export declare function generatePageApiModule(options: PageApiModuleOptions): string;
|
|
47
|
+
/**
|
|
48
|
+
* Generate the virtual:conloca-puck-config module.
|
|
49
|
+
*
|
|
50
|
+
* Returns a module that re-exports the Puck configuration.
|
|
51
|
+
* This is separate from the HMR-enabled puck-entry.js used by the CMS SPA.
|
|
52
|
+
*
|
|
53
|
+
* @param puckConfigPath - Path to the puck config module
|
|
54
|
+
* @returns JavaScript module code as a string
|
|
55
|
+
*/
|
|
56
|
+
export declare function generatePuckConfigModule(puckConfigPath: string): string;
|
|
57
|
+
//# sourceMappingURL=virtual-module-generators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual-module-generators.d.ts","sourceRoot":"","sources":["../../../src/lib/virtual-module-generators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAEjF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAe/E;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAwM3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAMvE"}
|