astro 3.6.3 → 3.6.5
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/dist/@types/astro.d.ts +33 -14
- package/dist/assets/endpoint/node.js +40 -9
- package/dist/assets/vite-plugin-assets.js +2 -1
- package/dist/core/app/index.js +2 -2
- package/dist/core/app/types.d.ts +1 -1
- package/dist/core/build/generate.js +2 -2
- package/dist/core/build/plugins/plugin-manifest.js +1 -1
- package/dist/core/config/schema.d.ts +76 -22
- package/dist/core/config/schema.js +16 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/pipeline.js +1 -1
- package/dist/core/render/context.d.ts +1 -1
- package/dist/core/render/context.js +1 -1
- package/dist/core/render/core.js +2 -2
- package/dist/core/routing/manifest/create.js +1 -1
- package/dist/i18n/middleware.js +3 -3
- package/dist/runtime/server/render/page.js +1 -1
- package/dist/vite-plugin-astro/hmr.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +2 -2
- package/package.json +3 -3
package/dist/@types/astro.d.ts
CHANGED
|
@@ -1412,23 +1412,42 @@ export interface AstroUserConfig {
|
|
|
1412
1412
|
/**
|
|
1413
1413
|
* @docs
|
|
1414
1414
|
* @kind h4
|
|
1415
|
-
* @name experimental.i18n.
|
|
1416
|
-
* @type {
|
|
1417
|
-
* @
|
|
1418
|
-
* @version 3.5.0
|
|
1415
|
+
* @name experimental.i18n.routing
|
|
1416
|
+
* @type {Routing}
|
|
1417
|
+
* @version 3.7.0
|
|
1419
1418
|
* @description
|
|
1420
1419
|
*
|
|
1421
|
-
* Controls the routing strategy to determine your site URLs. Set this based on your folder/URL path configuration for your default language
|
|
1422
|
-
*
|
|
1423
|
-
* - `prefix-other-locales`(default): Only non-default languages will display a language prefix.
|
|
1424
|
-
* The `defaultLocale` will not show a language prefix and content files do not exist in a localized folder.
|
|
1425
|
-
* URLs will be of the form `example.com/[locale]/content/` for all non-default languages, but `example.com/content/` for the default locale.
|
|
1426
|
-
* - `prefix-always`: All URLs will display a language prefix.
|
|
1427
|
-
* URLs will be of the form `example.com/[locale]/content/` for every route, including the default language.
|
|
1428
|
-
* Localized folders are used for every language, including the default.
|
|
1429
|
-
*
|
|
1420
|
+
* Controls the routing strategy to determine your site URLs. Set this based on your folder/URL path configuration for your default language.
|
|
1430
1421
|
*/
|
|
1431
|
-
|
|
1422
|
+
routing?: {
|
|
1423
|
+
/**
|
|
1424
|
+
* @docs
|
|
1425
|
+
* @name experimental.i18n.routing.prefixDefaultLocale
|
|
1426
|
+
* @type {boolean}
|
|
1427
|
+
* @default `false`
|
|
1428
|
+
* @version 3.7.0
|
|
1429
|
+
* @description
|
|
1430
|
+
*
|
|
1431
|
+
* When `false`, only non-default languages will display a language prefix.
|
|
1432
|
+
* The `defaultLocale` will not show a language prefix and content files do not exist in a localized folder.
|
|
1433
|
+
* URLs will be of the form `example.com/[locale]/content/` for all non-default languages, but `example.com/content/` for the default locale.
|
|
1434
|
+
*
|
|
1435
|
+
* When `true`, all URLs will display a language prefix.
|
|
1436
|
+
* URLs will be of the form `example.com/[locale]/content/` for every route, including the default language.
|
|
1437
|
+
* Localized folders are used for every language, including the default.
|
|
1438
|
+
*/
|
|
1439
|
+
prefixDefaultLocale: boolean;
|
|
1440
|
+
/**
|
|
1441
|
+
* @name experimental.i18n.routing.strategy
|
|
1442
|
+
* @type {"pathname"}
|
|
1443
|
+
* @default `"pathname"`
|
|
1444
|
+
* @version 3.7.0
|
|
1445
|
+
* @description
|
|
1446
|
+
*
|
|
1447
|
+
* - `"pathanme": The strategy is applied to the pathname of the URLs
|
|
1448
|
+
*/
|
|
1449
|
+
strategy: 'pathname';
|
|
1450
|
+
};
|
|
1432
1451
|
};
|
|
1433
1452
|
/**
|
|
1434
1453
|
* @docs
|
|
@@ -1,21 +1,42 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
1
4
|
import { isRemotePath, removeQueryString } from "@astrojs/internal-helpers/path";
|
|
2
5
|
import { readFile } from "fs/promises";
|
|
3
6
|
import mime from "mime/lite.js";
|
|
4
|
-
import os from "os";
|
|
5
7
|
import { getConfiguredImageService, isRemoteAllowed } from "../internal.js";
|
|
6
8
|
import { etag } from "../utils/etag.js";
|
|
7
|
-
import { assetsDir, imageConfig } from "astro:assets";
|
|
9
|
+
import { assetsDir, outDir, imageConfig } from "astro:assets";
|
|
8
10
|
function replaceFileSystemReferences(src) {
|
|
9
11
|
return os.platform().includes("win32") ? src.replace(/^\/@fs\//, "") : src.replace(/^\/@fs/, "");
|
|
10
12
|
}
|
|
11
13
|
async function loadLocalImage(src, url) {
|
|
12
|
-
const
|
|
14
|
+
const assetsDirPath = fileURLToPath(assetsDir);
|
|
15
|
+
let fileUrl;
|
|
16
|
+
if (import.meta.env.DEV) {
|
|
17
|
+
fileUrl = pathToFileURL(removeQueryString(replaceFileSystemReferences(src)));
|
|
18
|
+
} else {
|
|
19
|
+
try {
|
|
20
|
+
fileUrl = new URL("." + src, outDir);
|
|
21
|
+
const filePath = fileURLToPath(fileUrl);
|
|
22
|
+
if (!isAbsolute(filePath) || !filePath.startsWith(assetsDirPath)) {
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
} catch (err) {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
13
29
|
let buffer = void 0;
|
|
14
30
|
try {
|
|
15
|
-
buffer = await readFile(
|
|
31
|
+
buffer = await readFile(fileUrl);
|
|
16
32
|
} catch (e) {
|
|
17
|
-
|
|
18
|
-
|
|
33
|
+
try {
|
|
34
|
+
const sourceUrl = new URL(src, url.origin);
|
|
35
|
+
buffer = await loadRemoteImage(sourceUrl);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error("Could not process image request:", err);
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
19
40
|
}
|
|
20
41
|
return buffer;
|
|
21
42
|
}
|
|
@@ -39,7 +60,11 @@ const GET = async ({ request }) => {
|
|
|
39
60
|
const url = new URL(request.url);
|
|
40
61
|
const transform = await imageService.parseURL(url, imageConfig);
|
|
41
62
|
if (!transform?.src) {
|
|
42
|
-
|
|
63
|
+
const err = new Error(
|
|
64
|
+
"Incorrect transform returned by `parseURL`. Expected a transform with a `src` property."
|
|
65
|
+
);
|
|
66
|
+
console.error("Could not parse image transform from URL:", err);
|
|
67
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
43
68
|
}
|
|
44
69
|
let inputBuffer = void 0;
|
|
45
70
|
if (isRemotePath(transform.src)) {
|
|
@@ -51,7 +76,7 @@ const GET = async ({ request }) => {
|
|
|
51
76
|
inputBuffer = await loadLocalImage(transform.src, url);
|
|
52
77
|
}
|
|
53
78
|
if (!inputBuffer) {
|
|
54
|
-
return new Response("
|
|
79
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
55
80
|
}
|
|
56
81
|
const { data, format } = await imageService.transform(inputBuffer, transform, imageConfig);
|
|
57
82
|
return new Response(data, {
|
|
@@ -64,7 +89,13 @@ const GET = async ({ request }) => {
|
|
|
64
89
|
}
|
|
65
90
|
});
|
|
66
91
|
} catch (err) {
|
|
67
|
-
|
|
92
|
+
console.error("Could not process image request:", err);
|
|
93
|
+
return new Response(
|
|
94
|
+
import.meta.env.DEV ? `Could not process image request: ${err}` : `Internal Server Error`,
|
|
95
|
+
{
|
|
96
|
+
status: 500
|
|
97
|
+
}
|
|
98
|
+
);
|
|
68
99
|
}
|
|
69
100
|
};
|
|
70
101
|
export {
|
|
@@ -54,11 +54,12 @@ function assets({
|
|
|
54
54
|
export { default as Picture } from "astro/components/Picture.astro";
|
|
55
55
|
|
|
56
56
|
export const imageConfig = ${JSON.stringify(settings.config.image)};
|
|
57
|
-
export const
|
|
57
|
+
export const outDir = new URL(${JSON.stringify(
|
|
58
58
|
new URL(
|
|
59
59
|
isServerLikeOutput(settings.config) ? settings.config.build.client : settings.config.outDir
|
|
60
60
|
)
|
|
61
61
|
)});
|
|
62
|
+
export const assetsDir = new URL(${JSON.stringify(settings.config.build.assets)}, outDir);
|
|
62
63
|
export const getImage = async (options) => await getImageInternal(options, imageConfig);
|
|
63
64
|
`;
|
|
64
65
|
}
|
package/dist/core/app/index.js
CHANGED
|
@@ -195,7 +195,7 @@ class App {
|
|
|
195
195
|
env: this.#pipeline.env,
|
|
196
196
|
mod: handler,
|
|
197
197
|
locales: this.#manifest.i18n?.locales,
|
|
198
|
-
|
|
198
|
+
routing: this.#manifest.i18n?.routing,
|
|
199
199
|
defaultLocale: this.#manifest.i18n?.defaultLocale
|
|
200
200
|
});
|
|
201
201
|
} else {
|
|
@@ -229,7 +229,7 @@ class App {
|
|
|
229
229
|
mod,
|
|
230
230
|
env: this.#pipeline.env,
|
|
231
231
|
locales: this.#manifest.i18n?.locales,
|
|
232
|
-
|
|
232
|
+
routing: this.#manifest.i18n?.routing,
|
|
233
233
|
defaultLocale: this.#manifest.i18n?.defaultLocale
|
|
234
234
|
});
|
|
235
235
|
}
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export type SSRManifest = {
|
|
|
47
47
|
};
|
|
48
48
|
export type SSRManifestI18n = {
|
|
49
49
|
fallback?: Record<string, string>;
|
|
50
|
-
|
|
50
|
+
routing?: 'prefix-always' | 'prefix-other-locales';
|
|
51
51
|
locales: string[];
|
|
52
52
|
defaultLocale: string;
|
|
53
53
|
};
|
|
@@ -431,7 +431,7 @@ async function generatePath(pathname, gopts, pipeline) {
|
|
|
431
431
|
env: pipeline.getEnvironment(),
|
|
432
432
|
mod,
|
|
433
433
|
locales: i18n?.locales,
|
|
434
|
-
|
|
434
|
+
routing: i18n?.routing,
|
|
435
435
|
defaultLocale: i18n?.defaultLocale
|
|
436
436
|
});
|
|
437
437
|
let body;
|
|
@@ -486,7 +486,7 @@ function createBuildManifest(settings, internals, renderers) {
|
|
|
486
486
|
if (settings.config.experimental.i18n) {
|
|
487
487
|
i18nManifest = {
|
|
488
488
|
fallback: settings.config.experimental.i18n.fallback,
|
|
489
|
-
|
|
489
|
+
routing: settings.config.experimental.i18n.routing,
|
|
490
490
|
defaultLocale: settings.config.experimental.i18n.defaultLocale,
|
|
491
491
|
locales: settings.config.experimental.i18n.locales
|
|
492
492
|
};
|
|
@@ -186,7 +186,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
186
186
|
if (settings.config.experimental.i18n) {
|
|
187
187
|
i18nManifest = {
|
|
188
188
|
fallback: settings.config.experimental.i18n.fallback,
|
|
189
|
-
|
|
189
|
+
routing: settings.config.experimental.i18n.routing,
|
|
190
190
|
locales: settings.config.experimental.i18n.locales,
|
|
191
191
|
defaultLocale: settings.config.experimental.i18n.defaultLocale
|
|
192
192
|
};
|
|
@@ -250,27 +250,45 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
250
250
|
defaultLocale: z.ZodString;
|
|
251
251
|
locales: z.ZodArray<z.ZodString, "many">;
|
|
252
252
|
fallback: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
253
|
-
|
|
253
|
+
routing: z.ZodEffects<z.ZodDefault<z.ZodObject<{
|
|
254
|
+
prefixDefaultLocale: z.ZodDefault<z.ZodBoolean>;
|
|
255
|
+
strategy: z.ZodDefault<z.ZodEnum<["pathname"]>>;
|
|
256
|
+
}, "strip", z.ZodTypeAny, {
|
|
257
|
+
prefixDefaultLocale: boolean;
|
|
258
|
+
strategy: "pathname";
|
|
259
|
+
}, {
|
|
260
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
261
|
+
strategy?: "pathname" | undefined;
|
|
262
|
+
}>>, "prefix-always" | "prefix-other-locales", {
|
|
263
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
264
|
+
strategy?: "pathname" | undefined;
|
|
265
|
+
} | undefined>;
|
|
254
266
|
}, "strip", z.ZodTypeAny, {
|
|
255
267
|
defaultLocale: string;
|
|
256
268
|
locales: string[];
|
|
257
|
-
|
|
269
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
258
270
|
fallback?: Record<string, string> | undefined;
|
|
259
271
|
}, {
|
|
260
272
|
defaultLocale: string;
|
|
261
273
|
locales: string[];
|
|
262
274
|
fallback?: Record<string, string> | undefined;
|
|
263
|
-
|
|
275
|
+
routing?: {
|
|
276
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
277
|
+
strategy?: "pathname" | undefined;
|
|
278
|
+
} | undefined;
|
|
264
279
|
}>>, {
|
|
265
280
|
defaultLocale: string;
|
|
266
281
|
locales: string[];
|
|
267
|
-
|
|
282
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
268
283
|
fallback?: Record<string, string> | undefined;
|
|
269
284
|
} | undefined, {
|
|
270
285
|
defaultLocale: string;
|
|
271
286
|
locales: string[];
|
|
272
287
|
fallback?: Record<string, string> | undefined;
|
|
273
|
-
|
|
288
|
+
routing?: {
|
|
289
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
290
|
+
strategy?: "pathname" | undefined;
|
|
291
|
+
} | undefined;
|
|
274
292
|
} | undefined>>;
|
|
275
293
|
contentCollectionCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
276
294
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -280,7 +298,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
280
298
|
i18n?: {
|
|
281
299
|
defaultLocale: string;
|
|
282
300
|
locales: string[];
|
|
283
|
-
|
|
301
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
284
302
|
fallback?: Record<string, string> | undefined;
|
|
285
303
|
} | undefined;
|
|
286
304
|
}, {
|
|
@@ -290,7 +308,10 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
290
308
|
defaultLocale: string;
|
|
291
309
|
locales: string[];
|
|
292
310
|
fallback?: Record<string, string> | undefined;
|
|
293
|
-
|
|
311
|
+
routing?: {
|
|
312
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
313
|
+
strategy?: "pathname" | undefined;
|
|
314
|
+
} | undefined;
|
|
294
315
|
} | undefined;
|
|
295
316
|
contentCollectionCache?: boolean | undefined;
|
|
296
317
|
}>>;
|
|
@@ -374,7 +395,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
374
395
|
i18n?: {
|
|
375
396
|
defaultLocale: string;
|
|
376
397
|
locales: string[];
|
|
377
|
-
|
|
398
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
378
399
|
fallback?: Record<string, string> | undefined;
|
|
379
400
|
} | undefined;
|
|
380
401
|
};
|
|
@@ -465,7 +486,10 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
465
486
|
defaultLocale: string;
|
|
466
487
|
locales: string[];
|
|
467
488
|
fallback?: Record<string, string> | undefined;
|
|
468
|
-
|
|
489
|
+
routing?: {
|
|
490
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
491
|
+
strategy?: "pathname" | undefined;
|
|
492
|
+
} | undefined;
|
|
469
493
|
} | undefined;
|
|
470
494
|
contentCollectionCache?: boolean | undefined;
|
|
471
495
|
} | undefined;
|
|
@@ -647,27 +671,45 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
647
671
|
defaultLocale: z.ZodString;
|
|
648
672
|
locales: z.ZodArray<z.ZodString, "many">;
|
|
649
673
|
fallback: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
650
|
-
|
|
674
|
+
routing: z.ZodEffects<z.ZodDefault<z.ZodObject<{
|
|
675
|
+
prefixDefaultLocale: z.ZodDefault<z.ZodBoolean>;
|
|
676
|
+
strategy: z.ZodDefault<z.ZodEnum<["pathname"]>>;
|
|
677
|
+
}, "strip", z.ZodTypeAny, {
|
|
678
|
+
prefixDefaultLocale: boolean;
|
|
679
|
+
strategy: "pathname";
|
|
680
|
+
}, {
|
|
681
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
682
|
+
strategy?: "pathname" | undefined;
|
|
683
|
+
}>>, "prefix-always" | "prefix-other-locales", {
|
|
684
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
685
|
+
strategy?: "pathname" | undefined;
|
|
686
|
+
} | undefined>;
|
|
651
687
|
}, "strip", z.ZodTypeAny, {
|
|
652
688
|
defaultLocale: string;
|
|
653
689
|
locales: string[];
|
|
654
|
-
|
|
690
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
655
691
|
fallback?: Record<string, string> | undefined;
|
|
656
692
|
}, {
|
|
657
693
|
defaultLocale: string;
|
|
658
694
|
locales: string[];
|
|
659
695
|
fallback?: Record<string, string> | undefined;
|
|
660
|
-
|
|
696
|
+
routing?: {
|
|
697
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
698
|
+
strategy?: "pathname" | undefined;
|
|
699
|
+
} | undefined;
|
|
661
700
|
}>>, {
|
|
662
701
|
defaultLocale: string;
|
|
663
702
|
locales: string[];
|
|
664
|
-
|
|
703
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
665
704
|
fallback?: Record<string, string> | undefined;
|
|
666
705
|
} | undefined, {
|
|
667
706
|
defaultLocale: string;
|
|
668
707
|
locales: string[];
|
|
669
708
|
fallback?: Record<string, string> | undefined;
|
|
670
|
-
|
|
709
|
+
routing?: {
|
|
710
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
711
|
+
strategy?: "pathname" | undefined;
|
|
712
|
+
} | undefined;
|
|
671
713
|
} | undefined>>;
|
|
672
714
|
contentCollectionCache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
673
715
|
}, "strict", z.ZodTypeAny, {
|
|
@@ -677,7 +719,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
677
719
|
i18n?: {
|
|
678
720
|
defaultLocale: string;
|
|
679
721
|
locales: string[];
|
|
680
|
-
|
|
722
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
681
723
|
fallback?: Record<string, string> | undefined;
|
|
682
724
|
} | undefined;
|
|
683
725
|
}, {
|
|
@@ -687,7 +729,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
687
729
|
defaultLocale: string;
|
|
688
730
|
locales: string[];
|
|
689
731
|
fallback?: Record<string, string> | undefined;
|
|
690
|
-
|
|
732
|
+
routing?: {
|
|
733
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
734
|
+
strategy?: "pathname" | undefined;
|
|
735
|
+
} | undefined;
|
|
691
736
|
} | undefined;
|
|
692
737
|
contentCollectionCache?: boolean | undefined;
|
|
693
738
|
}>>;
|
|
@@ -837,7 +882,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
837
882
|
i18n?: {
|
|
838
883
|
defaultLocale: string;
|
|
839
884
|
locales: string[];
|
|
840
|
-
|
|
885
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
841
886
|
fallback?: Record<string, string> | undefined;
|
|
842
887
|
} | undefined;
|
|
843
888
|
};
|
|
@@ -909,7 +954,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
909
954
|
defaultLocale: string;
|
|
910
955
|
locales: string[];
|
|
911
956
|
fallback?: Record<string, string> | undefined;
|
|
912
|
-
|
|
957
|
+
routing?: {
|
|
958
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
959
|
+
strategy?: "pathname" | undefined;
|
|
960
|
+
} | undefined;
|
|
913
961
|
} | undefined;
|
|
914
962
|
contentCollectionCache?: boolean | undefined;
|
|
915
963
|
} | undefined;
|
|
@@ -1013,7 +1061,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1013
1061
|
i18n?: {
|
|
1014
1062
|
defaultLocale: string;
|
|
1015
1063
|
locales: string[];
|
|
1016
|
-
|
|
1064
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
1017
1065
|
fallback?: Record<string, string> | undefined;
|
|
1018
1066
|
} | undefined;
|
|
1019
1067
|
};
|
|
@@ -1085,7 +1133,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1085
1133
|
defaultLocale: string;
|
|
1086
1134
|
locales: string[];
|
|
1087
1135
|
fallback?: Record<string, string> | undefined;
|
|
1088
|
-
|
|
1136
|
+
routing?: {
|
|
1137
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
1138
|
+
strategy?: "pathname" | undefined;
|
|
1139
|
+
} | undefined;
|
|
1089
1140
|
} | undefined;
|
|
1090
1141
|
contentCollectionCache?: boolean | undefined;
|
|
1091
1142
|
} | undefined;
|
|
@@ -1189,7 +1240,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1189
1240
|
i18n?: {
|
|
1190
1241
|
defaultLocale: string;
|
|
1191
1242
|
locales: string[];
|
|
1192
|
-
|
|
1243
|
+
routing: "prefix-always" | "prefix-other-locales";
|
|
1193
1244
|
fallback?: Record<string, string> | undefined;
|
|
1194
1245
|
} | undefined;
|
|
1195
1246
|
};
|
|
@@ -1261,7 +1312,10 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1261
1312
|
defaultLocale: string;
|
|
1262
1313
|
locales: string[];
|
|
1263
1314
|
fallback?: Record<string, string> | undefined;
|
|
1264
|
-
|
|
1315
|
+
routing?: {
|
|
1316
|
+
prefixDefaultLocale?: boolean | undefined;
|
|
1317
|
+
strategy?: "pathname" | undefined;
|
|
1318
|
+
} | undefined;
|
|
1265
1319
|
} | undefined;
|
|
1266
1320
|
contentCollectionCache?: boolean | undefined;
|
|
1267
1321
|
} | undefined;
|
|
@@ -214,8 +214,22 @@ const AstroConfigSchema = z.object({
|
|
|
214
214
|
defaultLocale: z.string(),
|
|
215
215
|
locales: z.string().array(),
|
|
216
216
|
fallback: z.record(z.string(), z.string()).optional(),
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
routing: z.object({
|
|
218
|
+
prefixDefaultLocale: z.boolean().default(false),
|
|
219
|
+
strategy: z.enum(["pathname"]).default("pathname")
|
|
220
|
+
}).default({}).transform((routing) => {
|
|
221
|
+
let strategy;
|
|
222
|
+
switch (routing.strategy) {
|
|
223
|
+
case "pathname": {
|
|
224
|
+
if (routing.prefixDefaultLocale === true) {
|
|
225
|
+
strategy = "prefix-always";
|
|
226
|
+
} else {
|
|
227
|
+
strategy = "prefix-other-locales";
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return strategy;
|
|
232
|
+
})
|
|
219
233
|
}).optional().superRefine((i18n, ctx) => {
|
|
220
234
|
if (i18n) {
|
|
221
235
|
const { defaultLocale, locales, fallback } = i18n;
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -20,7 +20,7 @@ async function dev(inlineConfig) {
|
|
|
20
20
|
base: restart.container.settings.config.base
|
|
21
21
|
})
|
|
22
22
|
);
|
|
23
|
-
const currentVersion = "3.6.
|
|
23
|
+
const currentVersion = "3.6.5";
|
|
24
24
|
if (currentVersion.includes("-")) {
|
|
25
25
|
logger.warn(null, msg.prerelease({ currentVersion }));
|
|
26
26
|
}
|
|
@@ -129,7 +129,7 @@ async function callEndpoint(mod, env, ctx, onRequest) {
|
|
|
129
129
|
props: ctx.props,
|
|
130
130
|
site: env.site,
|
|
131
131
|
adapterName: env.adapterName,
|
|
132
|
-
routingStrategy: ctx.
|
|
132
|
+
routingStrategy: ctx.routing,
|
|
133
133
|
defaultLocale: ctx.defaultLocale,
|
|
134
134
|
locales: ctx.locales
|
|
135
135
|
});
|
package/dist/core/messages.js
CHANGED
|
@@ -50,7 +50,7 @@ function serverStart({
|
|
|
50
50
|
base,
|
|
51
51
|
isRestart = false
|
|
52
52
|
}) {
|
|
53
|
-
const version = "3.6.
|
|
53
|
+
const version = "3.6.5";
|
|
54
54
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
55
55
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
56
56
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -235,7 +235,7 @@ function printHelp({
|
|
|
235
235
|
message.push(
|
|
236
236
|
linebreak(),
|
|
237
237
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
238
|
-
`v${"3.6.
|
|
238
|
+
`v${"3.6.5"}`
|
|
239
239
|
)} ${headline}`
|
|
240
240
|
);
|
|
241
241
|
}
|
package/dist/core/pipeline.js
CHANGED
|
@@ -90,7 +90,7 @@ class Pipeline {
|
|
|
90
90
|
site: env.site,
|
|
91
91
|
adapterName: env.adapterName,
|
|
92
92
|
locales: renderContext.locales,
|
|
93
|
-
routingStrategy: renderContext.
|
|
93
|
+
routingStrategy: renderContext.routing,
|
|
94
94
|
defaultLocale: renderContext.defaultLocale
|
|
95
95
|
});
|
|
96
96
|
switch (renderContext.route.type) {
|
|
@@ -17,7 +17,7 @@ export interface RenderContext {
|
|
|
17
17
|
locals?: object;
|
|
18
18
|
locales: string[] | undefined;
|
|
19
19
|
defaultLocale: string | undefined;
|
|
20
|
-
|
|
20
|
+
routing: 'prefix-always' | 'prefix-other-locales' | undefined;
|
|
21
21
|
}
|
|
22
22
|
export type CreateRenderContextArgs = Partial<Omit<RenderContext, 'params' | 'props' | 'locals'>> & {
|
|
23
23
|
route: RouteData;
|
|
@@ -19,7 +19,7 @@ async function createRenderContext(options) {
|
|
|
19
19
|
params,
|
|
20
20
|
props,
|
|
21
21
|
locales: options.locales,
|
|
22
|
-
|
|
22
|
+
routing: options.routing,
|
|
23
23
|
defaultLocale: options.defaultLocale
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(context, "locals", {
|
package/dist/core/render/core.js
CHANGED
|
@@ -45,7 +45,7 @@ async function renderPage({ mod, renderContext, env, cookies }) {
|
|
|
45
45
|
locals: renderContext.locals ?? {},
|
|
46
46
|
locales: renderContext.locales,
|
|
47
47
|
defaultLocale: renderContext.defaultLocale,
|
|
48
|
-
routingStrategy: renderContext.
|
|
48
|
+
routingStrategy: renderContext.routing
|
|
49
49
|
});
|
|
50
50
|
if (mod.frontmatter && typeof mod.frontmatter === "object" && "draft" in mod.frontmatter) {
|
|
51
51
|
env.logger.warn(
|
|
@@ -57,7 +57,7 @@ async function renderPage({ mod, renderContext, env, cookies }) {
|
|
|
57
57
|
result,
|
|
58
58
|
Component,
|
|
59
59
|
renderContext.props,
|
|
60
|
-
|
|
60
|
+
{},
|
|
61
61
|
env.streaming,
|
|
62
62
|
renderContext.route
|
|
63
63
|
);
|
|
@@ -367,7 +367,7 @@ This route collides with: "${collision.component}".`
|
|
|
367
367
|
}
|
|
368
368
|
setRoutes.delete(route);
|
|
369
369
|
}
|
|
370
|
-
if (i18n.
|
|
370
|
+
if (i18n.routing === "prefix-always") {
|
|
371
371
|
const defaultLocaleRoutes = routesByLocale.get(i18n.defaultLocale);
|
|
372
372
|
if (defaultLocaleRoutes) {
|
|
373
373
|
const indexDefaultRoute = defaultLocaleRoutes.find((routeData) => {
|
package/dist/i18n/middleware.js
CHANGED
|
@@ -29,14 +29,14 @@ function createI18nMiddleware(i18n, base, trailingSlash) {
|
|
|
29
29
|
const separators = url.pathname.split("/");
|
|
30
30
|
const pathnameContainsDefaultLocale = url.pathname.includes(`/${defaultLocale}`);
|
|
31
31
|
const isLocaleFree = checkIsLocaleFree(url.pathname, i18n.locales);
|
|
32
|
-
if (i18n.
|
|
32
|
+
if (i18n.routing === "prefix-other-locales" && pathnameContainsDefaultLocale) {
|
|
33
33
|
const newLocation = url.pathname.replace(`/${defaultLocale}`, "");
|
|
34
34
|
response.headers.set("Location", newLocation);
|
|
35
35
|
return new Response(null, {
|
|
36
36
|
status: 404,
|
|
37
37
|
headers: response.headers
|
|
38
38
|
});
|
|
39
|
-
} else if (i18n.
|
|
39
|
+
} else if (i18n.routing === "prefix-always") {
|
|
40
40
|
if (url.pathname === base + "/" || url.pathname === base) {
|
|
41
41
|
if (trailingSlash === "always") {
|
|
42
42
|
return context.redirect(`${appendForwardSlash(joinPaths(base, i18n.defaultLocale))}`);
|
|
@@ -56,7 +56,7 @@ function createI18nMiddleware(i18n, base, trailingSlash) {
|
|
|
56
56
|
if (urlLocale && fallbackKeys.includes(urlLocale)) {
|
|
57
57
|
const fallbackLocale = fallback[urlLocale];
|
|
58
58
|
let newPathname;
|
|
59
|
-
if (fallbackLocale === defaultLocale) {
|
|
59
|
+
if (fallbackLocale === defaultLocale && i18n.routing !== "prefix-always") {
|
|
60
60
|
newPathname = url.pathname.replace(`/${urlLocale}`, ``);
|
|
61
61
|
} else {
|
|
62
62
|
newPathname = url.pathname.replace(`/${urlLocale}`, `/${fallbackLocale}`);
|
|
@@ -59,7 +59,7 @@ async function handleHotUpdate(ctx, { config, logger, compile, source }) {
|
|
|
59
59
|
const file = ctx.file.replace(slash(fileURLToPath(config.root)), "/");
|
|
60
60
|
if (isStyleOnlyChange) {
|
|
61
61
|
logger.info("astro", msg.hmr({ file, style: true }));
|
|
62
|
-
return mods.filter((mod) => mod.id
|
|
62
|
+
return mods.filter((mod) => mod.id?.includes("astro&type=style"));
|
|
63
63
|
}
|
|
64
64
|
for (const mod of mods) {
|
|
65
65
|
for (const imp of mod.importedModules) {
|
|
@@ -63,7 +63,7 @@ function createDevelopmentManifest(settings) {
|
|
|
63
63
|
if (settings.config.experimental.i18n) {
|
|
64
64
|
i18nManifest = {
|
|
65
65
|
fallback: settings.config.experimental.i18n.fallback,
|
|
66
|
-
|
|
66
|
+
routing: settings.config.experimental.i18n.routing,
|
|
67
67
|
defaultLocale: settings.config.experimental.i18n.defaultLocale,
|
|
68
68
|
locales: settings.config.experimental.i18n.locales
|
|
69
69
|
};
|
|
@@ -149,7 +149,7 @@ async function handleRoute({
|
|
|
149
149
|
mod,
|
|
150
150
|
route,
|
|
151
151
|
locales: manifest.i18n?.locales,
|
|
152
|
-
|
|
152
|
+
routing: manifest.i18n?.routing,
|
|
153
153
|
defaultLocale: manifest.i18n?.defaultLocale
|
|
154
154
|
});
|
|
155
155
|
} else {
|
|
@@ -202,7 +202,7 @@ async function handleRoute({
|
|
|
202
202
|
mod,
|
|
203
203
|
env,
|
|
204
204
|
locales: i18n?.locales,
|
|
205
|
-
|
|
205
|
+
routing: i18n?.routing,
|
|
206
206
|
defaultLocale: i18n?.defaultLocale
|
|
207
207
|
});
|
|
208
208
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.5",
|
|
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",
|
|
@@ -167,8 +167,8 @@
|
|
|
167
167
|
"yargs-parser": "^21.1.1",
|
|
168
168
|
"zod": "^3.22.4",
|
|
169
169
|
"@astrojs/internal-helpers": "0.2.1",
|
|
170
|
-
"@astrojs/
|
|
171
|
-
"@astrojs/
|
|
170
|
+
"@astrojs/telemetry": "3.0.4",
|
|
171
|
+
"@astrojs/markdown-remark": "3.5.0"
|
|
172
172
|
},
|
|
173
173
|
"optionalDependencies": {
|
|
174
174
|
"sharp": "^0.32.5"
|