@conloca/astro-cms 0.1.15 → 0.2.0
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 +259 -247
- package/dist/internal/acorn-default.mjs +11 -3
- package/dist/internal/page-handler.astro +137 -358
- package/dist/ts/node/content.d.ts +4 -0
- package/dist/ts/node/content.d.ts.map +1 -0
- package/dist/ts/node/content.js +3 -0
- package/dist/ts/node/content.js.map +1 -0
- package/dist/ts/node/index.d.ts +9 -0
- package/dist/ts/node/index.d.ts.map +1 -0
- package/dist/ts/node/index.js +14 -0
- package/dist/ts/node/index.js.map +1 -0
- package/dist/ts/src/asset-ref-base.d.ts +3 -0
- package/dist/ts/src/asset-ref-base.d.ts.map +1 -0
- package/dist/ts/src/asset-ref-base.js +48 -0
- package/dist/ts/src/asset-ref-base.js.map +1 -0
- package/dist/ts/src/checks.d.ts +7 -0
- package/dist/ts/src/checks.d.ts.map +1 -0
- package/dist/ts/src/checks.js +7 -0
- package/dist/ts/src/checks.js.map +1 -0
- package/dist/ts/src/cms-handler.d.ts +18 -0
- package/dist/ts/src/cms-handler.d.ts.map +1 -0
- package/dist/ts/src/cms-handler.js +245 -0
- package/dist/ts/src/cms-handler.js.map +1 -0
- package/dist/ts/src/collections.d.ts +160 -0
- package/dist/ts/src/collections.d.ts.map +1 -0
- package/dist/ts/src/collections.js +170 -0
- package/dist/ts/src/collections.js.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts +18 -0
- package/dist/ts/src/components/HydrationWrapper.d.ts.map +1 -0
- package/dist/ts/src/components/HydrationWrapper.js +22 -0
- package/dist/ts/src/components/HydrationWrapper.js.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts +27 -0
- package/dist/ts/src/components/RenderWithFragments.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithFragments.js +133 -0
- package/dist/ts/src/components/RenderWithFragments.js.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts +21 -0
- package/dist/ts/src/components/RenderWithHydration.d.ts.map +1 -0
- package/dist/ts/src/components/RenderWithHydration.js +39 -0
- package/dist/ts/src/components/RenderWithHydration.js.map +1 -0
- package/dist/ts/src/components.d.ts +4 -0
- package/dist/ts/src/components.d.ts.map +1 -0
- package/dist/ts/src/components.js +4 -0
- package/dist/ts/src/components.js.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts +18 -0
- package/dist/ts/src/discovery/astro-frontmatter.d.ts.map +1 -0
- package/dist/ts/src/discovery/astro-frontmatter.js +25 -0
- package/dist/ts/src/discovery/astro-frontmatter.js.map +1 -0
- package/dist/ts/src/discovery/discover.d.ts +43 -0
- package/dist/ts/src/discovery/discover.d.ts.map +1 -0
- package/dist/ts/src/discovery/discover.js +87 -0
- package/dist/ts/src/discovery/discover.js.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts +41 -0
- package/dist/ts/src/discovery/extract-props-ts.d.ts.map +1 -0
- package/dist/ts/src/discovery/extract-props-ts.js +232 -0
- package/dist/ts/src/discovery/extract-props-ts.js.map +1 -0
- package/dist/ts/src/discovery/merge-registry.d.ts +58 -0
- package/dist/ts/src/discovery/merge-registry.d.ts.map +1 -0
- package/dist/ts/src/discovery/merge-registry.js +333 -0
- package/dist/ts/src/discovery/merge-registry.js.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts +27 -0
- package/dist/ts/src/discovery/registry-endpoint.d.ts.map +1 -0
- package/dist/ts/src/discovery/registry-endpoint.js +76 -0
- package/dist/ts/src/discovery/registry-endpoint.js.map +1 -0
- package/dist/ts/src/discovery/scan-components.d.ts +94 -0
- package/dist/ts/src/discovery/scan-components.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-components.js +397 -0
- package/dist/ts/src/discovery/scan-components.js.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts +63 -0
- package/dist/ts/src/discovery/scan-mdx.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-mdx.js +113 -0
- package/dist/ts/src/discovery/scan-mdx.js.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts +71 -0
- package/dist/ts/src/discovery/scan-overrides.d.ts.map +1 -0
- package/dist/ts/src/discovery/scan-overrides.js +34 -0
- package/dist/ts/src/discovery/scan-overrides.js.map +1 -0
- package/dist/ts/src/editor-descriptors.d.ts +31 -0
- package/dist/ts/src/editor-descriptors.d.ts.map +1 -0
- package/dist/ts/src/editor-descriptors.js +84 -0
- package/dist/ts/src/editor-descriptors.js.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts +32 -0
- package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -0
- package/dist/ts/src/handlers/collection-content-api.js +166 -0
- package/dist/ts/src/handlers/collection-content-api.js.map +1 -0
- package/dist/ts/src/handlers/page-render-core.d.ts +137 -0
- package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -0
- package/dist/ts/src/handlers/page-render-core.js +315 -0
- package/dist/ts/src/handlers/page-render-core.js.map +1 -0
- package/dist/ts/src/hydration.d.ts +4 -0
- package/dist/ts/src/hydration.d.ts.map +1 -0
- package/dist/ts/src/hydration.js +5 -0
- package/dist/ts/src/hydration.js.map +1 -0
- package/dist/ts/src/index.d.ts +21 -0
- package/dist/ts/src/index.d.ts.map +1 -0
- package/dist/ts/src/index.js +45 -0
- package/dist/ts/src/index.js.map +1 -0
- package/dist/ts/src/internal/declared-collections.d.ts +30 -0
- package/dist/ts/src/internal/declared-collections.d.ts.map +1 -0
- package/dist/ts/src/internal/declared-collections.js +84 -0
- package/dist/ts/src/internal/declared-collections.js.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts +44 -0
- package/dist/ts/src/internal/page-collection-schema.d.ts.map +1 -0
- package/dist/ts/src/internal/page-collection-schema.js +152 -0
- package/dist/ts/src/internal/page-collection-schema.js.map +1 -0
- package/dist/ts/src/lib/content-config-guard.d.ts +11 -0
- package/dist/ts/src/lib/content-config-guard.d.ts.map +1 -0
- package/dist/ts/src/lib/content-config-guard.js +41 -0
- package/dist/ts/src/lib/content-config-guard.js.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts +47 -0
- package/dist/ts/src/lib/hydration-scanner.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-scanner.js +136 -0
- package/dist/ts/src/lib/hydration-scanner.js.map +1 -0
- package/dist/{lib/hydration-script.d.mts → ts/src/lib/hydration-script.d.ts} +7 -10
- package/dist/ts/src/lib/hydration-script.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-script.js +89 -0
- package/dist/ts/src/lib/hydration-script.js.map +1 -0
- package/dist/ts/src/lib/hydration-utils.d.ts +51 -0
- package/dist/ts/src/lib/hydration-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/hydration-utils.js +84 -0
- package/dist/ts/src/lib/hydration-utils.js.map +1 -0
- package/dist/ts/src/lib/resolve-locale.d.ts +15 -0
- package/dist/ts/src/lib/resolve-locale.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-locale.js +16 -0
- package/dist/ts/src/lib/resolve-locale.js.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts +8 -0
- package/dist/ts/src/lib/resolve-site-name.d.ts.map +1 -0
- package/dist/ts/src/lib/resolve-site-name.js +12 -0
- package/dist/ts/src/lib/resolve-site-name.js.map +1 -0
- package/dist/ts/src/lib/route-utils.d.ts +61 -0
- package/dist/ts/src/lib/route-utils.d.ts.map +1 -0
- package/dist/ts/src/lib/route-utils.js +96 -0
- package/dist/ts/src/lib/route-utils.js.map +1 -0
- package/dist/ts/src/lib/routing-config.d.ts +38 -0
- package/dist/ts/src/lib/routing-config.d.ts.map +1 -0
- package/dist/ts/src/lib/routing-config.js +106 -0
- package/dist/ts/src/lib/routing-config.js.map +1 -0
- package/dist/ts/src/lib/serialize-props.d.ts +6 -0
- package/dist/ts/src/lib/serialize-props.d.ts.map +1 -0
- package/dist/ts/src/lib/serialize-props.js +8 -0
- package/dist/ts/src/lib/serialize-props.js.map +1 -0
- package/dist/ts/src/lib/unknown-components.d.ts +21 -0
- package/dist/ts/src/lib/unknown-components.d.ts.map +1 -0
- package/dist/ts/src/lib/unknown-components.js +49 -0
- package/dist/ts/src/lib/unknown-components.js.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts +33 -0
- package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -0
- package/dist/ts/src/lib/virtual-module-generators.js +51 -0
- package/dist/ts/src/lib/virtual-module-generators.js.map +1 -0
- package/dist/{withHydration-HIvO9ysY.d.mts → ts/src/lib/withHydration.d.ts} +7 -11
- package/dist/ts/src/lib/withHydration.d.ts.map +1 -0
- package/dist/ts/src/lib/withHydration.js +50 -0
- package/dist/ts/src/lib/withHydration.js.map +1 -0
- package/dist/ts/src/loader.d.ts +27 -0
- package/dist/ts/src/loader.d.ts.map +1 -0
- package/dist/ts/src/loader.js +118 -0
- package/dist/ts/src/loader.js.map +1 -0
- package/dist/ts/src/locales-helpers.d.ts +61 -0
- package/dist/ts/src/locales-helpers.d.ts.map +1 -0
- package/dist/ts/src/locales-helpers.js +50 -0
- package/dist/ts/src/locales-helpers.js.map +1 -0
- package/dist/ts/src/mime-types.d.ts +3 -0
- package/dist/ts/src/mime-types.d.ts.map +1 -0
- package/dist/ts/src/mime-types.js +20 -0
- package/dist/ts/src/mime-types.js.map +1 -0
- package/dist/ts/src/page-feed.d.ts +13 -0
- package/dist/ts/src/page-feed.d.ts.map +1 -0
- package/dist/ts/src/page-feed.js +20 -0
- package/dist/ts/src/page-feed.js.map +1 -0
- package/dist/ts/src/page-schemas.d.ts +6 -0
- package/dist/ts/src/page-schemas.d.ts.map +1 -0
- package/dist/ts/src/page-schemas.js +6 -0
- package/dist/ts/src/page-schemas.js.map +1 -0
- package/dist/ts/src/path-validation.d.ts +8 -0
- package/dist/ts/src/path-validation.d.ts.map +1 -0
- package/dist/ts/src/path-validation.js +13 -0
- package/dist/ts/src/path-validation.js.map +1 -0
- package/dist/ts/src/plugin-spa.d.ts +182 -0
- package/dist/ts/src/plugin-spa.d.ts.map +1 -0
- package/dist/ts/src/plugin-spa.js +1165 -0
- package/dist/ts/src/plugin-spa.js.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts +30 -0
- package/dist/ts/src/puck-manifest/components-endpoint.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js +54 -0
- package/dist/ts/src/puck-manifest/components-endpoint.js.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts +91 -0
- package/dist/ts/src/puck-manifest/field-projection.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/field-projection.js +422 -0
- package/dist/ts/src/puck-manifest/field-projection.js.map +1 -0
- package/dist/ts/src/puck-manifest/index.d.ts +4 -0
- package/dist/ts/src/puck-manifest/index.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/index.js +3 -0
- package/dist/ts/src/puck-manifest/index.js.map +1 -0
- package/dist/ts/src/puck-manifest/literal.d.ts +163 -0
- package/dist/ts/src/puck-manifest/literal.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/literal.js +354 -0
- package/dist/ts/src/puck-manifest/literal.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts +42 -0
- package/dist/ts/src/puck-manifest/read-config.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-config.js +517 -0
- package/dist/ts/src/puck-manifest/read-config.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts +7 -0
- package/dist/ts/src/puck-manifest/read-field.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-field.js +11 -0
- package/dist/ts/src/puck-manifest/read-field.js.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts +147 -0
- package/dist/ts/src/puck-manifest/read-wrapper.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js +889 -0
- package/dist/ts/src/puck-manifest/read-wrapper.js.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts +50 -0
- package/dist/ts/src/puck-manifest/reading-budget.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/reading-budget.js +113 -0
- package/dist/ts/src/puck-manifest/reading-budget.js.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js +4 -0
- package/dist/ts/src/puck-manifest/resolve-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts +96 -0
- package/dist/ts/src/puck-manifest/source-reference.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/source-reference.js +424 -0
- package/dist/ts/src/puck-manifest/source-reference.js.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts +29 -0
- package/dist/ts/src/puck-manifest/syntax.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/syntax.js +79 -0
- package/dist/ts/src/puck-manifest/syntax.js.map +1 -0
- package/dist/ts/src/puck-manifest/types.d.ts +145 -0
- package/dist/ts/src/puck-manifest/types.d.ts.map +1 -0
- package/dist/ts/src/puck-manifest/types.js +2 -0
- package/dist/ts/src/puck-manifest/types.js.map +1 -0
- package/dist/ts/src/safe-json-stringify.d.ts +13 -0
- package/dist/ts/src/safe-json-stringify.d.ts.map +1 -0
- package/dist/ts/src/safe-json-stringify.js +7 -0
- package/dist/ts/src/safe-json-stringify.js.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts +19 -0
- package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -0
- package/dist/ts/src/sandbox-frame-handler.js +27 -0
- package/dist/ts/src/sandbox-frame-handler.js.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts +73 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js +224 -0
- package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts +50 -0
- package/dist/ts/src/site-styles/render-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/render-endpoint.js +264 -0
- package/dist/ts/src/site-styles/render-endpoint.js.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts +59 -0
- package/dist/ts/src/site-styles/styles-endpoint.d.ts.map +1 -0
- package/dist/ts/src/site-styles/styles-endpoint.js +156 -0
- package/dist/ts/src/site-styles/styles-endpoint.js.map +1 -0
- package/dist/ts/src/sitemap-options.d.ts +21 -0
- package/dist/ts/src/sitemap-options.d.ts.map +1 -0
- package/dist/ts/src/sitemap-options.js +92 -0
- package/dist/ts/src/sitemap-options.js.map +1 -0
- package/dist/ts/src/tiptap-html-static.d.ts +15 -0
- package/dist/ts/src/tiptap-html-static.d.ts.map +1 -0
- package/dist/ts/src/tiptap-html-static.js +67 -0
- package/dist/ts/src/tiptap-html-static.js.map +1 -0
- package/dist/ts/src/types.d.ts +543 -0
- package/dist/ts/src/types.d.ts.map +1 -0
- package/dist/ts/src/types.js +2 -0
- package/dist/ts/src/types.js.map +1 -0
- package/dist/virtual-modules.d.ts +74 -0
- package/node/content.ts +14 -0
- package/node/index.ts +22 -0
- package/package.json +198 -56
- package/src/asset-ref-base.ts +48 -0
- package/src/checks.ts +10 -0
- package/src/cms-handler.ts +280 -0
- package/src/collections.ts +262 -0
- package/src/components/HydrationWrapper.tsx +41 -0
- package/src/components/RenderWithFragments.tsx +204 -0
- package/src/components/RenderWithHydration.tsx +55 -0
- package/src/components.ts +3 -0
- package/src/discovery/astro-frontmatter.ts +24 -0
- package/src/discovery/discover.ts +108 -0
- package/src/discovery/extract-props-ts.ts +255 -0
- package/src/discovery/merge-registry.ts +411 -0
- package/src/discovery/registry-endpoint.ts +80 -0
- package/src/discovery/scan-components.ts +458 -0
- package/src/discovery/scan-mdx.ts +190 -0
- package/src/discovery/scan-overrides.ts +92 -0
- package/src/editor-descriptors.ts +96 -0
- package/src/env.d.ts +31 -0
- package/src/handlers/collection-content-api.ts +196 -0
- package/src/handlers/page-handler.astro +320 -0
- package/src/handlers/page-render-core.ts +456 -0
- package/src/hydration.ts +7 -0
- package/src/index.ts +111 -0
- package/src/internal/acorn-default.mjs +37 -0
- package/src/internal/declared-collections.ts +98 -0
- package/src/internal/page-collection-schema.ts +210 -0
- package/src/lib/content-config-guard.ts +48 -0
- package/src/lib/hydration-scanner.ts +176 -0
- package/src/lib/hydration-script.ts +126 -0
- package/src/lib/hydration-utils.ts +120 -0
- package/src/lib/resolve-locale.ts +22 -0
- package/src/lib/resolve-site-name.ts +10 -0
- package/src/lib/route-utils.ts +106 -0
- package/src/lib/routing-config.ts +126 -0
- package/src/lib/serialize-props.ts +7 -0
- package/src/lib/unknown-components.ts +64 -0
- package/src/lib/virtual-module-generators.ts +58 -0
- package/src/lib/withHydration.ts +71 -0
- package/src/loader.ts +145 -0
- package/src/locales-helpers.ts +68 -0
- package/src/mime-types.ts +19 -0
- package/src/page-feed.ts +26 -0
- package/src/page-schemas.ts +19 -0
- package/src/path-validation.ts +13 -0
- package/src/plugin-spa.ts +1480 -0
- package/src/puck-manifest/components-endpoint.ts +55 -0
- package/src/puck-manifest/field-projection.ts +510 -0
- package/src/puck-manifest/index.ts +3 -0
- package/src/puck-manifest/literal.ts +459 -0
- package/src/puck-manifest/read-config.ts +577 -0
- package/src/puck-manifest/read-field.ts +19 -0
- package/src/puck-manifest/read-wrapper.ts +1056 -0
- package/src/puck-manifest/reading-budget.ts +127 -0
- package/src/puck-manifest/resolve-reference.ts +9 -0
- package/src/puck-manifest/source-reference.ts +484 -0
- package/src/puck-manifest/syntax.ts +104 -0
- package/src/puck-manifest/types.ts +139 -0
- package/src/safe-json-stringify.ts +17 -0
- package/src/sandbox-frame-handler.ts +31 -0
- package/src/site-styles/content-wrapper-endpoint.ts +327 -0
- package/src/site-styles/render-endpoint.ts +331 -0
- package/src/site-styles/styles-endpoint.ts +184 -0
- package/src/sitemap-options.ts +115 -0
- package/src/tiptap-html-static.ts +84 -0
- package/{dist/types-CVQNmPxF.d.mts → src/types.ts} +232 -79
- package/src/virtual-modules.d.ts +74 -0
- package/dist/collections.d.mts +0 -36
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -65
- package/dist/collections.mjs.map +0 -1
- package/dist/components.d.mts +0 -46
- package/dist/components.d.mts.map +0 -1
- package/dist/components.mjs +0 -226
- package/dist/components.mjs.map +0 -1
- package/dist/hydration-scanner-B0NjYkZ_.mjs +0 -109
- package/dist/hydration-scanner-B0NjYkZ_.mjs.map +0 -1
- package/dist/hydration.d.mts +0 -4
- package/dist/hydration.mjs +0 -3
- package/dist/index.d.mts +0 -139
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -66
- package/dist/index.mjs.map +0 -1
- package/dist/internal/cms-handler.d.mts +0 -26
- package/dist/internal/cms-handler.d.mts.map +0 -1
- package/dist/internal/cms-handler.mjs +0 -267
- package/dist/internal/cms-handler.mjs.map +0 -1
- package/dist/lib/hydration-script.d.mts.map +0 -1
- package/dist/lib/hydration-script.mjs +0 -85
- package/dist/lib/hydration-script.mjs.map +0 -1
- package/dist/loader-By-AQWHc.mjs +0 -68
- package/dist/loader-By-AQWHc.mjs.map +0 -1
- package/dist/node/content.d.mts +0 -19
- package/dist/node/content.d.mts.map +0 -1
- package/dist/node/content.mjs +0 -4
- package/dist/node/index.d.mts +0 -52
- package/dist/node/index.d.mts.map +0 -1
- package/dist/node/index.mjs +0 -753
- package/dist/node/index.mjs.map +0 -1
- package/dist/serialize-props-Dhv_MnkY.mjs +0 -73
- package/dist/serialize-props-Dhv_MnkY.mjs.map +0 -1
- package/dist/types-CVQNmPxF.d.mts.map +0 -1
- package/dist/withHydration-EzyzBQ-Y.mjs +0 -49
- package/dist/withHydration-EzyzBQ-Y.mjs.map +0 -1
- package/dist/withHydration-HIvO9ysY.d.mts.map +0 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import spaConfig from 'virtual:conloca-config';
|
|
5
|
+
import {
|
|
6
|
+
type CFAccessResult,
|
|
7
|
+
createContentAPIRouter,
|
|
8
|
+
FileSystemContentAPI,
|
|
9
|
+
validateCFAccessRequest,
|
|
10
|
+
} from '@conloca/content-api/node';
|
|
11
|
+
import { handleMDXCompileRequest } from '@conloca/mdx/node';
|
|
12
|
+
import type { APIRoute } from 'astro';
|
|
13
|
+
import { SPA_MIME_TYPES } from './mime-types.js';
|
|
14
|
+
import { isPathWithinBase } from './path-validation.js';
|
|
15
|
+
import { safeJsonStringify } from './safe-json-stringify.js';
|
|
16
|
+
|
|
17
|
+
export { SPA_MIME_TYPES } from './mime-types.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Read the top-level locales options from build-time env vars.
|
|
21
|
+
* `CONLOCA_LOCALES` is inlined as a JS array (or `null`) by Vite's
|
|
22
|
+
* `define`; `CONLOCA_DEFAULT_LOCALE` is a string (or `''`). When neither
|
|
23
|
+
* is set, returns an empty object so the spread is a no-op and the
|
|
24
|
+
* content-api falls back to sites.json (the existing behavior).
|
|
25
|
+
*/
|
|
26
|
+
function localesFromEnv(): { availableLocales?: string[]; defaultLocale?: string } {
|
|
27
|
+
const list = import.meta.env.CONLOCA_LOCALES as readonly string[] | null | undefined;
|
|
28
|
+
const defaultLocale = import.meta.env.CONLOCA_DEFAULT_LOCALE as string | undefined;
|
|
29
|
+
return {
|
|
30
|
+
...(Array.isArray(list) && list.length > 0 ? { availableLocales: list as string[] } : {}),
|
|
31
|
+
...(typeof defaultLocale === 'string' && defaultLocale ? { defaultLocale } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// mdxPages config (root / site / defaultLocale) is no longer passed as
|
|
36
|
+
// env vars — the content-api reads sites.json directly from disk under
|
|
37
|
+
// `contentRoot`, so handlers below don't need to spread mdx-options at
|
|
38
|
+
// all. See `readSitesConfig()` in @conloca/content-api/node.
|
|
39
|
+
|
|
40
|
+
// Get the path to the cms-spa package by resolving its package.json
|
|
41
|
+
const require = createRequire(import.meta.url);
|
|
42
|
+
const cmsSpaPath = dirname(require.resolve('@conloca/cms-spa/package.json'));
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Unified CMS handler - single entry point for all CMS routes.
|
|
46
|
+
*
|
|
47
|
+
* This handler:
|
|
48
|
+
* 1. Validates CF Access authentication ONCE at the top
|
|
49
|
+
* 2. Routes to appropriate sub-handler based on path:
|
|
50
|
+
* - /api/* -> handleContentApi()
|
|
51
|
+
* - /* -> handleSpa()
|
|
52
|
+
*
|
|
53
|
+
* Benefits:
|
|
54
|
+
* - Single authentication check prevents security gaps
|
|
55
|
+
* - New routes automatically inherit auth protection
|
|
56
|
+
* - Easier to audit security
|
|
57
|
+
*/
|
|
58
|
+
export const ALL: APIRoute = async ({ params, request }) => {
|
|
59
|
+
// Step 1: Validate CF Access ONCE
|
|
60
|
+
const cfResult = await validateCFAccessRequest(request);
|
|
61
|
+
if (!cfResult.valid && cfResult.required) {
|
|
62
|
+
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
|
|
63
|
+
status: 401,
|
|
64
|
+
headers: { 'Content-Type': 'application/json' },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Step 2: Route based on path
|
|
69
|
+
const pathArray = params.path;
|
|
70
|
+
const path = Array.isArray(pathArray) ? pathArray.join('/') : pathArray || '';
|
|
71
|
+
|
|
72
|
+
// Route to appropriate handler
|
|
73
|
+
if (path.startsWith('api/')) {
|
|
74
|
+
return handleContentApi(request, cfResult);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return handleSpa(params);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// SPA Handler (from spa-handler.ts)
|
|
82
|
+
// ============================================================================
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Generate HTML for dev mode that loads cms-spa source through Vite.
|
|
86
|
+
* This ensures React is resolved from Vite's pre-bundled deps, not from the cms-spa bundle.
|
|
87
|
+
*/
|
|
88
|
+
function generateDevHtml(config: typeof spaConfig): string {
|
|
89
|
+
return `<!DOCTYPE html>
|
|
90
|
+
<html lang="en">
|
|
91
|
+
<head>
|
|
92
|
+
<meta charset="UTF-8" />
|
|
93
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
94
|
+
<title>Conloca CMS</title>
|
|
95
|
+
<link rel="stylesheet" href="${config.basename}/main.css" />
|
|
96
|
+
<script type="module" src="${config.basename}/site-styles.js"></script>
|
|
97
|
+
<script type="module" src="${config.basename}/editor-styles.js"></script>
|
|
98
|
+
<script>
|
|
99
|
+
// Configure UI with plugin options
|
|
100
|
+
window.__UI_CONFIG__ = ${safeJsonStringify(config)};
|
|
101
|
+
</script>
|
|
102
|
+
<script type="module" src="${config.basename}/schemas-entry.js"></script>
|
|
103
|
+
<script type="module" src="${config.basename}/puck-entry.js"></script>
|
|
104
|
+
<script type="module" src="${config.basename}/content-listener.js"></script>
|
|
105
|
+
</head>
|
|
106
|
+
<body>
|
|
107
|
+
<div id="root"></div>
|
|
108
|
+
<script type="module" src="${config.basename}/cms-spa-entry.js"></script>
|
|
109
|
+
</body>
|
|
110
|
+
</html>`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Load the HTML at runtime (production only)
|
|
115
|
+
*/
|
|
116
|
+
async function loadIndexHtml(): Promise<string> {
|
|
117
|
+
const spaDir = join(cmsSpaPath, 'dist/spa');
|
|
118
|
+
const { readdir } = await import('node:fs/promises');
|
|
119
|
+
const files = await readdir(spaDir);
|
|
120
|
+
const htmlFile = files.find((f) => f.startsWith('index.') && f.endsWith('.html'));
|
|
121
|
+
|
|
122
|
+
if (!htmlFile) {
|
|
123
|
+
throw new Error('No index.html found in @conloca/cms-spa dist/spa');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const htmlPath = join(spaDir, htmlFile);
|
|
127
|
+
const html = await readFile(htmlPath, 'utf-8');
|
|
128
|
+
|
|
129
|
+
return html;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Handle SPA requests - serve CMS admin interface
|
|
134
|
+
*/
|
|
135
|
+
async function handleSpa(params: { path?: string | string[] }): Promise<Response> {
|
|
136
|
+
// The path parameter is an array for [...path] routes
|
|
137
|
+
const pathArray = params.path;
|
|
138
|
+
const path = Array.isArray(pathArray) ? pathArray.join('/') : pathArray || '';
|
|
139
|
+
|
|
140
|
+
// For the root path or any path without an extension, serve the HTML
|
|
141
|
+
if (!path?.includes('.')) {
|
|
142
|
+
try {
|
|
143
|
+
let html: string;
|
|
144
|
+
|
|
145
|
+
// In dev mode, generate HTML that loads source through Vite
|
|
146
|
+
// In production, load the pre-built HTML from cms-spa dist
|
|
147
|
+
if (import.meta.env.DEV) {
|
|
148
|
+
html = generateDevHtml(spaConfig);
|
|
149
|
+
} else {
|
|
150
|
+
html = await loadIndexHtml();
|
|
151
|
+
// Inject CMS configuration and load virtual modules
|
|
152
|
+
const configScript = `
|
|
153
|
+
<script>
|
|
154
|
+
// Configure UI with plugin options
|
|
155
|
+
window.__UI_CONFIG__ = ${safeJsonStringify(spaConfig)};
|
|
156
|
+
</script>
|
|
157
|
+
<script type="module" src="${spaConfig.basename}/site-styles.js"></script>
|
|
158
|
+
<script type="module" src="${spaConfig.basename}/editor-styles.js"></script>
|
|
159
|
+
<script type="module" src="${spaConfig.basename}/schemas-entry.js"></script>
|
|
160
|
+
<script type="module" src="${spaConfig.basename}/puck-entry.js"></script>
|
|
161
|
+
<script type="module" src="${spaConfig.basename}/content-listener.js"></script>
|
|
162
|
+
`;
|
|
163
|
+
// Inject the script at the top to ensure config is available first
|
|
164
|
+
html = html.replace('<head>', `<head>${configScript}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return new Response(html, {
|
|
168
|
+
headers: {
|
|
169
|
+
'Content-Type': 'text/html',
|
|
170
|
+
'Cache-Control': 'no-store, must-revalidate',
|
|
171
|
+
'X-HMR': 'spa-page',
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error('Error loading CMS HTML:', error);
|
|
176
|
+
return new Response('CMS build not found. Run nx build @conloca/astro-cms', {
|
|
177
|
+
status: 500,
|
|
178
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// For asset requests, serve them from the cms-spa dist/spa directory
|
|
184
|
+
try {
|
|
185
|
+
const spaBase = join(cmsSpaPath, 'dist/spa');
|
|
186
|
+
const assetPath = join(spaBase, path);
|
|
187
|
+
|
|
188
|
+
if (!isPathWithinBase(spaBase, assetPath)) {
|
|
189
|
+
console.warn('[security] Path traversal attempt blocked:', path);
|
|
190
|
+
return new Response('Forbidden', { status: 403 });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const content = await readFile(assetPath);
|
|
194
|
+
|
|
195
|
+
// Determine content type from extension map with octet-stream fallback
|
|
196
|
+
const ext = path.substring(path.lastIndexOf('.'));
|
|
197
|
+
const contentType = SPA_MIME_TYPES[ext] ?? 'application/octet-stream';
|
|
198
|
+
|
|
199
|
+
return new Response(content as BodyInit, {
|
|
200
|
+
headers: {
|
|
201
|
+
'Content-Type': contentType,
|
|
202
|
+
'Cache-Control': import.meta.env.DEV ? 'no-store, must-revalidate' : 'public, max-age=31536000',
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
} catch {
|
|
206
|
+
return new Response('Not found', { status: 404 });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ============================================================================
|
|
211
|
+
// Content API Handler (from content-api-handler.ts)
|
|
212
|
+
// ============================================================================
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Handle Content API requests - delegates to Hono router
|
|
216
|
+
*/
|
|
217
|
+
async function handleContentApi(request: Request, cfResult: CFAccessResult): Promise<Response> {
|
|
218
|
+
const contentRoot = import.meta.env.CONLOCA_CONTENT_ROOT || './content';
|
|
219
|
+
const canvasDir = import.meta.env.CONLOCA_CANVAS_DIR || './canvas';
|
|
220
|
+
|
|
221
|
+
// FileSystemContentAPI.create() handles caching internally.
|
|
222
|
+
// mdxPages is read from sites.json by the content-api itself.
|
|
223
|
+
const contentApi = await FileSystemContentAPI.create({
|
|
224
|
+
contentRoot,
|
|
225
|
+
canvasDir,
|
|
226
|
+
...localesFromEnv(),
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Create the Hono router with assets and content root for git operations
|
|
230
|
+
const assetsPath = import.meta.env.CONLOCA_ASSETS_PATH || '';
|
|
231
|
+
const app = createContentAPIRouter(contentApi, {
|
|
232
|
+
...(assetsPath && { assetsPath }),
|
|
233
|
+
contentRoot,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// Mounted here rather than in @conloca/content-api because compiling MDX is a
|
|
237
|
+
// renderer concern; content-api is purely storage.
|
|
238
|
+
app.post('/mdx/compile', (c) => handleMDXCompileRequest(c.req.raw));
|
|
239
|
+
|
|
240
|
+
// Extract the path after the API base
|
|
241
|
+
const url = new URL(request.url);
|
|
242
|
+
// Find where /api/ appears in the pathname
|
|
243
|
+
const apiIndex = url.pathname.indexOf('/api/');
|
|
244
|
+
if (apiIndex === -1) {
|
|
245
|
+
return new Response('Invalid API path', { status: 400 });
|
|
246
|
+
}
|
|
247
|
+
const basePath = url.pathname.substring(0, apiIndex + 4); // Include '/api'
|
|
248
|
+
const path = url.pathname.substring(basePath.length) || '/';
|
|
249
|
+
|
|
250
|
+
// Pass user to Hono via headers for downstream use (needed for git commit attribution)
|
|
251
|
+
const headers = new Headers(request.headers);
|
|
252
|
+
if (cfResult.user) {
|
|
253
|
+
if (cfResult.user.email) {
|
|
254
|
+
headers.set('X-CF-User-Email', cfResult.user.email);
|
|
255
|
+
}
|
|
256
|
+
if (cfResult.user.sub) {
|
|
257
|
+
headers.set('X-CF-User-Sub', cfResult.user.sub);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Create a new request with the correct path for Hono
|
|
262
|
+
// Note: duplex option is required for Node.js fetch when sending a body
|
|
263
|
+
// but not in the TypeScript RequestInit type
|
|
264
|
+
const honoRequest = new Request(new URL(path + url.search, 'http://localhost').href, {
|
|
265
|
+
method: request.method,
|
|
266
|
+
headers,
|
|
267
|
+
body: request.body,
|
|
268
|
+
...(request.body && { duplex: 'half' }),
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// Let Hono handle the request
|
|
272
|
+
const response = await app.fetch(honoRequest);
|
|
273
|
+
|
|
274
|
+
// Return the Hono response
|
|
275
|
+
return new Response(response.body, {
|
|
276
|
+
status: response.status,
|
|
277
|
+
statusText: response.statusText,
|
|
278
|
+
headers: response.headers,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { defineCollection } from 'astro:content';
|
|
2
|
+
import type { DataSchemas, PageSchemas } from '@conloca/cms-spa/page-schema-define';
|
|
3
|
+
import { createContentAPI } from '@conloca/content-api/reader';
|
|
4
|
+
import { dataMetaSchema, fragmentMetaSchema, pageMetaSchema } from '@conloca/content-api/schemas';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { ALL_FRAGMENTS_COLLECTION } from './handlers/page-render-core.js';
|
|
7
|
+
import { declareConlocaCollection, withDeclarationCheck } from './internal/declared-collections.js';
|
|
8
|
+
import { buildPageCollectionSchema, hostFieldsFromPageSchemas } from './internal/page-collection-schema.js';
|
|
9
|
+
import { conlocaLoader } from './loader.js';
|
|
10
|
+
|
|
11
|
+
export { ALL_FRAGMENTS_COLLECTION };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options for createConlocaCollections().
|
|
15
|
+
*/
|
|
16
|
+
export interface CreateConlocaCollectionsOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Path to content root directory. Defaults to the contentRoot configured on
|
|
19
|
+
* conlocaCMS() in astro.config, falling back to './content'.
|
|
20
|
+
*/
|
|
21
|
+
contentRoot?: string;
|
|
22
|
+
/** Site name for multi-site setups. @default 'default' */
|
|
23
|
+
site?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The same `pageSchemas` object the editor loads. Host meta fields are
|
|
26
|
+
* validated on every page collection at build time (made optional, because
|
|
27
|
+
* the editor scopes a descriptor to a prefix while Astro validates the
|
|
28
|
+
* whole pile). Pass the object itself — not a hand-copied field list — so
|
|
29
|
+
* the form and the build cannot drift. Listing types come from augmenting
|
|
30
|
+
* `HostPageMeta`, not from Astro `entry.data`.
|
|
31
|
+
* The {@link pageSchemasOf} read-back is a {@link conlocaPages} contract
|
|
32
|
+
* and does not cover this deprecated wrapper.
|
|
33
|
+
*/
|
|
34
|
+
pageSchemas?: PageSchemas;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Return type of createConlocaCollections().
|
|
39
|
+
*/
|
|
40
|
+
export interface ConlocaCollectionsResult {
|
|
41
|
+
/** Astro Content Collections definitions - export this as `collections` */
|
|
42
|
+
collections: Record<string, ReturnType<typeof defineCollection>>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Declare collections explicitly with {@link conlocaPages},
|
|
47
|
+
* {@link conlocaData} and {@link conlocaFragments} — they keep the entry
|
|
48
|
+
* types Astro's generated `getCollection` needs, and undeclared content
|
|
49
|
+
* fails the build instead of silently not building. This wrapper still
|
|
50
|
+
* works but returns untyped entries.
|
|
51
|
+
*
|
|
52
|
+
* Creates Astro Content Collections by discovering from indexed content.
|
|
53
|
+
* Uses content-api to find collections that have content.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // src/content.config.ts
|
|
58
|
+
* import { createConlocaCollections } from '@conloca/astro-cms/node/content';
|
|
59
|
+
* import { pageSchemas } from './page-schemas';
|
|
60
|
+
*
|
|
61
|
+
* export const { collections } = await createConlocaCollections({ pageSchemas });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export async function createConlocaCollections(
|
|
65
|
+
options: CreateConlocaCollectionsOptions = {},
|
|
66
|
+
): Promise<ConlocaCollectionsResult> {
|
|
67
|
+
// Default comes from the conlocaCMS integration, which publishes its raw
|
|
68
|
+
// contentRoot option to process.env before the content config loads — one
|
|
69
|
+
// contentRoot in astro.config covers both. (A missing directory is the
|
|
70
|
+
// integration's job to report; it warns in dev and fails the build.)
|
|
71
|
+
const { contentRoot = process.env.CONLOCA_CONTENT_ROOT ?? './content', site = 'default', pageSchemas } = options;
|
|
72
|
+
|
|
73
|
+
const api = await createContentAPI({ contentRoot });
|
|
74
|
+
const collections: Record<string, ReturnType<typeof defineCollection>> = {};
|
|
75
|
+
|
|
76
|
+
collections[ALL_FRAGMENTS_COLLECTION] = defineCollection({
|
|
77
|
+
loader: conlocaLoader({ contentRoot, site, kind: 'fragment' }),
|
|
78
|
+
schema: fragmentMetaSchema.loose(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
for (const name of api.fragments.collections) {
|
|
82
|
+
collections[name] = defineCollection({
|
|
83
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'fragment' }),
|
|
84
|
+
schema: fragmentMetaSchema.loose(),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const name of api.data.collections) {
|
|
89
|
+
collections[name] = defineCollection({
|
|
90
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }),
|
|
91
|
+
schema: dataMetaSchema.loose(),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const hostFields = pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : undefined;
|
|
96
|
+
const pageSchema =
|
|
97
|
+
hostFields && Object.keys(hostFields.shape).length > 0
|
|
98
|
+
? buildPageCollectionSchema(hostFields)
|
|
99
|
+
: pageMetaSchema.loose();
|
|
100
|
+
|
|
101
|
+
const siteCollections = api.getSite(site)?.collections ?? new Set<string>();
|
|
102
|
+
for (const name of siteCollections) {
|
|
103
|
+
collections[name] = defineCollection({
|
|
104
|
+
loader: conlocaLoader({ collection: name, contentRoot, site, kind: 'page' }),
|
|
105
|
+
schema: pageSchema,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { collections };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const defaultContentRoot = () => process.env.CONLOCA_CONTENT_ROOT ?? './content';
|
|
113
|
+
|
|
114
|
+
/** Options for conlocaPages(). */
|
|
115
|
+
export interface ConlocaPagesOptions {
|
|
116
|
+
/**
|
|
117
|
+
* The same `pageSchemas` object the editor loads. Host meta fields are
|
|
118
|
+
* validated on every page at build time and typed via the HostPageMeta
|
|
119
|
+
* augmentation. Pass the object itself — not a hand-copied field list;
|
|
120
|
+
* {@link pageSchemasOf} reads it back off the returned collection so a
|
|
121
|
+
* site test can assert exactly that.
|
|
122
|
+
*/
|
|
123
|
+
pageSchemas?: PageSchemas;
|
|
124
|
+
/** @default 'pages' — must equal the content.config key this is assigned to. */
|
|
125
|
+
collection?: string;
|
|
126
|
+
/** @default 'default' */
|
|
127
|
+
site?: string;
|
|
128
|
+
/** @default conlocaCMS()'s contentRoot (via CONLOCA_CONTENT_ROOT), falling back to './content'. */
|
|
129
|
+
contentRoot?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// What each conlocaPages call was handed, keyed weakly by the collection it
|
|
133
|
+
// returned: fresh objects per config evaluation, so a stale evaluation can
|
|
134
|
+
// never answer for a new one, and nothing is kept alive for it.
|
|
135
|
+
const pageSchemasByCollection = new WeakMap<object, PageSchemas>();
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The exact pageSchemas object a conlocaPages collection was declared with,
|
|
139
|
+
* or undefined for anything else. Lets a site test assert the identity the
|
|
140
|
+
* pageSchemas option demands — against the real factory, with no module mock.
|
|
141
|
+
*/
|
|
142
|
+
export function pageSchemasOf(collection: object): PageSchemas | undefined {
|
|
143
|
+
return pageSchemasByCollection.get(collection);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* One typed Astro collection for Conloca pages — the explicit,
|
|
148
|
+
* Starlight-shaped declaration:
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
* export const collections = { pages: conlocaPages({ pageSchemas }) };
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* Entry data is typed as {@link ConlocaPageEntry}; `getCollection('pages')`
|
|
155
|
+
* carries pathname/title/dates and the host's declared meta fields.
|
|
156
|
+
*/
|
|
157
|
+
export function conlocaPages(options: ConlocaPagesOptions = {}) {
|
|
158
|
+
const { contentRoot = defaultContentRoot(), site = 'default', collection = 'pages', pageSchemas } = options;
|
|
159
|
+
declareConlocaCollection('page', collection);
|
|
160
|
+
const defined = defineCollection({
|
|
161
|
+
loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'page' }), {
|
|
162
|
+
contentRoot,
|
|
163
|
+
site,
|
|
164
|
+
}),
|
|
165
|
+
schema: buildPageCollectionSchema(pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : z.object({})),
|
|
166
|
+
});
|
|
167
|
+
if (pageSchemas) pageSchemasByCollection.set(defined, pageSchemas);
|
|
168
|
+
return defined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Options for conlocaData(). */
|
|
172
|
+
export interface ConlocaDataOptions<DS extends DataSchemas> {
|
|
173
|
+
/**
|
|
174
|
+
* The same `dataSchemas` object the editor renders entry forms from. Its
|
|
175
|
+
* keys ARE the data collections — nothing is named twice. Each entry's
|
|
176
|
+
* payload is validated against its schema at build time.
|
|
177
|
+
*/
|
|
178
|
+
dataSchemas: DS;
|
|
179
|
+
/** @default 'default' */
|
|
180
|
+
site?: string;
|
|
181
|
+
/** @default conlocaCMS()'s contentRoot (via CONLOCA_CONTENT_ROOT), falling back to './content'. */
|
|
182
|
+
contentRoot?: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Deliberate asymmetry with pages: a data schema is validated AS GIVEN —
|
|
187
|
+
* requiredness preserved, no rewrite guard — because the site owns it whole
|
|
188
|
+
* for exactly one collection, unlike host page fields folded into the shared
|
|
189
|
+
* pages schema. The flip side, accepted for now: a .transform or .default in
|
|
190
|
+
* a dataSchema runs at build time but not in the editor form, so the two can
|
|
191
|
+
* diverge.
|
|
192
|
+
*/
|
|
193
|
+
function conlocaDataCollection<T extends z.ZodObject<z.ZodRawShape>>(
|
|
194
|
+
name: string,
|
|
195
|
+
payload: T,
|
|
196
|
+
contentRoot: string,
|
|
197
|
+
site: string,
|
|
198
|
+
) {
|
|
199
|
+
return defineCollection({
|
|
200
|
+
loader: withDeclarationCheck(conlocaLoader({ collection: name, contentRoot, site, kind: 'data' }), {
|
|
201
|
+
contentRoot,
|
|
202
|
+
site,
|
|
203
|
+
}),
|
|
204
|
+
// Base meta plus this collection's payload under `data`. `data` stays
|
|
205
|
+
// optional: an entry saved before any payload exists is not an error.
|
|
206
|
+
schema: z.looseObject({ ...dataMetaSchema.shape, data: payload.optional() }),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Typed Astro collections for Conloca data, one per `dataSchemas` key:
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* export const collections = { ...conlocaData({ dataSchemas }) };
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* `getCollection('testimonials')` entries carry `data` typed by that key's
|
|
218
|
+
* schema, and a stored entry that fails its schema fails the build instead
|
|
219
|
+
* of rendering blank.
|
|
220
|
+
*/
|
|
221
|
+
export function conlocaData<DS extends DataSchemas>(options: ConlocaDataOptions<DS>) {
|
|
222
|
+
const { dataSchemas, contentRoot = defaultContentRoot(), site = 'default' } = options;
|
|
223
|
+
const entries = Object.entries(dataSchemas).map(([name, payload]) => {
|
|
224
|
+
declareConlocaCollection('data', name);
|
|
225
|
+
return [name, conlocaDataCollection(name, payload, contentRoot, site)] as const;
|
|
226
|
+
});
|
|
227
|
+
// Object.fromEntries erases per-key types; the assertion restores exactly
|
|
228
|
+
// what the loop built — one collection per dataSchemas key.
|
|
229
|
+
return Object.fromEntries(entries) as { [K in keyof DS]: ReturnType<typeof conlocaDataCollection<DS[K]>> };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The fragments aggregate (always) plus one collection per named fragment
|
|
234
|
+
* folder: `...conlocaFragments('general')`. No arguments declares only the
|
|
235
|
+
* aggregate the render pipeline reads. There are no per-call options:
|
|
236
|
+
* contentRoot comes from conlocaCMS()'s contentRoot (via
|
|
237
|
+
* CONLOCA_CONTENT_ROOT) and the site is always 'default'.
|
|
238
|
+
*/
|
|
239
|
+
export function conlocaFragments<const N extends readonly string[]>(...names: N) {
|
|
240
|
+
const contentRoot = defaultContentRoot();
|
|
241
|
+
const site = 'default';
|
|
242
|
+
const fragmentCollection = (collection?: string) =>
|
|
243
|
+
defineCollection({
|
|
244
|
+
loader: withDeclarationCheck(conlocaLoader({ collection, contentRoot, site, kind: 'fragment' }), {
|
|
245
|
+
contentRoot,
|
|
246
|
+
site,
|
|
247
|
+
}),
|
|
248
|
+
schema: fragmentMetaSchema.loose(),
|
|
249
|
+
});
|
|
250
|
+
const named = Object.fromEntries(
|
|
251
|
+
names.map((name) => {
|
|
252
|
+
declareConlocaCollection('fragment', name);
|
|
253
|
+
return [name, fragmentCollection(name)] as const;
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
// The computed key and Object.fromEntries both erase literal keys; the
|
|
257
|
+
// assertion restores exactly what was built — the aggregate plus one
|
|
258
|
+
// collection per name.
|
|
259
|
+
return { [ALL_FRAGMENTS_COLLECTION]: fragmentCollection(), ...named } as {
|
|
260
|
+
[ALL_FRAGMENTS_COLLECTION]: ReturnType<typeof fragmentCollection>;
|
|
261
|
+
} & { [K in N[number]]: ReturnType<typeof fragmentCollection> };
|
|
262
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { serializeProps } from '../lib/serialize-props.js';
|
|
3
|
+
import type { HydrationStrategy } from '../types.js';
|
|
4
|
+
|
|
5
|
+
interface HydrationWrapperProps {
|
|
6
|
+
componentName: string;
|
|
7
|
+
strategy: HydrationStrategy;
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Wraps hydratable components with data attributes for browser hydration.
|
|
14
|
+
*
|
|
15
|
+
* When strategy is 'none', renders children directly without wrapper overhead.
|
|
16
|
+
* Otherwise, wraps in a div with data-hydrate attributes that the browser
|
|
17
|
+
* hydration script uses to find and hydrate components.
|
|
18
|
+
*/
|
|
19
|
+
export function HydrationWrapper({ componentName, strategy, props, children }: HydrationWrapperProps) {
|
|
20
|
+
// No hydration needed - render children directly without wrapper
|
|
21
|
+
if (strategy === 'none') {
|
|
22
|
+
return <>{children}</>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Strip Puck-internal props that aren't needed for hydration.
|
|
26
|
+
// `puck` contains functions (renderDropZone) that can't survive JSON serialization
|
|
27
|
+
// and would crash on hydration if a component called them.
|
|
28
|
+
const { puck: _puck, ...hydrateProps } = props as Record<string, unknown> & { puck?: unknown };
|
|
29
|
+
|
|
30
|
+
// Wrap with hydration markers for the browser script to find
|
|
31
|
+
return (
|
|
32
|
+
<div
|
|
33
|
+
style={{ display: 'contents' }}
|
|
34
|
+
data-hydrate={componentName}
|
|
35
|
+
data-hydrate-strategy={strategy}
|
|
36
|
+
data-props={serializeProps(hydrateProps)}
|
|
37
|
+
>
|
|
38
|
+
{children}
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|