astro 5.9.4 → 5.10.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/client.d.ts +1 -3
- package/components/Image.astro +5 -6
- package/components/Picture.astro +5 -5
- package/components/ResponsivePicture.astro +1 -0
- package/dist/actions/integration.d.ts +2 -1
- package/dist/actions/integration.js +3 -2
- package/dist/actions/utils.d.ts +1 -1
- package/dist/actions/utils.js +9 -8
- package/dist/assets/internal.d.ts +1 -5
- package/dist/assets/internal.js +21 -23
- package/dist/assets/types.d.ts +4 -4
- package/dist/assets/vite-plugin-assets.js +2 -2
- package/dist/content/config.d.ts +74 -0
- package/dist/content/config.js +78 -0
- package/dist/content/consts.d.ts +1 -0
- package/dist/content/consts.js +2 -0
- package/dist/content/content-layer.js +3 -3
- package/dist/content/loaders/errors.d.ts +20 -0
- package/dist/content/loaders/errors.js +64 -0
- package/dist/content/loaders/types.d.ts +21 -0
- package/dist/content/runtime.d.ts +23 -7
- package/dist/content/runtime.js +218 -28
- package/dist/content/types-generator.js +11 -4
- package/dist/content/utils.d.ts +37 -1
- package/dist/content/utils.js +29 -8
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +20 -6
- package/dist/core/config/schemas/base.d.ts +39 -39
- package/dist/core/config/schemas/base.js +8 -8
- package/dist/core/config/schemas/refined.js +0 -7
- package/dist/core/config/schemas/relative.d.ts +51 -51
- package/dist/core/constants.js +1 -1
- package/dist/core/csp/config.d.ts +3 -3
- package/dist/core/csp/config.js +1 -0
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +16 -0
- package/dist/core/errors/errors-data.js +15 -4
- package/dist/core/errors/errors.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/integrations/hooks.js +5 -2
- package/dist/runtime/client/dev-toolbar/apps/astro.js +4 -6
- package/dist/types/public/config.d.ts +39 -130
- package/dist/types/public/content.d.ts +30 -0
- package/package.json +2 -1
- package/templates/content/module.mjs +14 -0
- package/templates/content/types.d.ts +43 -0
- package/types/content.d.ts +23 -80
package/dist/core/dev/dev.js
CHANGED
|
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
|
|
|
22
22
|
await telemetry.record([]);
|
|
23
23
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
24
24
|
const logger = restart.container.logger;
|
|
25
|
-
const currentVersion = "5.
|
|
25
|
+
const currentVersion = "5.10.0";
|
|
26
26
|
const isPrerelease = currentVersion.includes("-");
|
|
27
27
|
if (!isPrerelease) {
|
|
28
28
|
try {
|
|
@@ -1509,6 +1509,22 @@ export declare const ContentEntryDataError: {
|
|
|
1509
1509
|
message(collection: string, entryId: string, error: ZodError): string;
|
|
1510
1510
|
hint: string;
|
|
1511
1511
|
};
|
|
1512
|
+
/**
|
|
1513
|
+
* @docs
|
|
1514
|
+
* @message
|
|
1515
|
+
* **Example error message:**<br/>
|
|
1516
|
+
* The schema cannot be a function for live collections. Please use a schema object instead. Check your collection definitions in your live content config file.
|
|
1517
|
+
* @description
|
|
1518
|
+
* Error in live content config.
|
|
1519
|
+
* @see
|
|
1520
|
+
* - [Experimental live content](https://astro.build/en/reference/experimental-flags/live-content-collections/)
|
|
1521
|
+
*/
|
|
1522
|
+
export declare const LiveContentConfigError: {
|
|
1523
|
+
name: string;
|
|
1524
|
+
title: string;
|
|
1525
|
+
message: (error: string, filename?: string) => string;
|
|
1526
|
+
hint: string;
|
|
1527
|
+
};
|
|
1512
1528
|
/**
|
|
1513
1529
|
* @docs
|
|
1514
1530
|
* @message
|
|
@@ -555,8 +555,10 @@ const InvalidContentEntryDataError = {
|
|
|
555
555
|
title: "Content entry data does not match schema.",
|
|
556
556
|
message(collection, entryId, error) {
|
|
557
557
|
return [
|
|
558
|
-
`**${String(collection)} \u2192 ${String(entryId)}** data does not match collection schema
|
|
559
|
-
|
|
558
|
+
`**${String(collection)} \u2192 ${String(entryId)}** data does not match collection schema.
|
|
559
|
+
`,
|
|
560
|
+
...error.errors.map((zodError) => ` **${zodError.path.join(".")}**: ${zodError.message}`),
|
|
561
|
+
""
|
|
560
562
|
].join("\n");
|
|
561
563
|
},
|
|
562
564
|
hint: "See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas."
|
|
@@ -577,12 +579,20 @@ const ContentEntryDataError = {
|
|
|
577
579
|
title: "Content entry data does not match schema.",
|
|
578
580
|
message(collection, entryId, error) {
|
|
579
581
|
return [
|
|
580
|
-
`**${String(collection)} \u2192 ${String(entryId)}** data does not match collection schema
|
|
581
|
-
|
|
582
|
+
`**${String(collection)} \u2192 ${String(entryId)}** data does not match collection schema.
|
|
583
|
+
`,
|
|
584
|
+
...error.errors.map((zodError) => ` **${zodError.path.join(".")}**: ${zodError.message}`),
|
|
585
|
+
""
|
|
582
586
|
].join("\n");
|
|
583
587
|
},
|
|
584
588
|
hint: "See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas."
|
|
585
589
|
};
|
|
590
|
+
const LiveContentConfigError = {
|
|
591
|
+
name: "LiveContentConfigError",
|
|
592
|
+
title: "Error in live content config.",
|
|
593
|
+
message: (error, filename) => `${error} Check your collection definitions in ${filename ?? "your live content config file"}.`,
|
|
594
|
+
hint: "See https://docs.astro.build/en/reference/experimental-flags/live-content-collections/ for more information on live content collections."
|
|
595
|
+
};
|
|
586
596
|
const ContentLoaderInvalidDataError = {
|
|
587
597
|
name: "ContentLoaderInvalidDataError",
|
|
588
598
|
title: "Content entry is missing an ID",
|
|
@@ -778,6 +788,7 @@ export {
|
|
|
778
788
|
InvalidGlob,
|
|
779
789
|
InvalidImageService,
|
|
780
790
|
InvalidPrerenderExport,
|
|
791
|
+
LiveContentConfigError,
|
|
781
792
|
LocalImageUsedWrongly,
|
|
782
793
|
LocalsNotAnObject,
|
|
783
794
|
LocalsReassigned,
|
package/dist/core/messages.js
CHANGED
|
@@ -37,7 +37,7 @@ function serverStart({
|
|
|
37
37
|
host,
|
|
38
38
|
base
|
|
39
39
|
}) {
|
|
40
|
-
const version = "5.
|
|
40
|
+
const version = "5.10.0";
|
|
41
41
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
42
42
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
43
43
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -274,7 +274,7 @@ function printHelp({
|
|
|
274
274
|
message.push(
|
|
275
275
|
linebreak(),
|
|
276
276
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
277
|
-
`v${"5.
|
|
277
|
+
`v${"5.10.0"}`
|
|
278
278
|
)} ${headline}`
|
|
279
279
|
);
|
|
280
280
|
}
|
|
@@ -126,8 +126,11 @@ async function runHookConfigSetup({
|
|
|
126
126
|
if (settings.config.adapter) {
|
|
127
127
|
settings.config.integrations.unshift(settings.config.adapter);
|
|
128
128
|
}
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
const actionsFilename = await isActionsFilePresent(fs, settings.config.srcDir);
|
|
130
|
+
if (actionsFilename) {
|
|
131
|
+
settings.config.integrations.push(
|
|
132
|
+
astroIntegrationActionsRouteHandler({ settings, filename: actionsFilename })
|
|
133
|
+
);
|
|
131
134
|
}
|
|
132
135
|
let updatedConfig = { ...settings.config };
|
|
133
136
|
let updatedSettings = { ...settings, config: updatedConfig };
|
|
@@ -57,7 +57,7 @@ var astro_default = {
|
|
|
57
57
|
link: "https://astro.build/chat"
|
|
58
58
|
}
|
|
59
59
|
];
|
|
60
|
-
const
|
|
60
|
+
const { latestAstroVersion, version, debugInfo } = window.__astro_dev_toolbar__ ?? {};
|
|
61
61
|
const windowComponent = createWindowElement(
|
|
62
62
|
`<style>
|
|
63
63
|
#buttons-container {
|
|
@@ -299,8 +299,8 @@ var astro_default = {
|
|
|
299
299
|
<header>
|
|
300
300
|
<section>
|
|
301
301
|
${astroLogo}
|
|
302
|
-
<astro-dev-toolbar-badge badge-style="gray" size="large">${
|
|
303
|
-
${
|
|
302
|
+
<astro-dev-toolbar-badge badge-style="gray" size="large">${version}</astro-dev-toolbar-badge>
|
|
303
|
+
${latestAstroVersion ? `<astro-dev-toolbar-badge badge-style="green" size="large">${latestAstroVersion} available!</astro-dev-toolbar-badge>
|
|
304
304
|
` : ""}
|
|
305
305
|
</section>
|
|
306
306
|
<astro-dev-toolbar-button id="copy-debug-button">Copy debug info <astro-dev-toolbar-icon icon="copy" /></astro-dev-toolbar-button>
|
|
@@ -330,9 +330,7 @@ var astro_default = {
|
|
|
330
330
|
);
|
|
331
331
|
const copyDebugButton = windowComponent.querySelector("#copy-debug-button");
|
|
332
332
|
copyDebugButton?.addEventListener("click", () => {
|
|
333
|
-
navigator.clipboard.writeText(
|
|
334
|
-
"```\n" + window.__astro_dev_toolbar__.debugInfo + "\n```"
|
|
335
|
-
);
|
|
333
|
+
navigator.clipboard.writeText("```\n" + debugInfo + "\n```");
|
|
336
334
|
copyDebugButton.textContent = "Copied to clipboard!";
|
|
337
335
|
setTimeout(() => {
|
|
338
336
|
resetDebugButton();
|
|
@@ -1242,58 +1242,70 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
|
|
|
1242
1242
|
remotePatterns?: Partial<RemotePattern>[];
|
|
1243
1243
|
/**
|
|
1244
1244
|
* @docs
|
|
1245
|
-
* @name image.
|
|
1245
|
+
* @name image.layout
|
|
1246
1246
|
* @type {ImageLayout}
|
|
1247
1247
|
* @default `undefined`
|
|
1248
|
+
* @version 5.10.0
|
|
1248
1249
|
* @description
|
|
1249
1250
|
* The default layout type for responsive images. Can be overridden by the `layout` prop on the image component.
|
|
1250
|
-
* Requires the `experimental.responsiveImages` flag to be enabled.
|
|
1251
1251
|
* - `constrained` - The image will scale to fit the container, maintaining its aspect ratio, but will not exceed the specified dimensions.
|
|
1252
1252
|
* - `fixed` - The image will maintain its original dimensions.
|
|
1253
1253
|
* - `full-width` - The image will scale to fit the container, maintaining its aspect ratio.
|
|
1254
|
+
*
|
|
1255
|
+
* See [the `layout` component property](https://docs.astro.build/en/reference/modules/astro-assets/#layout) for more details.
|
|
1254
1256
|
*/
|
|
1255
|
-
|
|
1257
|
+
layout?: ImageLayout | undefined;
|
|
1256
1258
|
/**
|
|
1257
1259
|
* @docs
|
|
1258
|
-
* @name image.
|
|
1260
|
+
* @name image.objectFit
|
|
1259
1261
|
* @type {ImageFit}
|
|
1260
1262
|
* @default `"cover"`
|
|
1263
|
+
* @version 5.10.0
|
|
1261
1264
|
* @description
|
|
1262
1265
|
* The default object-fit value for responsive images. Can be overridden by the `fit` prop on the image component.
|
|
1263
|
-
* Requires
|
|
1266
|
+
* Requires a value for `layout` to be set.
|
|
1267
|
+
*
|
|
1268
|
+
* See [the `fit` component property](https://docs.astro.build/en/reference/modules/astro-assets/#fit) for more details.
|
|
1264
1269
|
*/
|
|
1265
|
-
|
|
1270
|
+
objectFit?: ImageFit;
|
|
1266
1271
|
/**
|
|
1267
1272
|
* @docs
|
|
1268
|
-
* @name image.
|
|
1273
|
+
* @name image.objectPosition
|
|
1269
1274
|
* @type {string}
|
|
1270
1275
|
* @default `"center"`
|
|
1276
|
+
* @version 5.10.0
|
|
1271
1277
|
* @description
|
|
1272
1278
|
* The default object-position value for responsive images. Can be overridden by the `position` prop on the image component.
|
|
1273
|
-
* Requires
|
|
1279
|
+
* Requires a value for `layout` to be set.
|
|
1280
|
+
*
|
|
1281
|
+
* See [the `position` component property](https://docs.astro.build/en/reference/modules/astro-assets/#position) for more details.
|
|
1274
1282
|
*/
|
|
1275
|
-
|
|
1283
|
+
objectPosition?: string;
|
|
1276
1284
|
/**
|
|
1277
1285
|
* @docs
|
|
1278
|
-
* @name image.
|
|
1286
|
+
* @name image.breakpoints
|
|
1279
1287
|
* @type {number[]}
|
|
1280
1288
|
* @default `[640, 750, 828, 1080, 1280, 1668, 2048, 2560] | [640, 750, 828, 960, 1080, 1280, 1668, 1920, 2048, 2560, 3200, 3840, 4480, 5120, 6016]`
|
|
1289
|
+
* @version 5.10.0
|
|
1281
1290
|
* @description
|
|
1282
|
-
* The breakpoints used to generate responsive images. Requires
|
|
1291
|
+
* The breakpoints used to generate responsive images. Requires a value for `layout` to be set. The full list is not normally used,
|
|
1283
1292
|
* but is filtered according to the source and output size. The defaults used depend on whether a local or remote image service is used. For remote services
|
|
1284
1293
|
* the more comprehensive list is used, because only the required sizes are generated. For local services, the list is shorter to reduce the number of images generated.
|
|
1285
1294
|
*/
|
|
1286
|
-
|
|
1295
|
+
breakpoints?: number[];
|
|
1287
1296
|
/**
|
|
1288
1297
|
* @docs
|
|
1289
|
-
* @name image.
|
|
1298
|
+
* @name image.responsiveStyles
|
|
1290
1299
|
* @type {boolean}
|
|
1291
|
-
* @default `
|
|
1300
|
+
* @default `false`
|
|
1301
|
+
* @version 5.10.0
|
|
1292
1302
|
* @description
|
|
1293
|
-
* Whether to automatically add global styles
|
|
1294
|
-
* This option is only used when the `
|
|
1303
|
+
* Whether to automatically add global styles for responsive images. You should enable this option unless you are styling the images yourself.
|
|
1304
|
+
* This option is only used when `layout` is set to `constrained`, `full-width`, or `fixed` using the configuration or the `layout` prop on the image component.
|
|
1305
|
+
*
|
|
1306
|
+
* See [the images docs](https://docs.astro.build/en/guides/images/#responsive-image-styles) for more information.
|
|
1295
1307
|
*/
|
|
1296
|
-
|
|
1308
|
+
responsiveStyles?: boolean;
|
|
1297
1309
|
};
|
|
1298
1310
|
/**
|
|
1299
1311
|
* @docs
|
|
@@ -1974,119 +1986,6 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
|
|
|
1974
1986
|
* To use this feature with the Astro VS Code extension, you must also enable the `astro.content-intellisense` option in your VS Code settings. For editors using the Astro language server directly, pass the `contentIntellisense: true` initialization parameter to enable this feature.
|
|
1975
1987
|
*/
|
|
1976
1988
|
contentIntellisense?: boolean;
|
|
1977
|
-
/**
|
|
1978
|
-
*
|
|
1979
|
-
* @name experimental.responsiveImages
|
|
1980
|
-
* @type {boolean}
|
|
1981
|
-
* @default `undefined`
|
|
1982
|
-
* @version 5.0.0
|
|
1983
|
-
* @description
|
|
1984
|
-
*
|
|
1985
|
-
* Enables automatic responsive images in your project.
|
|
1986
|
-
*
|
|
1987
|
-
* ```js title=astro.config.mjs
|
|
1988
|
-
* {
|
|
1989
|
-
* experimental: {
|
|
1990
|
-
* responsiveImages: true,
|
|
1991
|
-
* },
|
|
1992
|
-
* }
|
|
1993
|
-
* ```
|
|
1994
|
-
*
|
|
1995
|
-
* When enabled, you can pass a `layout` props to any `<Image />` or `<Picture />` component to create a responsive image. When a layout is set, images have automatically generated `srcset` and `sizes` attributes based on the image's dimensions and the layout type. Images with `constrained` and `full-width` layouts will have styles applied to ensure they resize according to their container.
|
|
1996
|
-
*
|
|
1997
|
-
* ```astro title=MyComponent.astro
|
|
1998
|
-
* ---
|
|
1999
|
-
* import { Image, Picture } from 'astro:assets';
|
|
2000
|
-
* import myImage from '../assets/my_image.png';
|
|
2001
|
-
* ---
|
|
2002
|
-
* <Image src={myImage} alt="A description of my image." layout='constrained' width={800} height={600} />
|
|
2003
|
-
* <Picture src={myImage} alt="A description of my image." layout='full-width' formats={['avif', 'webp', 'jpeg']} />
|
|
2004
|
-
* ```
|
|
2005
|
-
* This `<Image />` component will generate the following HTML output:
|
|
2006
|
-
* ```html title=Output
|
|
2007
|
-
*
|
|
2008
|
-
* <img
|
|
2009
|
-
* src="/_astro/my_image.hash3.webp"
|
|
2010
|
-
* srcset="/_astro/my_image.hash1.webp 640w,
|
|
2011
|
-
* /_astro/my_image.hash2.webp 750w,
|
|
2012
|
-
* /_astro/my_image.hash3.webp 800w,
|
|
2013
|
-
* /_astro/my_image.hash4.webp 828w,
|
|
2014
|
-
* /_astro/my_image.hash5.webp 1080w,
|
|
2015
|
-
* /_astro/my_image.hash6.webp 1280w,
|
|
2016
|
-
* /_astro/my_image.hash7.webp 1600w"
|
|
2017
|
-
* alt="A description of my image"
|
|
2018
|
-
* sizes="(min-width: 800px) 800px, 100vw"
|
|
2019
|
-
* loading="lazy"
|
|
2020
|
-
* decoding="async"
|
|
2021
|
-
* fetchpriority="auto"
|
|
2022
|
-
* width="800"
|
|
2023
|
-
* height="600"
|
|
2024
|
-
* style="--fit: cover; --pos: center;"
|
|
2025
|
-
* data-astro-image="constrained"
|
|
2026
|
-
* >
|
|
2027
|
-
* ```
|
|
2028
|
-
*
|
|
2029
|
-
* The following styles are applied to ensure the images resize correctly:
|
|
2030
|
-
*
|
|
2031
|
-
* ```css title="Responsive Image Styles"
|
|
2032
|
-
*
|
|
2033
|
-
* :where([data-astro-image]) {
|
|
2034
|
-
* object-fit: var(--fit);
|
|
2035
|
-
* object-position: var(--pos);
|
|
2036
|
-
* }
|
|
2037
|
-
*
|
|
2038
|
-
* :where([data-astro-image='full-width']) {
|
|
2039
|
-
* width: 100%;
|
|
2040
|
-
* }
|
|
2041
|
-
*
|
|
2042
|
-
* :where([data-astro-image='constrained']) {
|
|
2043
|
-
* max-width: 100%;
|
|
2044
|
-
* }
|
|
2045
|
-
*
|
|
2046
|
-
* ```
|
|
2047
|
-
* You can enable responsive images for all `<Image />` and `<Picture />` components by setting `image.experimentalLayout` with a default value. This can be overridden by the `layout` prop on each component.
|
|
2048
|
-
*
|
|
2049
|
-
* **Example:**
|
|
2050
|
-
* ```js title=astro.config.mjs
|
|
2051
|
-
* {
|
|
2052
|
-
* image: {
|
|
2053
|
-
* // Used for all `<Image />` and `<Picture />` components unless overridden
|
|
2054
|
-
* experimentalLayout: 'constrained',
|
|
2055
|
-
* },
|
|
2056
|
-
* experimental: {
|
|
2057
|
-
* responsiveImages: true,
|
|
2058
|
-
* },
|
|
2059
|
-
* }
|
|
2060
|
-
* ```
|
|
2061
|
-
*
|
|
2062
|
-
* ```astro title=MyComponent.astro
|
|
2063
|
-
* ---
|
|
2064
|
-
* import { Image } from 'astro:assets';
|
|
2065
|
-
* import myImage from '../assets/my_image.png';
|
|
2066
|
-
* ---
|
|
2067
|
-
*
|
|
2068
|
-
* <Image src={myImage} alt="This will use responsive layout" width={800} height={600} />
|
|
2069
|
-
*
|
|
2070
|
-
* <Image src={myImage} alt="This will use full-width layout" layout="full-width" />
|
|
2071
|
-
*
|
|
2072
|
-
* <Image src={myImage} alt="This will disable responsive images" layout="none" />
|
|
2073
|
-
* ```
|
|
2074
|
-
*
|
|
2075
|
-
* #### Responsive image properties
|
|
2076
|
-
*
|
|
2077
|
-
* These are additional properties available to the `<Image />` and `<Picture />` components when responsive images are enabled:
|
|
2078
|
-
*
|
|
2079
|
-
* - `layout`: The layout type for the image. Can be `constrained`, `fixed`, `full-width` or `none`. Defaults to value of `image.experimentalLayout`.
|
|
2080
|
-
* - `fit`: Defines how the image should be cropped if the aspect ratio is changed. Values match those of CSS `object-fit`. Defaults to `cover`, or the value of `image.experimentalObjectFit` if set.
|
|
2081
|
-
* - `position`: Defines the position of the image crop if the aspect ratio is changed. Values match those of CSS `object-position`. Defaults to `center`, or the value of `image.experimentalObjectPosition` if set.
|
|
2082
|
-
* - `priority`: If set, eagerly loads the image. Otherwise images will be lazy-loaded. Use this for your largest above-the-fold image. Defaults to `false`.
|
|
2083
|
-
*
|
|
2084
|
-
* The `widths` and `sizes` attributes are automatically generated based on the image's dimensions and the layout type, and in most cases should not be set manually. The generated `sizes` attribute for `constrained` and `full-width` images
|
|
2085
|
-
* is based on the assumption that the image is displayed at close to the full width of the screen when the viewport is smaller than the image's width. If it is significantly different (e.g. if it's in a multi-column layout on small screens) you may need to adjust the `sizes` attribute manually for best results.
|
|
2086
|
-
*
|
|
2087
|
-
* The `densities` attribute is not compatible with responsive images and will be ignored if set.
|
|
2088
|
-
*/
|
|
2089
|
-
responsiveImages?: boolean;
|
|
2090
1989
|
/**
|
|
2091
1990
|
*
|
|
2092
1991
|
* @name experimental.fonts
|
|
@@ -2397,6 +2296,16 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
|
|
|
2397
2296
|
*
|
|
2398
2297
|
*/
|
|
2399
2298
|
preserveScriptOrder?: boolean;
|
|
2299
|
+
/**
|
|
2300
|
+
* @name experimental.liveContentCollections
|
|
2301
|
+
* @type {boolean}
|
|
2302
|
+
* @default `false`
|
|
2303
|
+
* @version 5.x
|
|
2304
|
+
* @description
|
|
2305
|
+
* Enables the use of live content collections.
|
|
2306
|
+
*
|
|
2307
|
+
*/
|
|
2308
|
+
liveContentCollections?: boolean;
|
|
2400
2309
|
};
|
|
2401
2310
|
}
|
|
2402
2311
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MarkdownHeading } from '@astrojs/markdown-remark';
|
|
2
2
|
import type * as rollup from 'rollup';
|
|
3
3
|
import type { DataEntry, RenderedContent } from '../../content/data-store.js';
|
|
4
|
+
import type { LiveCollectionError } from '../../content/loaders/errors.js';
|
|
4
5
|
import type { AstroComponentFactory } from '../../runtime/server/index.js';
|
|
5
6
|
import type { AstroConfig } from './config.js';
|
|
6
7
|
export interface AstroInstance {
|
|
@@ -108,4 +109,33 @@ export type GetDataEntryInfoReturnType = {
|
|
|
108
109
|
data: Record<string, unknown>;
|
|
109
110
|
rawData?: string;
|
|
110
111
|
};
|
|
112
|
+
export interface CacheHint {
|
|
113
|
+
/** Cache tags */
|
|
114
|
+
tags?: Array<string>;
|
|
115
|
+
/** Maximum age of the response in seconds */
|
|
116
|
+
maxAge?: number;
|
|
117
|
+
}
|
|
118
|
+
export interface LiveDataEntry<TData extends Record<string, any> = Record<string, unknown>> {
|
|
119
|
+
/** The ID of the entry. Unique per collection. */
|
|
120
|
+
id: string;
|
|
121
|
+
/** The parsed entry data */
|
|
122
|
+
data: TData;
|
|
123
|
+
/** A hint for how to cache this entry */
|
|
124
|
+
cacheHint?: CacheHint;
|
|
125
|
+
}
|
|
126
|
+
export interface LiveDataCollection<TData extends Record<string, any> = Record<string, unknown>> {
|
|
127
|
+
entries: Array<LiveDataEntry<TData>>;
|
|
128
|
+
/** A hint for how to cache this collection. Individual entries can also have cache hints */
|
|
129
|
+
cacheHint?: CacheHint;
|
|
130
|
+
}
|
|
131
|
+
export interface LiveDataCollectionResult<TData extends Record<string, any> = Record<string, unknown>, TError extends Error = Error> {
|
|
132
|
+
entries?: Array<LiveDataEntry<TData>>;
|
|
133
|
+
error?: TError | LiveCollectionError;
|
|
134
|
+
cacheHint?: CacheHint;
|
|
135
|
+
}
|
|
136
|
+
export interface LiveDataEntryResult<TData extends Record<string, any> = Record<string, unknown>, TError extends Error = Error> {
|
|
137
|
+
entry?: LiveDataEntry<TData>;
|
|
138
|
+
error?: TError | LiveCollectionError;
|
|
139
|
+
cacheHint?: CacheHint;
|
|
140
|
+
}
|
|
111
141
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"./assets/services/noop": "./dist/assets/services/noop.js",
|
|
65
65
|
"./assets/fonts/providers/*": "./dist/assets/fonts/providers/entrypoints/*.js",
|
|
66
66
|
"./loaders": "./dist/content/loaders/index.js",
|
|
67
|
+
"./content/config": "./dist/content/config.js",
|
|
67
68
|
"./content/runtime": "./dist/content/runtime.js",
|
|
68
69
|
"./content/runtime-assets": "./dist/content/runtime-assets.js",
|
|
69
70
|
"./debug": "./components/Debug.astro",
|
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
createGetEntries,
|
|
7
7
|
createGetEntry,
|
|
8
8
|
createGetEntryBySlug,
|
|
9
|
+
createGetLiveCollection,
|
|
10
|
+
createGetLiveEntry,
|
|
9
11
|
createReference,
|
|
10
12
|
} from 'astro/content/runtime';
|
|
11
13
|
|
|
12
14
|
export { defineCollection, renderEntry as render } from 'astro/content/runtime';
|
|
13
15
|
export { z } from 'astro/zod';
|
|
14
16
|
|
|
17
|
+
/* @@LIVE_CONTENT_CONFIG@@ */
|
|
18
|
+
|
|
15
19
|
const contentDir = '@@CONTENT_DIR@@';
|
|
16
20
|
|
|
17
21
|
const contentEntryGlob = '@@CONTENT_ENTRY_GLOB_PATH@@';
|
|
@@ -56,12 +60,14 @@ export const getCollection = createGetCollection({
|
|
|
56
60
|
dataCollectionToEntryMap,
|
|
57
61
|
getRenderEntryImport: createGlobLookup(collectionToRenderEntryMap),
|
|
58
62
|
cacheEntriesByCollection,
|
|
63
|
+
liveCollections,
|
|
59
64
|
});
|
|
60
65
|
|
|
61
66
|
export const getEntry = createGetEntry({
|
|
62
67
|
getEntryImport: createGlobLookup(collectionToEntryMap),
|
|
63
68
|
getRenderEntryImport: createGlobLookup(collectionToRenderEntryMap),
|
|
64
69
|
collectionNames,
|
|
70
|
+
liveCollections,
|
|
65
71
|
});
|
|
66
72
|
|
|
67
73
|
export const getEntryBySlug = createGetEntryBySlug({
|
|
@@ -80,3 +86,11 @@ export const getDataEntryById = createGetDataEntryById({
|
|
|
80
86
|
export const getEntries = createGetEntries(getEntry);
|
|
81
87
|
|
|
82
88
|
export const reference = createReference({ lookupMap });
|
|
89
|
+
|
|
90
|
+
export const getLiveCollection = createGetLiveCollection({
|
|
91
|
+
liveCollections,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export const getLiveEntry = createGetLiveEntry({
|
|
95
|
+
liveCollections,
|
|
96
|
+
});
|
|
@@ -45,6 +45,10 @@ declare module 'astro:content' {
|
|
|
45
45
|
collection: C;
|
|
46
46
|
slug: E;
|
|
47
47
|
};
|
|
48
|
+
export type ReferenceLiveEntry<C extends keyof LiveContentConfig['collections']> = {
|
|
49
|
+
collection: C;
|
|
50
|
+
id: string;
|
|
51
|
+
};
|
|
48
52
|
|
|
49
53
|
/** @deprecated Use `getEntry` instead. */
|
|
50
54
|
export function getEntryBySlug<
|
|
@@ -73,6 +77,13 @@ declare module 'astro:content' {
|
|
|
73
77
|
filter?: (entry: CollectionEntry<C>) => unknown,
|
|
74
78
|
): Promise<CollectionEntry<C>[]>;
|
|
75
79
|
|
|
80
|
+
export function getLiveCollection<C extends keyof LiveContentConfig['collections']>(
|
|
81
|
+
collection: C,
|
|
82
|
+
filter?: LiveLoaderCollectionFilterType<C>,
|
|
83
|
+
): Promise<
|
|
84
|
+
import('astro').LiveDataCollectionResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>
|
|
85
|
+
>;
|
|
86
|
+
|
|
76
87
|
export function getEntry<
|
|
77
88
|
C extends keyof ContentEntryMap,
|
|
78
89
|
E extends ValidContentEntrySlug<C> | (string & {}),
|
|
@@ -109,6 +120,10 @@ declare module 'astro:content' {
|
|
|
109
120
|
? Promise<DataEntryMap[C][E]> | undefined
|
|
110
121
|
: Promise<DataEntryMap[C][E]>
|
|
111
122
|
: Promise<CollectionEntry<C> | undefined>;
|
|
123
|
+
export function getLiveEntry<C extends keyof LiveContentConfig['collections']>(
|
|
124
|
+
collection: C,
|
|
125
|
+
filter: string | LiveLoaderEntryFilterType<C>,
|
|
126
|
+
): Promise<import('astro').LiveDataEntryResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>>;
|
|
112
127
|
|
|
113
128
|
/** Resolve an array of entry references from the same collection */
|
|
114
129
|
export function getEntries<C extends keyof ContentEntryMap>(
|
|
@@ -152,5 +167,33 @@ declare module 'astro:content' {
|
|
|
152
167
|
|
|
153
168
|
type AnyEntryMap = ContentEntryMap & DataEntryMap;
|
|
154
169
|
|
|
170
|
+
type ExtractLoaderTypes<T> = T extends import('astro/loaders').LiveLoader<
|
|
171
|
+
infer TData,
|
|
172
|
+
infer TEntryFilter,
|
|
173
|
+
infer TCollectionFilter,
|
|
174
|
+
infer TError
|
|
175
|
+
>
|
|
176
|
+
? { data: TData; entryFilter: TEntryFilter; collectionFilter: TCollectionFilter; error: TError }
|
|
177
|
+
: { data: never; entryFilter: never; collectionFilter: never; error: never };
|
|
178
|
+
type ExtractDataType<T> = ExtractLoaderTypes<T>['data'];
|
|
179
|
+
type ExtractEntryFilterType<T> = ExtractLoaderTypes<T>['entryFilter'];
|
|
180
|
+
type ExtractCollectionFilterType<T> = ExtractLoaderTypes<T>['collectionFilter'];
|
|
181
|
+
type ExtractErrorType<T> = ExtractLoaderTypes<T>['error'];
|
|
182
|
+
|
|
183
|
+
type LiveLoaderDataType<C extends keyof LiveContentConfig['collections']> =
|
|
184
|
+
LiveContentConfig['collections'][C]['schema'] extends undefined
|
|
185
|
+
? ExtractDataType<LiveContentConfig['collections'][C]['loader']>
|
|
186
|
+
: import('astro/zod').infer<
|
|
187
|
+
Exclude<LiveContentConfig['collections'][C]['schema'], undefined>
|
|
188
|
+
>;
|
|
189
|
+
type LiveLoaderEntryFilterType<C extends keyof LiveContentConfig['collections']> =
|
|
190
|
+
ExtractEntryFilterType<LiveContentConfig['collections'][C]['loader']>;
|
|
191
|
+
type LiveLoaderCollectionFilterType<C extends keyof LiveContentConfig['collections']> =
|
|
192
|
+
ExtractCollectionFilterType<LiveContentConfig['collections'][C]['loader']>;
|
|
193
|
+
type LiveLoaderErrorType<C extends keyof LiveContentConfig['collections']> = ExtractErrorType<
|
|
194
|
+
LiveContentConfig['collections'][C]['loader']
|
|
195
|
+
>;
|
|
196
|
+
|
|
155
197
|
export type ContentConfig = '@@CONTENT_CONFIG_TYPE@@';
|
|
198
|
+
export type LiveContentConfig = '@@LIVE_CONTENT_CONFIG_TYPE@@';
|
|
156
199
|
}
|
package/types/content.d.ts
CHANGED
|
@@ -1,85 +1,24 @@
|
|
|
1
1
|
declare module 'astro:content' {
|
|
2
2
|
export { z } from 'astro/zod';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export interface DataEntry {
|
|
24
|
-
id: string;
|
|
25
|
-
data: Record<string, unknown>;
|
|
26
|
-
filePath?: string;
|
|
27
|
-
body?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface DataStore {
|
|
31
|
-
get: (key: string) => DataEntry;
|
|
32
|
-
entries: () => Array<[id: string, DataEntry]>;
|
|
33
|
-
set: (key: string, data: Record<string, unknown>, body?: string, filePath?: string) => void;
|
|
34
|
-
values: () => Array<DataEntry>;
|
|
35
|
-
keys: () => Array<string>;
|
|
36
|
-
delete: (key: string) => void;
|
|
37
|
-
clear: () => void;
|
|
38
|
-
has: (key: string) => boolean;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface MetaStore {
|
|
42
|
-
get: (key: string) => string | undefined;
|
|
43
|
-
set: (key: string, value: string) => void;
|
|
44
|
-
delete: (key: string) => void;
|
|
45
|
-
has: (key: string) => boolean;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type BaseSchema = import('astro/zod').ZodType;
|
|
49
|
-
|
|
50
|
-
export type SchemaContext = { image: ImageFunction };
|
|
51
|
-
|
|
52
|
-
type ContentLayerConfig<S extends BaseSchema, TData extends { id: string } = { id: string }> = {
|
|
53
|
-
type?: 'content_layer';
|
|
54
|
-
schema?: S | ((context: SchemaContext) => S);
|
|
55
|
-
loader:
|
|
56
|
-
| import('astro/loaders').Loader
|
|
57
|
-
| (() =>
|
|
58
|
-
| Array<TData>
|
|
59
|
-
| Promise<Array<TData>>
|
|
60
|
-
| Record<string, Omit<TData, 'id'> & { id?: string }>
|
|
61
|
-
| Promise<Record<string, Omit<TData, 'id'> & { id?: string }>>);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
type DataCollectionConfig<S extends BaseSchema> = {
|
|
65
|
-
type: 'data';
|
|
66
|
-
schema?: S | ((context: SchemaContext) => S);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
type ContentCollectionConfig<S extends BaseSchema> = {
|
|
70
|
-
type?: 'content';
|
|
71
|
-
schema?: S | ((context: SchemaContext) => S);
|
|
72
|
-
loader?: never;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export type CollectionConfig<S extends BaseSchema> =
|
|
76
|
-
| ContentCollectionConfig<S>
|
|
77
|
-
| DataCollectionConfig<S>
|
|
78
|
-
| ContentLayerConfig<S>;
|
|
79
|
-
|
|
80
|
-
export function defineCollection<S extends BaseSchema>(
|
|
81
|
-
input: CollectionConfig<S>,
|
|
82
|
-
): CollectionConfig<S>;
|
|
3
|
+
export type {
|
|
4
|
+
ImageFunction,
|
|
5
|
+
DataEntry,
|
|
6
|
+
DataStore,
|
|
7
|
+
MetaStore,
|
|
8
|
+
BaseSchema,
|
|
9
|
+
SchemaContext,
|
|
10
|
+
} from 'astro/content/config';
|
|
11
|
+
|
|
12
|
+
export function defineLiveCollection<
|
|
13
|
+
L extends import('astro/loader').LiveLoader,
|
|
14
|
+
S extends import('astro/content/config').BaseSchema | undefined = undefined,
|
|
15
|
+
>(
|
|
16
|
+
config: import('astro/content/config').LiveCollectionConfig<L, S>,
|
|
17
|
+
): import('astro/content/config').LiveCollectionConfig<L, S>;
|
|
18
|
+
|
|
19
|
+
export function defineCollection<S extends import('astro/content/config').BaseSchema>(
|
|
20
|
+
config: import('astro/content/config').CollectionConfig<S>,
|
|
21
|
+
): import('astro/content/config').CollectionConfig<S>;
|
|
83
22
|
|
|
84
23
|
/** Run `astro dev` or `astro sync` to generate high fidelity types */
|
|
85
24
|
export const getEntryBySlug: (...args: any[]) => any;
|
|
@@ -106,4 +45,8 @@ declare module 'astro:content' {
|
|
|
106
45
|
export type ContentConfig = any;
|
|
107
46
|
/** Run `astro dev` or `astro sync` to generate high fidelity types */
|
|
108
47
|
export const render: (entry: any) => any;
|
|
48
|
+
/** Run `astro dev` or `astro sync` to generate high fidelity types */
|
|
49
|
+
export const getLiveCollection: (...args: any[]) => any;
|
|
50
|
+
/** Run `astro dev` or `astro sync` to generate high fidelity types */
|
|
51
|
+
export const getLiveEntry: (...args: any[]) => any;
|
|
109
52
|
}
|