astro 3.4.4 → 3.5.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 +86 -0
- package/components/Code.astro +15 -2
- package/components/Picture.astro +2 -1
- package/components/ViewTransitions.astro +39 -38
- package/content-module.template.mjs +4 -14
- package/dist/@types/astro.d.ts +222 -5
- package/dist/assets/build/generate.d.ts +2 -1
- package/dist/assets/build/generate.js +16 -5
- package/dist/assets/consts.d.ts +1 -0
- package/dist/assets/consts.js +2 -0
- package/dist/assets/endpoint/generic.js +6 -2
- package/dist/assets/internal.js +9 -2
- package/dist/assets/services/service.d.ts +8 -3
- package/dist/assets/services/service.js +2 -1
- package/dist/assets/services/vendor/squoosh/image-pool.d.ts +1 -2
- package/dist/assets/types.d.ts +9 -5
- package/dist/assets/utils/emitAsset.js +5 -0
- package/dist/assets/utils/metadata.d.ts +1 -2
- package/dist/assets/utils/proxy.d.ts +1 -0
- package/dist/assets/utils/proxy.js +16 -0
- package/dist/assets/utils/queryParams.d.ts +1 -1
- package/dist/assets/utils/transformToPath.d.ts +1 -1
- package/dist/assets/utils/transformToPath.js +8 -3
- package/dist/assets/vite-plugin-assets.js +26 -11
- package/dist/cli/build/index.js +1 -1
- package/dist/content/consts.d.ts +1 -0
- package/dist/content/consts.js +2 -0
- package/dist/content/runtime-assets.d.ts +9 -1
- package/dist/content/runtime-assets.js +1 -1
- package/dist/content/runtime.d.ts +1 -0
- package/dist/content/runtime.js +8 -2
- package/dist/content/utils.d.ts +1 -0
- package/dist/content/utils.js +9 -0
- package/dist/content/vite-plugin-content-assets.js +49 -23
- package/dist/content/vite-plugin-content-imports.js +9 -3
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +17 -12
- package/dist/content/vite-plugin-content-virtual-mod.js +136 -57
- package/dist/core/app/index.js +19 -4
- package/dist/core/app/types.d.ts +7 -1
- package/dist/core/build/buildPipeline.js +17 -4
- package/dist/core/build/common.js +2 -0
- package/dist/core/build/generate.js +64 -34
- package/dist/core/build/index.d.ts +0 -8
- package/dist/core/build/index.js +9 -2
- package/dist/core/build/internal.d.ts +11 -1
- package/dist/core/build/internal.js +23 -1
- package/dist/core/build/page-data.js +46 -18
- package/dist/core/build/plugin.d.ts +12 -10
- package/dist/core/build/plugin.js +14 -22
- package/dist/core/build/plugins/index.js +4 -0
- package/dist/core/build/plugins/plugin-alias-resolve.js +1 -1
- package/dist/core/build/plugins/plugin-analyzer.js +1 -1
- package/dist/core/build/plugins/plugin-chunks.d.ts +4 -0
- package/dist/core/build/plugins/plugin-chunks.js +31 -0
- package/dist/core/build/plugins/plugin-component-entry.js +1 -1
- package/dist/core/build/plugins/plugin-content.d.ts +4 -0
- package/dist/core/build/plugins/plugin-content.js +273 -0
- package/dist/core/build/plugins/plugin-css.js +9 -4
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +1 -1
- package/dist/core/build/plugins/plugin-internals.js +1 -1
- package/dist/core/build/plugins/plugin-manifest.js +14 -5
- package/dist/core/build/plugins/plugin-middleware.d.ts +1 -3
- package/dist/core/build/plugins/plugin-middleware.js +5 -57
- package/dist/core/build/plugins/plugin-pages.js +3 -3
- package/dist/core/build/plugins/plugin-prerender.js +2 -5
- package/dist/core/build/plugins/plugin-renderers.js +1 -1
- package/dist/core/build/plugins/plugin-ssr.js +6 -5
- package/dist/core/build/plugins/util.d.ts +3 -3
- package/dist/core/build/static-build.d.ts +2 -1
- package/dist/core/build/static-build.js +52 -28
- package/dist/core/build/types.d.ts +1 -1
- package/dist/core/build/util.d.ts +7 -0
- package/dist/core/build/util.js +37 -1
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/config/config.js +3 -0
- package/dist/core/config/schema.d.ts +208 -0
- package/dist/core/config/schema.js +55 -2
- package/dist/core/config/settings.js +1 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +9 -3
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.d.ts +4 -3
- package/dist/core/endpoint/index.js +29 -3
- package/dist/core/errors/errors-data.d.ts +11 -0
- package/dist/core/errors/errors-data.js +17 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/index.d.ts +7 -3
- package/dist/core/middleware/index.js +3 -2
- package/dist/core/middleware/loadMiddleware.d.ts +1 -2
- package/dist/core/middleware/loadMiddleware.js +3 -4
- package/dist/core/middleware/sequence.d.ts +2 -2
- package/dist/core/middleware/sequence.js +3 -2
- package/dist/core/middleware/vite-plugin.d.ts +9 -0
- package/dist/core/middleware/vite-plugin.js +101 -0
- package/dist/core/pipeline.d.ts +1 -1
- package/dist/core/pipeline.js +6 -4
- package/dist/core/redirects/helpers.d.ts +1 -0
- package/dist/core/redirects/helpers.js +4 -0
- package/dist/core/render/context.d.ts +24 -1
- package/dist/core/render/context.js +96 -2
- package/dist/core/render/core.d.ts +2 -14
- package/dist/core/render/core.js +12 -52
- package/dist/core/render/index.d.ts +2 -3
- package/dist/core/render/index.js +3 -4
- package/dist/core/render/params-and-props.d.ts +1 -1
- package/dist/core/render/params-and-props.js +5 -2
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +23 -0
- package/dist/core/render/route-cache.d.ts +1 -1
- package/dist/core/render/route-cache.js +17 -11
- package/dist/core/routing/manifest/create.js +118 -4
- package/dist/core/sync/index.d.ts +2 -24
- package/dist/i18n/index.d.ts +54 -0
- package/dist/i18n/index.js +91 -0
- package/dist/i18n/middleware.d.ts +2 -0
- package/dist/i18n/middleware.js +62 -0
- package/dist/i18n/vite-plugin-i18n.d.ts +7 -0
- package/dist/i18n/vite-plugin-i18n.js +62 -0
- package/dist/integrations/astroFeaturesValidation.js +4 -1
- package/dist/integrations/index.js +12 -0
- package/dist/prefetch/index.d.ts +31 -0
- package/dist/prefetch/index.js +176 -0
- package/dist/prefetch/vite-plugin-prefetch.d.ts +5 -0
- package/dist/prefetch/vite-plugin-prefetch.js +43 -0
- package/dist/runtime/client/dev-overlay/plugins/audit.js +17 -9
- package/dist/runtime/server/index.d.ts +0 -2
- package/dist/runtime/server/render/component.js +3 -5
- package/dist/transitions/router.d.ts +1 -0
- package/dist/transitions/router.js +9 -4
- package/dist/transitions/vite-plugin-transitions.d.ts +4 -1
- package/dist/transitions/vite-plugin-transitions.js +7 -1
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +1 -0
- package/dist/vite-plugin-astro-server/devPipeline.js +2 -0
- package/dist/vite-plugin-astro-server/plugin.js +11 -1
- package/dist/vite-plugin-astro-server/route.js +113 -51
- package/dist/vite-plugin-head/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +1 -0
- package/package.json +7 -5
- package/tsconfigs/base.json +1 -1
- package/dist/core/endpoint/dev/index.d.ts +0 -2
- package/dist/core/endpoint/dev/index.js +0 -17
package/client.d.ts
CHANGED
|
@@ -119,6 +119,92 @@ declare module 'astro:transitions/client' {
|
|
|
119
119
|
export const supportsViewTransitions: TransitionRouterModule['supportsViewTransitions'];
|
|
120
120
|
export const transitionEnabledOnThisPage: TransitionRouterModule['transitionEnabledOnThisPage'];
|
|
121
121
|
export const navigate: TransitionRouterModule['navigate'];
|
|
122
|
+
export type Options = import('./dist/transitions/router.js').Options;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare module 'astro:prefetch' {
|
|
126
|
+
export { prefetch, PrefetchOptions } from 'astro/prefetch';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare module 'astro:i18n' {
|
|
130
|
+
export type GetLocaleOptions = import('./dist/i18n/index.js').GetLocaleOptions;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @param {string} locale A locale
|
|
134
|
+
* @param {string} [path=""] An optional path to add after the `locale`.
|
|
135
|
+
* @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path
|
|
136
|
+
* @return {string}
|
|
137
|
+
*
|
|
138
|
+
* Returns a _relative_ path with passed locale.
|
|
139
|
+
*
|
|
140
|
+
* ## Errors
|
|
141
|
+
*
|
|
142
|
+
* Throws an error if the locale doesn't exist in the list of locales defined in the configuration.
|
|
143
|
+
*
|
|
144
|
+
* ## Examples
|
|
145
|
+
*
|
|
146
|
+
* ```js
|
|
147
|
+
* import { getRelativeLocaleUrl } from "astro:i18n";
|
|
148
|
+
* getRelativeLocaleUrl("es"); // /es
|
|
149
|
+
* getRelativeLocaleUrl("es", "getting-started"); // /es/getting-started
|
|
150
|
+
* getRelativeLocaleUrl("es_US", "getting-started", { prependWith: "blog" }); // /blog/es-us/getting-started
|
|
151
|
+
* getRelativeLocaleUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // /blog/es_US/getting-started
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export const getRelativeLocaleUrl: (
|
|
155
|
+
locale: string,
|
|
156
|
+
path?: string,
|
|
157
|
+
options?: GetLocaleOptions
|
|
158
|
+
) => string;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* @param {string} locale A locale
|
|
163
|
+
* @param {string} [path=""] An optional path to add after the `locale`.
|
|
164
|
+
* @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path
|
|
165
|
+
* @return {string}
|
|
166
|
+
*
|
|
167
|
+
* Returns an absolute path with the passed locale. The behaviour is subject to change based on `site` configuration.
|
|
168
|
+
* If _not_ provided, the function will return a _relative_ URL.
|
|
169
|
+
*
|
|
170
|
+
* ## Errors
|
|
171
|
+
*
|
|
172
|
+
* Throws an error if the locale doesn't exist in the list of locales defined in the configuration.
|
|
173
|
+
*
|
|
174
|
+
* ## Examples
|
|
175
|
+
*
|
|
176
|
+
* If `site` is `https://example.com`:
|
|
177
|
+
*
|
|
178
|
+
* ```js
|
|
179
|
+
* import { getAbsoluteLocaleUrl } from "astro:i18n";
|
|
180
|
+
* getAbsoluteLocaleUrl("es"); // https://example.com/es
|
|
181
|
+
* getAbsoluteLocaleUrl("es", "getting-started"); // https://example.com/es/getting-started
|
|
182
|
+
* getAbsoluteLocaleUrl("es_US", "getting-started", { prependWith: "blog" }); // https://example.com/blog/es-us/getting-started
|
|
183
|
+
* getAbsoluteLocaleUrl("es_US", "getting-started", { prependWith: "blog", normalizeLocale: false }); // https://example.com/blog/es_US/getting-started
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export const getAbsoluteLocaleUrl: (
|
|
187
|
+
locale: string,
|
|
188
|
+
path?: string,
|
|
189
|
+
options?: GetLocaleOptions
|
|
190
|
+
) => string;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @param {string} [path=""] An optional path to add after the `locale`.
|
|
194
|
+
* @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path
|
|
195
|
+
* @return {string[]}
|
|
196
|
+
*
|
|
197
|
+
* Works like `getRelativeLocaleUrl` but it emits the relative URLs for ALL locales:
|
|
198
|
+
*/
|
|
199
|
+
export const getRelativeLocaleUrlList: (path?: string, options?: GetLocaleOptions) => string[];
|
|
200
|
+
/**
|
|
201
|
+
* @param {string} [path=""] An optional path to add after the `locale`.
|
|
202
|
+
* @param {import('./dist/i18n/index.js').GetLocaleOptions} options Customise the generated path
|
|
203
|
+
* @return {string[]}
|
|
204
|
+
*
|
|
205
|
+
* Works like `getAbsoluteLocaleUrl` but it emits the absolute URLs for ALL locales:
|
|
206
|
+
*/
|
|
207
|
+
export const getAbsoluteLocaleUrlList: (path?: string, options?: GetLocaleOptions) => string[];
|
|
122
208
|
}
|
|
123
209
|
|
|
124
210
|
declare module 'astro:middleware' {
|
package/components/Code.astro
CHANGED
|
@@ -32,6 +32,11 @@ interface Props {
|
|
|
32
32
|
* @default "github-dark"
|
|
33
33
|
*/
|
|
34
34
|
theme?: BuiltinTheme | ThemeRegistration | ThemeRegistrationRaw;
|
|
35
|
+
/**
|
|
36
|
+
* Multiple themes to style with -- alternative to "theme" option.
|
|
37
|
+
* Supports all themes found above; see https://github.com/antfu/shikiji#lightdark-dual-themes for more information.
|
|
38
|
+
*/
|
|
39
|
+
experimentalThemes?: Record<string, BuiltinTheme | ThemeRegistration | ThemeRegistrationRaw>;
|
|
35
40
|
/**
|
|
36
41
|
* Enable word wrapping.
|
|
37
42
|
* - true: enabled.
|
|
@@ -53,6 +58,7 @@ const {
|
|
|
53
58
|
code,
|
|
54
59
|
lang = 'plaintext',
|
|
55
60
|
theme = 'github-dark',
|
|
61
|
+
experimentalThemes = {},
|
|
56
62
|
wrap = false,
|
|
57
63
|
inline = false,
|
|
58
64
|
} = Astro.props;
|
|
@@ -88,12 +94,15 @@ if (typeof lang === 'object') {
|
|
|
88
94
|
|
|
89
95
|
const highlighter = await getCachedHighlighter({
|
|
90
96
|
langs: [lang],
|
|
91
|
-
themes: [theme],
|
|
97
|
+
themes: Object.values(experimentalThemes).length ? Object.values(experimentalThemes) : [theme],
|
|
92
98
|
});
|
|
93
99
|
|
|
100
|
+
const themeOptions = Object.values(experimentalThemes).length
|
|
101
|
+
? { themes: experimentalThemes }
|
|
102
|
+
: { theme };
|
|
94
103
|
const html = highlighter.codeToHtml(code, {
|
|
95
104
|
lang: typeof lang === 'string' ? lang : lang.name,
|
|
96
|
-
|
|
105
|
+
...themeOptions,
|
|
97
106
|
transforms: {
|
|
98
107
|
pre(node) {
|
|
99
108
|
// Swap to `code` tag if inline
|
|
@@ -123,6 +132,10 @@ const html = highlighter.codeToHtml(code, {
|
|
|
123
132
|
}
|
|
124
133
|
},
|
|
125
134
|
root(node) {
|
|
135
|
+
if (Object.values(experimentalThemes).length) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
126
139
|
// theme.id for shiki -> shikiji compat
|
|
127
140
|
const themeName = typeof theme === 'string' ? theme : theme.name;
|
|
128
141
|
if (themeName === 'css-variables') {
|
package/components/Picture.astro
CHANGED
|
@@ -17,8 +17,9 @@ const defaultFallbackFormat = 'png' as const;
|
|
|
17
17
|
// Certain formats don't want PNG fallbacks:
|
|
18
18
|
// - GIF will typically want to stay as a gif, either for animation or for the lower amount of colors
|
|
19
19
|
// - SVGs can't be converted to raster formats in most cases
|
|
20
|
+
// - JPEGs compress photographs and high-noise images better than PNG in most cases
|
|
20
21
|
// For those, we'll use the original format as the fallback instead.
|
|
21
|
-
const specialFormatsFallback = ['gif', 'svg'] as const;
|
|
22
|
+
const specialFormatsFallback = ['gif', 'svg', 'jpg', 'jpeg'] as const;
|
|
22
23
|
|
|
23
24
|
const { formats = defaultFormats, pictureAttributes = {}, fallbackFormat, ...props } = Astro.props;
|
|
24
25
|
|
|
@@ -3,9 +3,10 @@ type Fallback = 'none' | 'animate' | 'swap';
|
|
|
3
3
|
|
|
4
4
|
export interface Props {
|
|
5
5
|
fallback?: Fallback;
|
|
6
|
+
handleForms?: boolean;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
const { fallback = 'animate' } = Astro.props;
|
|
9
|
+
const { fallback = 'animate', handleForms } = Astro.props;
|
|
9
10
|
---
|
|
10
11
|
|
|
11
12
|
<style is:global>
|
|
@@ -24,12 +25,13 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
24
25
|
</style>
|
|
25
26
|
<meta name="astro-view-transitions-enabled" content="true" />
|
|
26
27
|
<meta name="astro-view-transitions-fallback" content={fallback} />
|
|
28
|
+
{handleForms ? <meta name="astro-view-transitions-forms" content="true" /> : ''}
|
|
27
29
|
<script>
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
import type { Options } from 'astro:transitions/client';
|
|
31
|
+
import { supportsViewTransitions, navigate } from 'astro:transitions/client';
|
|
32
|
+
// NOTE: import from `astro/prefetch` as `astro:prefetch` requires the `prefetch` config to be enabled
|
|
33
|
+
import { init } from 'astro/prefetch';
|
|
34
|
+
|
|
33
35
|
export type Fallback = 'none' | 'animate' | 'swap';
|
|
34
36
|
|
|
35
37
|
function getFallback(): Fallback {
|
|
@@ -40,19 +42,8 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
40
42
|
return 'animate';
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (document.querySelector(`link[rel=prefetch][href="${pathname}"]`)) return;
|
|
46
|
-
// @ts-expect-error: connection might exist
|
|
47
|
-
if (navigator.connection) {
|
|
48
|
-
// @ts-expect-error: connection does exist
|
|
49
|
-
let conn = navigator.connection;
|
|
50
|
-
if (conn.saveData || /(2|3)g/.test(conn.effectiveType || '')) return;
|
|
51
|
-
}
|
|
52
|
-
let link = document.createElement('link');
|
|
53
|
-
link.setAttribute('rel', 'prefetch');
|
|
54
|
-
link.setAttribute('href', pathname);
|
|
55
|
-
document.head.append(link);
|
|
45
|
+
function isReloadEl(el: HTMLElement): boolean {
|
|
46
|
+
return el.dataset.astroReload !== undefined;
|
|
56
47
|
}
|
|
57
48
|
|
|
58
49
|
if (supportsViewTransitions || getFallback() !== 'none') {
|
|
@@ -67,7 +58,7 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
67
58
|
if (
|
|
68
59
|
!link ||
|
|
69
60
|
!(link instanceof HTMLAnchorElement) ||
|
|
70
|
-
link
|
|
61
|
+
isReloadEl(link) ||
|
|
71
62
|
link.hasAttribute('download') ||
|
|
72
63
|
!link.href ||
|
|
73
64
|
(link.target && link.target !== '_self') ||
|
|
@@ -89,23 +80,33 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
89
80
|
});
|
|
90
81
|
});
|
|
91
82
|
|
|
92
|
-
|
|
93
|
-
document.addEventListener(
|
|
94
|
-
|
|
95
|
-
(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
83
|
+
if (document.querySelector('[name="astro-view-transitions-forms"]')) {
|
|
84
|
+
document.addEventListener('submit', (ev) => {
|
|
85
|
+
let el = ev.target as HTMLElement;
|
|
86
|
+
if (el.tagName !== 'FORM' || isReloadEl(el)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const form = el as HTMLFormElement;
|
|
91
|
+
const formData = new FormData(form);
|
|
92
|
+
let action = form.action;
|
|
93
|
+
const options: Options = {};
|
|
94
|
+
if (form.method === 'get') {
|
|
95
|
+
const params = new URLSearchParams(formData as any);
|
|
96
|
+
const url = new URL(action);
|
|
97
|
+
url.search = params.toString();
|
|
98
|
+
action = url.toString();
|
|
99
|
+
} else {
|
|
100
|
+
options.formData = formData;
|
|
101
|
+
}
|
|
102
|
+
ev.preventDefault();
|
|
103
|
+
navigate(action, options);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// @ts-expect-error injected by vite-plugin-transitions for treeshaking
|
|
108
|
+
if (!__PREFETCH_DISABLED__) {
|
|
109
|
+
init({ prefetchAll: true });
|
|
110
|
+
}
|
|
110
111
|
}
|
|
111
112
|
</script>
|
|
@@ -9,21 +9,18 @@ import {
|
|
|
9
9
|
createReference,
|
|
10
10
|
} from 'astro/content/runtime';
|
|
11
11
|
|
|
12
|
+
export { defineCollection } from 'astro/content/runtime';
|
|
12
13
|
export { z } from 'astro/zod';
|
|
13
14
|
|
|
14
15
|
const contentDir = '@@CONTENT_DIR@@';
|
|
15
16
|
|
|
16
|
-
const contentEntryGlob =
|
|
17
|
-
query: { astroContentCollectionEntry: true },
|
|
18
|
-
});
|
|
17
|
+
const contentEntryGlob = '@@CONTENT_ENTRY_GLOB_PATH@@';
|
|
19
18
|
const contentCollectionToEntryMap = createCollectionToGlobResultMap({
|
|
20
19
|
globResult: contentEntryGlob,
|
|
21
20
|
contentDir,
|
|
22
21
|
});
|
|
23
22
|
|
|
24
|
-
const dataEntryGlob =
|
|
25
|
-
query: { astroDataCollectionEntry: true },
|
|
26
|
-
});
|
|
23
|
+
const dataEntryGlob = '@@DATA_ENTRY_GLOB_PATH@@';
|
|
27
24
|
const dataCollectionToEntryMap = createCollectionToGlobResultMap({
|
|
28
25
|
globResult: dataEntryGlob,
|
|
29
26
|
contentDir,
|
|
@@ -45,19 +42,12 @@ function createGlobLookup(glob) {
|
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
const renderEntryGlob =
|
|
49
|
-
query: { astroRenderContent: true },
|
|
50
|
-
});
|
|
45
|
+
const renderEntryGlob = '@@RENDER_ENTRY_GLOB_PATH@@';
|
|
51
46
|
const collectionToRenderEntryMap = createCollectionToGlobResultMap({
|
|
52
47
|
globResult: renderEntryGlob,
|
|
53
48
|
contentDir,
|
|
54
49
|
});
|
|
55
50
|
|
|
56
|
-
export function defineCollection(config) {
|
|
57
|
-
if (!config.type) config.type = 'content';
|
|
58
|
-
return config;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
51
|
export const getCollection = createGetCollection({
|
|
62
52
|
contentCollectionToEntryMap,
|
|
63
53
|
dataCollectionToEntryMap,
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -464,6 +464,67 @@ export interface AstroUserConfig {
|
|
|
464
464
|
* ```
|
|
465
465
|
*/
|
|
466
466
|
redirects?: Record<string, RedirectConfig>;
|
|
467
|
+
/**
|
|
468
|
+
* @docs
|
|
469
|
+
* @name prefetch
|
|
470
|
+
* @type {boolean | object}
|
|
471
|
+
* @description
|
|
472
|
+
* Enable prefetching for links on your site to provide faster page transitions.
|
|
473
|
+
* (Enabled by default on pages using the `<ViewTransitions />` router. Set `prefetch: false` to opt out of this behaviour.)
|
|
474
|
+
*
|
|
475
|
+
* This configuration automatically adds a prefetch script to every page in the project
|
|
476
|
+
* giving you access to the `data-astro-prefetch` attribute.
|
|
477
|
+
* Add this attribute to any `<a />` link on your page to enable prefetching for that page.
|
|
478
|
+
*
|
|
479
|
+
* ```html
|
|
480
|
+
* <a href="/about" data-astro-prefetch>About</a>
|
|
481
|
+
* ```
|
|
482
|
+
* Further customize the default prefetching behavior using the [`prefetch.defaultStrategy`](#prefetchdefaultstrategy) and [`prefetch.prefetchAll`](#prefetchprefetchall) options.
|
|
483
|
+
*
|
|
484
|
+
* See the [Prefetch guide](https://docs.astro.build/en/guides/prefetch/) for more information.
|
|
485
|
+
*/
|
|
486
|
+
prefetch?: boolean | {
|
|
487
|
+
/**
|
|
488
|
+
* @docs
|
|
489
|
+
* @name prefetch.prefetchAll
|
|
490
|
+
* @type {boolean}
|
|
491
|
+
* @description
|
|
492
|
+
* Enable prefetching for all links, including those without the `data-astro-prefetch` attribute.
|
|
493
|
+
* This value defaults to `true` when using the `<ViewTransitions />` router. Otherwise, the default value is `false`.
|
|
494
|
+
*
|
|
495
|
+
* ```js
|
|
496
|
+
* prefetch: {
|
|
497
|
+
* prefetchAll: true
|
|
498
|
+
* }
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* When set to `true`, you can disable prefetching individually by setting `data-astro-prefetch="false"` on any individual links.
|
|
502
|
+
*
|
|
503
|
+
* ```html
|
|
504
|
+
* <a href="/about" data-astro-prefetch="false">About</a>
|
|
505
|
+
*```
|
|
506
|
+
*/
|
|
507
|
+
prefetchAll?: boolean;
|
|
508
|
+
/**
|
|
509
|
+
* @docs
|
|
510
|
+
* @name prefetch.defaultStrategy
|
|
511
|
+
* @type {'tap' | 'hover' | 'viewport'}
|
|
512
|
+
* @default `'hover'`
|
|
513
|
+
* @description
|
|
514
|
+
* The default prefetch strategy to use when the `data-astro-prefetch` attribute is set on a link with no value.
|
|
515
|
+
*
|
|
516
|
+
* - `'tap'`: Prefetch just before you click on the link.
|
|
517
|
+
* - `'hover'`: Prefetch when you hover over or focus on the link. (default)
|
|
518
|
+
* - `'viewport'`: Prefetch as the links enter the viewport.
|
|
519
|
+
*
|
|
520
|
+
* You can override this default value and select a different strategy for any individual link by setting a value on the attribute.
|
|
521
|
+
*
|
|
522
|
+
* ```html
|
|
523
|
+
* <a href="/about" data-astro-prefetch="viewport">About</a>
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
defaultStrategy?: 'tap' | 'hover' | 'viewport';
|
|
527
|
+
};
|
|
467
528
|
/**
|
|
468
529
|
* @docs
|
|
469
530
|
* @name site
|
|
@@ -1275,6 +1336,107 @@ export interface AstroUserConfig {
|
|
|
1275
1336
|
* ```
|
|
1276
1337
|
*/
|
|
1277
1338
|
devOverlay?: boolean;
|
|
1339
|
+
/**
|
|
1340
|
+
* @docs
|
|
1341
|
+
* @name experimental.i18n
|
|
1342
|
+
* @type {object}
|
|
1343
|
+
* @version 3.5.0
|
|
1344
|
+
* @type {object}
|
|
1345
|
+
* @description
|
|
1346
|
+
*
|
|
1347
|
+
* Configures experimental i18n routing and allows you to specify some customization options.
|
|
1348
|
+
*/
|
|
1349
|
+
i18n?: {
|
|
1350
|
+
/**
|
|
1351
|
+
* @docs
|
|
1352
|
+
* @name experimental.i18n.defaultLocale
|
|
1353
|
+
* @type {string}
|
|
1354
|
+
* @version 3.5.0
|
|
1355
|
+
* @description
|
|
1356
|
+
*
|
|
1357
|
+
* The default locale of your website/application. This is a required field.
|
|
1358
|
+
*/
|
|
1359
|
+
defaultLocale: string;
|
|
1360
|
+
/**
|
|
1361
|
+
* @docs
|
|
1362
|
+
* @name experimental.i18n.locales
|
|
1363
|
+
* @type {string[]}
|
|
1364
|
+
* @version 3.5.0
|
|
1365
|
+
* @description
|
|
1366
|
+
*
|
|
1367
|
+
* A list of all locales supported by the website (e.g. `['en', 'es', 'pt_BR']`). This list should also include the `defaultLocale`. This is a required field.
|
|
1368
|
+
*
|
|
1369
|
+
* No particular language format or syntax is enforced, but your folder structure must match exactly the locales in the list.
|
|
1370
|
+
*/
|
|
1371
|
+
locales: string[];
|
|
1372
|
+
/**
|
|
1373
|
+
* @docs
|
|
1374
|
+
* @name experimental.i18n.fallback
|
|
1375
|
+
* @type {Record<string, string>}
|
|
1376
|
+
* @version 3.5.0
|
|
1377
|
+
* @description
|
|
1378
|
+
*
|
|
1379
|
+
* The fallback strategy when navigating to pages that do not exist (e.g. a translated page has not been created).
|
|
1380
|
+
*
|
|
1381
|
+
* Use this object to declare a fallback `locale` route for each language you support. If no fallback is specified, then unavailable pages will return a 404.
|
|
1382
|
+
*
|
|
1383
|
+
* #### Example
|
|
1384
|
+
*
|
|
1385
|
+
* The following example configures your content fallback strategy to redirect unavailable pages in `/pt/` to their `es` version, and unavailable pages in `/fr/` to their `en` version. Unavailable `/es/` pages will return a 404.
|
|
1386
|
+
*
|
|
1387
|
+
* ```js
|
|
1388
|
+
* export defualt defineConfig({
|
|
1389
|
+
* experimental: {
|
|
1390
|
+
* i18n: {
|
|
1391
|
+
* defaultLocale: "en",
|
|
1392
|
+
* locales: ["en", "fr", "pt", "es"],
|
|
1393
|
+
* fallback: {
|
|
1394
|
+
* pt: "es",
|
|
1395
|
+
* fr: "en"
|
|
1396
|
+
* }
|
|
1397
|
+
* }
|
|
1398
|
+
* }
|
|
1399
|
+
* })
|
|
1400
|
+
* ```
|
|
1401
|
+
*/
|
|
1402
|
+
fallback?: Record<string, string>;
|
|
1403
|
+
/**
|
|
1404
|
+
* @docs
|
|
1405
|
+
* @name experimental.i18n.routingStrategy
|
|
1406
|
+
* @type {'prefix-always' | 'prefix-other-locales'}
|
|
1407
|
+
* @default 'prefix-other-locales'
|
|
1408
|
+
* @version 3.5.0
|
|
1409
|
+
* @description
|
|
1410
|
+
*
|
|
1411
|
+
* Controls the routing strategy to determine your site URLs.
|
|
1412
|
+
*
|
|
1413
|
+
* - `prefix-other-locales`(default): Only non-default languages will display a language prefix. The `defaultLocale` will not show a language prefix.
|
|
1414
|
+
* URLs will be of the form `example.com/[lang]/content/` for all non-default languages, but `example.com/content/` for the default locale.
|
|
1415
|
+
* - `prefix-always`: All URLs will display a language prefix.
|
|
1416
|
+
* URLs will be of the form `example.com/[lang]/content/` for every route, including the default language.
|
|
1417
|
+
*
|
|
1418
|
+
* Note: Astro requires all content to exist within a `/[lang]/` folder, even for the default language.
|
|
1419
|
+
*/
|
|
1420
|
+
routingStrategy?: 'prefix-always' | 'prefix-other-locales';
|
|
1421
|
+
};
|
|
1422
|
+
/**
|
|
1423
|
+
* @docs
|
|
1424
|
+
* @name experimental.contentCollectionCache
|
|
1425
|
+
* @type {boolean}
|
|
1426
|
+
* @default `false`
|
|
1427
|
+
* @version 3.5.0
|
|
1428
|
+
* @description
|
|
1429
|
+
* Enables a persistent cache for content collections when building in static mode.
|
|
1430
|
+
*
|
|
1431
|
+
* ```js
|
|
1432
|
+
* {
|
|
1433
|
+
* experimental: {
|
|
1434
|
+
* contentCollectionCache: true,
|
|
1435
|
+
* },
|
|
1436
|
+
* }
|
|
1437
|
+
* ```
|
|
1438
|
+
*/
|
|
1439
|
+
contentCollectionCache?: boolean;
|
|
1278
1440
|
};
|
|
1279
1441
|
}
|
|
1280
1442
|
/**
|
|
@@ -1332,10 +1494,6 @@ export interface AstroInlineOnlyConfig {
|
|
|
1332
1494
|
* @default "info"
|
|
1333
1495
|
*/
|
|
1334
1496
|
logLevel?: LoggerLevel;
|
|
1335
|
-
/**
|
|
1336
|
-
* @internal for testing only, use `logLevel` instead.
|
|
1337
|
-
*/
|
|
1338
|
-
logger?: Logger;
|
|
1339
1497
|
}
|
|
1340
1498
|
export type ContentEntryModule = {
|
|
1341
1499
|
id: string;
|
|
@@ -1426,6 +1584,10 @@ export interface AstroSettings {
|
|
|
1426
1584
|
*/
|
|
1427
1585
|
clientDirectives: Map<string, string>;
|
|
1428
1586
|
devOverlayPlugins: string[];
|
|
1587
|
+
middlewares: {
|
|
1588
|
+
pre: string[];
|
|
1589
|
+
post: string[];
|
|
1590
|
+
};
|
|
1429
1591
|
tsConfig: TSConfig | undefined;
|
|
1430
1592
|
tsConfigPath: string | undefined;
|
|
1431
1593
|
watchFiles: string[];
|
|
@@ -1651,6 +1813,10 @@ export type AstroFeatureMap = {
|
|
|
1651
1813
|
* The adapter can emit static assets
|
|
1652
1814
|
*/
|
|
1653
1815
|
assets?: AstroAssetsFeature;
|
|
1816
|
+
/**
|
|
1817
|
+
* List of features that orbit around the i18n routing
|
|
1818
|
+
*/
|
|
1819
|
+
i18n?: AstroInternationalizationFeature;
|
|
1654
1820
|
};
|
|
1655
1821
|
export interface AstroAssetsFeature {
|
|
1656
1822
|
supportKind?: SupportsKind;
|
|
@@ -1663,6 +1829,12 @@ export interface AstroAssetsFeature {
|
|
|
1663
1829
|
*/
|
|
1664
1830
|
isSquooshCompatible?: boolean;
|
|
1665
1831
|
}
|
|
1832
|
+
export interface AstroInternationalizationFeature {
|
|
1833
|
+
/**
|
|
1834
|
+
* Whether the adapter is able to detect the language of the browser, usually using the `Accept-Language` header.
|
|
1835
|
+
*/
|
|
1836
|
+
detectBrowserLanguage?: SupportsKind;
|
|
1837
|
+
}
|
|
1666
1838
|
export interface AstroAdapter {
|
|
1667
1839
|
name: string;
|
|
1668
1840
|
serverEntrypoint?: string;
|
|
@@ -1712,6 +1884,14 @@ interface AstroSharedContext<Props extends Record<string, any> = Record<string,
|
|
|
1712
1884
|
* Object accessed via Astro middleware
|
|
1713
1885
|
*/
|
|
1714
1886
|
locals: App.Locals;
|
|
1887
|
+
/**
|
|
1888
|
+
* The current locale that is computed from the `Accept-Language` header of the browser (**SSR Only**).
|
|
1889
|
+
*/
|
|
1890
|
+
preferredLocale: string | undefined;
|
|
1891
|
+
/**
|
|
1892
|
+
* The list of locales computed from the `Accept-Language` header of the browser, sorted by quality value (**SSR Only**).
|
|
1893
|
+
*/
|
|
1894
|
+
preferredLocaleList: string[] | undefined;
|
|
1715
1895
|
}
|
|
1716
1896
|
export interface APIContext<Props extends Record<string, any> = Record<string, any>, APIParams extends Record<string, string | undefined> = Record<string, string | undefined>> extends AstroSharedContext<Props, Params> {
|
|
1717
1897
|
site: URL | undefined;
|
|
@@ -1808,6 +1988,32 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
|
|
|
1808
1988
|
*/
|
|
1809
1989
|
locals: App.Locals;
|
|
1810
1990
|
ResponseWithEncoding: typeof ResponseWithEncoding;
|
|
1991
|
+
/**
|
|
1992
|
+
* Available only when `experimental.i18n` enabled and in SSR.
|
|
1993
|
+
*
|
|
1994
|
+
* It represents the preferred locale of the user. It's computed by checking the supported locales in `i18n.locales`
|
|
1995
|
+
* and locales supported by the users's browser via the header `Accept-Language`
|
|
1996
|
+
*
|
|
1997
|
+
* For example, given `i18n.locales` equals to `['fr', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the
|
|
1998
|
+
* `Astro.preferredLanguage` will be `fr` because `en` is not supported, its [quality value] is the highest.
|
|
1999
|
+
*
|
|
2000
|
+
* [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
|
|
2001
|
+
*/
|
|
2002
|
+
preferredLocale: string | undefined;
|
|
2003
|
+
/**
|
|
2004
|
+
* Available only when `experimental.i18n` enabled and in SSR.
|
|
2005
|
+
*
|
|
2006
|
+
* It represents the list of the preferred locales that are supported by the application. The list is sorted via [quality value].
|
|
2007
|
+
*
|
|
2008
|
+
* For example, given `i18n.locales` equals to `['fr', 'pt', 'de']`, and the `Accept-Language` value equals to `en, de;q=0.2, fr;q=0.6`, the
|
|
2009
|
+
* `Astro.preferredLocaleList` will be equal to `['fs', 'de']` because `en` isn't supported, and `pt` isn't part of the locales contained in the
|
|
2010
|
+
* header.
|
|
2011
|
+
*
|
|
2012
|
+
* When the `Accept-Header` is `*`, the original `i18n.locales` are returned. The value `*` means no preferences, so Astro returns all the supported locales.
|
|
2013
|
+
*
|
|
2014
|
+
* [quality value]: https://developer.mozilla.org/en-US/docs/Glossary/Quality_values
|
|
2015
|
+
*/
|
|
2016
|
+
preferredLocaleList: string[] | undefined;
|
|
1811
2017
|
}
|
|
1812
2018
|
export type EndpointOutput = {
|
|
1813
2019
|
body: Body;
|
|
@@ -1860,6 +2066,7 @@ export interface AstroIntegration {
|
|
|
1860
2066
|
injectRoute: (injectRoute: InjectedRoute) => void;
|
|
1861
2067
|
addClientDirective: (directive: ClientDirectiveConfig) => void;
|
|
1862
2068
|
addDevOverlayPlugin: (entrypoint: string) => void;
|
|
2069
|
+
addMiddleware: (mid: AstroIntegrationMiddleware) => void;
|
|
1863
2070
|
logger: AstroIntegrationLogger;
|
|
1864
2071
|
}) => void | Promise<void>;
|
|
1865
2072
|
'astro:config:done'?: (options: {
|
|
@@ -1923,11 +2130,21 @@ export type MiddlewareNextResponse = MiddlewareNext<Response>;
|
|
|
1923
2130
|
export type AstroMiddlewareInstance<R> = {
|
|
1924
2131
|
onRequest?: MiddlewareHandler<R>;
|
|
1925
2132
|
};
|
|
2133
|
+
export type AstroIntegrationMiddleware = {
|
|
2134
|
+
order: 'pre' | 'post';
|
|
2135
|
+
entrypoint: string;
|
|
2136
|
+
};
|
|
1926
2137
|
export interface AstroPluginOptions {
|
|
1927
2138
|
settings: AstroSettings;
|
|
1928
2139
|
logger: Logger;
|
|
1929
2140
|
}
|
|
1930
|
-
|
|
2141
|
+
/**
|
|
2142
|
+
* - page: a route that lives in the file system, usually an Astro component
|
|
2143
|
+
* - endpoint: a route that lives in the file system, usually a JS file that exposes endpoints methods
|
|
2144
|
+
* - redirect: a route points to another route that lives in the file system
|
|
2145
|
+
* - fallback: a route that doesn't exist in the file system that needs to be handled with other means, usually the middleware
|
|
2146
|
+
*/
|
|
2147
|
+
export type RouteType = 'page' | 'endpoint' | 'redirect' | 'fallback';
|
|
1931
2148
|
export interface RoutePart {
|
|
1932
2149
|
content: string;
|
|
1933
2150
|
dynamic: boolean;
|
|
@@ -6,6 +6,7 @@ import type { MapValue } from '../../type-utils.js';
|
|
|
6
6
|
import type { AssetsGlobalStaticImagesList } from '../types.js';
|
|
7
7
|
type AssetEnv = {
|
|
8
8
|
logger: Logger;
|
|
9
|
+
isSSR: boolean;
|
|
9
10
|
count: {
|
|
10
11
|
total: number;
|
|
11
12
|
current: number;
|
|
@@ -18,6 +19,6 @@ type AssetEnv = {
|
|
|
18
19
|
assetsFolder: AstroConfig['build']['assets'];
|
|
19
20
|
};
|
|
20
21
|
export declare function prepareAssetsGenerationEnv(pipeline: BuildPipeline, totalCount: number): Promise<AssetEnv>;
|
|
21
|
-
export declare function generateImagesForPath(originalFilePath: string,
|
|
22
|
+
export declare function generateImagesForPath(originalFilePath: string, transformsAndPath: MapValue<AssetsGlobalStaticImagesList>, env: AssetEnv, queue: PQueue): Promise<void>;
|
|
22
23
|
export declare function getStaticImageList(): AssetsGlobalStaticImagesList;
|
|
23
24
|
export {};
|
|
@@ -33,6 +33,7 @@ async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
|
33
33
|
}
|
|
34
34
|
return {
|
|
35
35
|
logger,
|
|
36
|
+
isSSR: isServerLikeOutput(config),
|
|
36
37
|
count,
|
|
37
38
|
useCache,
|
|
38
39
|
assetsCacheDir,
|
|
@@ -42,13 +43,25 @@ async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
|
42
43
|
assetsFolder: config.build.assets
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
function getFullImagePath(originalFilePath, env) {
|
|
47
|
+
return new URL(
|
|
48
|
+
"." + prependForwardSlash(join(env.assetsFolder, basename(originalFilePath))),
|
|
49
|
+
env.serverRoot
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
async function generateImagesForPath(originalFilePath, transformsAndPath, env, queue) {
|
|
46
53
|
const originalImageData = await loadImage(originalFilePath, env);
|
|
47
|
-
for (const [_, transform] of transforms) {
|
|
54
|
+
for (const [_, transform] of transformsAndPath.transforms) {
|
|
48
55
|
queue.add(
|
|
49
56
|
async () => generateImage(originalImageData, transform.finalPath, transform.transform)
|
|
50
57
|
);
|
|
51
58
|
}
|
|
59
|
+
if (!env.isSSR && !isRemotePath(originalFilePath) && !globalThis.astroAsset.referencedImages?.has(transformsAndPath.originalSrcPath)) {
|
|
60
|
+
try {
|
|
61
|
+
await fs.promises.unlink(getFullImagePath(originalFilePath, env));
|
|
62
|
+
} catch (e) {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
52
65
|
async function generateImage(originalImage, filepath, options) {
|
|
53
66
|
const timeStart = performance.now();
|
|
54
67
|
const generationData = await generateImageInternal(originalImage, filepath, options);
|
|
@@ -156,9 +169,7 @@ async function loadImage(path, env) {
|
|
|
156
169
|
};
|
|
157
170
|
}
|
|
158
171
|
return {
|
|
159
|
-
data: await fs.promises.readFile(
|
|
160
|
-
new URL("." + prependForwardSlash(join(env.assetsFolder, basename(path))), env.serverRoot)
|
|
161
|
-
),
|
|
172
|
+
data: await fs.promises.readFile(getFullImagePath(path, env)),
|
|
162
173
|
expires: 0
|
|
163
174
|
};
|
|
164
175
|
}
|
package/dist/assets/consts.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare const VALID_INPUT_FORMATS: readonly ["jpeg", "jpg", "png", "tiff"
|
|
|
8
8
|
export declare const VALID_SUPPORTED_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif", "svg", "avif"];
|
|
9
9
|
export declare const DEFAULT_OUTPUT_FORMAT: "webp";
|
|
10
10
|
export declare const VALID_OUTPUT_FORMATS: readonly ["avif", "png", "webp", "jpeg", "jpg", "svg"];
|
|
11
|
+
export declare const DEFAULT_HASH_PROPS: string[];
|