astro 4.2.6 → 4.2.8
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/content-types.template.d.ts +1 -1
- package/dist/assets/services/squoosh.js +2 -0
- package/dist/cli/add/index.js +2 -0
- package/dist/content/utils.d.ts +1 -1
- package/dist/content/utils.js +23 -11
- package/dist/core/app/types.d.ts +1 -1
- package/dist/core/build/generate.js +3 -2
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +3 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/context.js +7 -2
- package/dist/i18n/middleware.js +2 -1
- package/dist/i18n/vite-plugin-i18n.d.ts +2 -1
- package/dist/i18n/vite-plugin-i18n.js +9 -21
- package/dist/preferences/index.js +3 -0
- package/dist/runtime/client/dev-toolbar/apps/settings.js +3 -0
- package/dist/runtime/server/endpoint.js +3 -1
- package/dist/runtime/server/scripts.js +2 -0
- package/dist/virtual-modules/i18n.js +2 -2
- package/dist/vite-plugin-astro-server/response.js +1 -5
- package/dist/vite-plugin-markdown/content-entry-type.js +4 -3
- package/dist/vite-plugin-markdown/index.js +3 -26
- package/package.json +3 -3
package/dist/cli/add/index.js
CHANGED
|
@@ -180,6 +180,8 @@ async function add(names, { flags }) {
|
|
|
180
180
|
case 3 /* failure */: {
|
|
181
181
|
throw createPrettyError(new Error(`Unable to install dependencies`));
|
|
182
182
|
}
|
|
183
|
+
case 0 /* none */:
|
|
184
|
+
break;
|
|
183
185
|
}
|
|
184
186
|
const rawConfigPath = await resolveConfigPath({
|
|
185
187
|
root: rootPath,
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -119,7 +119,7 @@ export declare function getContentEntryIdAndSlug({ entry, contentDir, collection
|
|
|
119
119
|
};
|
|
120
120
|
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[], dataFileExts: string[]): 'content' | 'data' | 'config' | 'ignored';
|
|
121
121
|
export declare function hasUnderscoreBelowContentDirectoryPath(fileUrl: URL, contentDir: ContentPaths['contentDir']): boolean;
|
|
122
|
-
export declare function
|
|
122
|
+
export declare function safeParseFrontmatter(source: string, id?: string): matter.GrayMatterFile<string>;
|
|
123
123
|
/**
|
|
124
124
|
* The content config is loaded separately from other `src/` files.
|
|
125
125
|
* This global observable lets dependent plugins (like the content flag plugin)
|
package/dist/content/utils.js
CHANGED
|
@@ -6,7 +6,8 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
6
6
|
import { normalizePath } from "vite";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
|
-
import {
|
|
9
|
+
import { MarkdownError } from "../core/errors/index.js";
|
|
10
|
+
import { isYAMLException } from "../core/errors/utils.js";
|
|
10
11
|
import { CONTENT_FLAGS, CONTENT_TYPES_FILE } from "./consts.js";
|
|
11
12
|
import { errorMap } from "./error-map.js";
|
|
12
13
|
import { createImage } from "./runtime-assets.js";
|
|
@@ -199,16 +200,27 @@ function getYAMLErrorLine(rawData, objectKey) {
|
|
|
199
200
|
const numNewlinesBeforeKey = dataBeforeKey.split("\n").length;
|
|
200
201
|
return numNewlinesBeforeKey;
|
|
201
202
|
}
|
|
202
|
-
function
|
|
203
|
+
function safeParseFrontmatter(source, id) {
|
|
203
204
|
try {
|
|
204
|
-
matter
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
return matter(source);
|
|
206
|
+
} catch (err) {
|
|
207
|
+
const markdownError = new MarkdownError({
|
|
208
|
+
name: "MarkdownError",
|
|
209
|
+
message: err.message,
|
|
210
|
+
stack: err.stack,
|
|
211
|
+
location: id ? {
|
|
212
|
+
file: id
|
|
213
|
+
} : void 0
|
|
214
|
+
});
|
|
215
|
+
if (isYAMLException(err)) {
|
|
216
|
+
markdownError.setLocation({
|
|
217
|
+
file: id,
|
|
218
|
+
line: err.mark.line,
|
|
219
|
+
column: err.mark.column
|
|
220
|
+
});
|
|
221
|
+
markdownError.setMessage(err.reason);
|
|
211
222
|
}
|
|
223
|
+
throw markdownError;
|
|
212
224
|
}
|
|
213
225
|
}
|
|
214
226
|
const globalContentConfigObserver = contentObservable({ status: "init" });
|
|
@@ -356,6 +368,6 @@ export {
|
|
|
356
368
|
loadContentConfig,
|
|
357
369
|
msg,
|
|
358
370
|
parseEntrySlug,
|
|
359
|
-
|
|
360
|
-
|
|
371
|
+
reloadContentConfigObserver,
|
|
372
|
+
safeParseFrontmatter
|
|
361
373
|
};
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -334,8 +334,8 @@ function addPageName(pathname, opts) {
|
|
|
334
334
|
const pageName = shouldAppendForwardSlash(trailingSlash, buildFormat) ? pathname.replace(/\/?$/, "/").replace(/^\//, "") : pathname.replace(/^\//, "");
|
|
335
335
|
opts.pageNames.push(pageName);
|
|
336
336
|
}
|
|
337
|
-
function getUrlForPath(pathname, base, origin, format, routeType) {
|
|
338
|
-
const ending = format === "directory" ? "/" : ".html";
|
|
337
|
+
function getUrlForPath(pathname, base, origin, format, trailingSlash, routeType) {
|
|
338
|
+
const ending = format === "directory" ? trailingSlash === "never" ? "" : "/" : ".html";
|
|
339
339
|
let buildPathname;
|
|
340
340
|
if (pathname === "/" || pathname === "") {
|
|
341
341
|
buildPathname = base;
|
|
@@ -389,6 +389,7 @@ async function generatePath(pathname, pipeline, gopts, route) {
|
|
|
389
389
|
pipeline.getConfig().base,
|
|
390
390
|
pipeline.getStaticBuildOptions().origin,
|
|
391
391
|
pipeline.getConfig().build.format,
|
|
392
|
+
pipeline.getConfig().trailingSlash,
|
|
392
393
|
route.type
|
|
393
394
|
);
|
|
394
395
|
const request = createRequest({
|
package/dist/core/constants.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const ASTRO_VERSION: string;
|
|
2
2
|
export declare const SUPPORTED_MARKDOWN_FILE_EXTENSIONS: readonly [".markdown", ".mdown", ".mkdn", ".mkd", ".mdwn", ".md"];
|
|
3
3
|
export declare const MIDDLEWARE_PATH_SEGMENT_NAME = "middleware";
|
|
4
|
+
export declare const ROUTE_DATA_SYMBOL = "astro.routeData";
|
package/dist/core/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const ASTRO_VERSION = "4.2.
|
|
1
|
+
const ASTRO_VERSION = "4.2.8";
|
|
2
2
|
const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
|
|
3
3
|
".markdown",
|
|
4
4
|
".mdown",
|
|
@@ -8,8 +8,10 @@ const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
|
|
|
8
8
|
".md"
|
|
9
9
|
];
|
|
10
10
|
const MIDDLEWARE_PATH_SEGMENT_NAME = "middleware";
|
|
11
|
+
const ROUTE_DATA_SYMBOL = "astro.routeData";
|
|
11
12
|
export {
|
|
12
13
|
ASTRO_VERSION,
|
|
13
14
|
MIDDLEWARE_PATH_SEGMENT_NAME,
|
|
15
|
+
ROUTE_DATA_SYMBOL,
|
|
14
16
|
SUPPORTED_MARKDOWN_FILE_EXTENSIONS
|
|
15
17
|
};
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
|
|
|
23
23
|
base: restart.container.settings.config.base
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
|
-
const currentVersion = "4.2.
|
|
26
|
+
const currentVersion = "4.2.8";
|
|
27
27
|
if (currentVersion.includes("-")) {
|
|
28
28
|
logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
|
|
29
29
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -36,7 +36,7 @@ function serverStart({
|
|
|
36
36
|
host,
|
|
37
37
|
base
|
|
38
38
|
}) {
|
|
39
|
-
const version = "4.2.
|
|
39
|
+
const version = "4.2.8";
|
|
40
40
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
41
41
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
42
42
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -258,7 +258,7 @@ function printHelp({
|
|
|
258
258
|
message.push(
|
|
259
259
|
linebreak(),
|
|
260
260
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
261
|
-
`v${"4.2.
|
|
261
|
+
`v${"4.2.8"}`
|
|
262
262
|
)} ${headline}`
|
|
263
263
|
);
|
|
264
264
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { normalizeTheLocale, toCodes } from "../../i18n/index.js";
|
|
2
2
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
3
3
|
import { getParamsAndProps } from "./params-and-props.js";
|
|
4
|
+
import { ROUTE_DATA_SYMBOL } from "../constants.js";
|
|
4
5
|
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
6
|
+
const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL);
|
|
5
7
|
async function createRenderContext(options) {
|
|
6
8
|
const request = options.request;
|
|
7
9
|
const pathname = options.pathname ?? new URL(request.url).pathname;
|
|
@@ -148,8 +150,11 @@ function computePreferredLocaleList(request, locales) {
|
|
|
148
150
|
return result;
|
|
149
151
|
}
|
|
150
152
|
function computeCurrentLocale(request, locales, routingStrategy, defaultLocale) {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
+
const routeData = Reflect.get(request, routeDataSymbol);
|
|
154
|
+
if (!routeData) {
|
|
155
|
+
return defaultLocale;
|
|
156
|
+
}
|
|
157
|
+
for (const segment of routeData.route.split("/")) {
|
|
153
158
|
for (const locale of locales) {
|
|
154
159
|
if (typeof locale === "string") {
|
|
155
160
|
if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) {
|
package/dist/i18n/middleware.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { appendForwardSlash, joinPaths } from "@astrojs/internal-helpers/path";
|
|
2
2
|
import { getPathByLocale, normalizeTheLocale } from "./index.js";
|
|
3
3
|
import { shouldAppendForwardSlash } from "../core/build/util.js";
|
|
4
|
-
|
|
4
|
+
import { ROUTE_DATA_SYMBOL } from "../core/constants.js";
|
|
5
|
+
const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL);
|
|
5
6
|
function pathnameHasLocale(pathname, locales) {
|
|
6
7
|
const segments = pathname.split("/");
|
|
7
8
|
for (const segment of segments) {
|
|
@@ -3,7 +3,8 @@ import type { AstroConfig, AstroSettings } from '../@types/astro.js';
|
|
|
3
3
|
type AstroInternationalization = {
|
|
4
4
|
settings: AstroSettings;
|
|
5
5
|
};
|
|
6
|
-
export interface I18nInternalConfig extends Pick<AstroConfig, 'base' | 'site' | 'trailingSlash'>,
|
|
6
|
+
export interface I18nInternalConfig extends Pick<AstroConfig, 'base' | 'site' | 'trailingSlash'>, Pick<AstroConfig['build'], 'format'> {
|
|
7
|
+
i18n: AstroConfig['i18n'];
|
|
7
8
|
}
|
|
8
9
|
export default function astroInternationalization({ settings, }: AstroInternationalization): vite.Plugin;
|
|
9
10
|
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { AstroError } from "../core/errors/errors.js";
|
|
2
2
|
import { AstroErrorData } from "../core/errors/index.js";
|
|
3
3
|
const virtualModuleId = "astro:i18n";
|
|
4
|
-
const configId = "astro-internal:i18n-config";
|
|
5
|
-
const resolvedConfigId = `\0${configId}`;
|
|
6
4
|
function astroInternationalization({
|
|
7
5
|
settings
|
|
8
6
|
}) {
|
|
@@ -16,30 +14,20 @@ function astroInternationalization({
|
|
|
16
14
|
return {
|
|
17
15
|
name: "astro:i18n",
|
|
18
16
|
enforce: "pre",
|
|
19
|
-
|
|
17
|
+
config(config) {
|
|
18
|
+
const i18nConfig = { base, format, site, trailingSlash, i18n };
|
|
19
|
+
return {
|
|
20
|
+
define: {
|
|
21
|
+
__ASTRO_INTERNAL_I18N_CONFIG__: JSON.stringify(i18nConfig)
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
resolveId(id) {
|
|
20
26
|
if (id === virtualModuleId) {
|
|
21
27
|
if (i18n === void 0)
|
|
22
28
|
throw new AstroError(AstroErrorData.i18nNotEnabled);
|
|
23
29
|
return this.resolve("astro/virtual-modules/i18n.js");
|
|
24
30
|
}
|
|
25
|
-
if (id === configId)
|
|
26
|
-
return resolvedConfigId;
|
|
27
|
-
},
|
|
28
|
-
load(id) {
|
|
29
|
-
if (id === resolvedConfigId) {
|
|
30
|
-
const { defaultLocale, locales, routing, fallback } = i18n;
|
|
31
|
-
const config = {
|
|
32
|
-
base,
|
|
33
|
-
format,
|
|
34
|
-
site,
|
|
35
|
-
trailingSlash,
|
|
36
|
-
defaultLocale,
|
|
37
|
-
locales,
|
|
38
|
-
routing,
|
|
39
|
-
fallback
|
|
40
|
-
};
|
|
41
|
-
return `export default ${JSON.stringify(config)};`;
|
|
42
|
-
}
|
|
43
31
|
}
|
|
44
32
|
};
|
|
45
33
|
}
|
|
@@ -144,7 +144,10 @@ var settings_default = {
|
|
|
144
144
|
astroToggle.input.addEventListener("change", setting.changeEvent);
|
|
145
145
|
astroToggle.input.checked = settings.config[setting.settingKey];
|
|
146
146
|
label.append(astroToggle);
|
|
147
|
+
break;
|
|
147
148
|
}
|
|
149
|
+
default:
|
|
150
|
+
break;
|
|
148
151
|
}
|
|
149
152
|
return label;
|
|
150
153
|
}
|
|
@@ -23,7 +23,9 @@ Found handlers: ${Object.keys(mod).map((exp) => JSON.stringify(exp)).join(", ")}
|
|
|
23
23
|
return new Response(null, { status: 404 });
|
|
24
24
|
}
|
|
25
25
|
const response = await handler.call(mod, context);
|
|
26
|
-
response.
|
|
26
|
+
if (response.status === 404 || response.status === 500) {
|
|
27
|
+
response.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
|
28
|
+
}
|
|
27
29
|
return response;
|
|
28
30
|
}
|
|
29
31
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as I18nInternals from "../i18n/index.js";
|
|
2
2
|
import { normalizeTheLocale, toCodes, toPaths } from "../i18n/index.js";
|
|
3
|
-
|
|
4
|
-
const {
|
|
3
|
+
const { trailingSlash, format, site, i18n } = __ASTRO_INTERNAL_I18N_CONFIG__;
|
|
4
|
+
const { defaultLocale, locales, routing } = i18n;
|
|
5
5
|
const base = import.meta.env.BASE_URL;
|
|
6
6
|
const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleRelativeUrl({
|
|
7
7
|
locale,
|
|
@@ -44,11 +44,7 @@ async function writeWebResponse(res, webResponse) {
|
|
|
44
44
|
}
|
|
45
45
|
const _headers = Object.fromEntries(headers.entries());
|
|
46
46
|
if (headers.has("set-cookie")) {
|
|
47
|
-
|
|
48
|
-
_headers["set-cookie"] = headers.getSetCookie().toString();
|
|
49
|
-
} else {
|
|
50
|
-
_headers["set-cookie"] = headers.get("set-cookie");
|
|
51
|
-
}
|
|
47
|
+
_headers["set-cookie"] = headers.getSetCookie();
|
|
52
48
|
}
|
|
53
49
|
res.writeHead(status, _headers);
|
|
54
50
|
if (body) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { safeParseFrontmatter } from "../content/utils.js";
|
|
2
3
|
const markdownContentEntryType = {
|
|
3
4
|
extensions: [".md"],
|
|
4
|
-
async getEntryInfo({ contents }) {
|
|
5
|
-
const parsed =
|
|
5
|
+
async getEntryInfo({ contents, fileUrl }) {
|
|
6
|
+
const parsed = safeParseFrontmatter(contents, fileURLToPath(fileUrl));
|
|
6
7
|
return {
|
|
7
8
|
data: parsed.data,
|
|
8
9
|
body: parsed.content,
|
|
@@ -2,39 +2,16 @@ import {
|
|
|
2
2
|
createMarkdownProcessor,
|
|
3
3
|
InvalidAstroDataError
|
|
4
4
|
} from "@astrojs/markdown-remark";
|
|
5
|
-
import matter from "gray-matter";
|
|
6
5
|
import fs from "node:fs";
|
|
7
6
|
import path from "node:path";
|
|
8
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
8
|
import { normalizePath } from "vite";
|
|
10
|
-
import { AstroError, AstroErrorData
|
|
9
|
+
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
10
|
+
import { safeParseFrontmatter } from "../content/utils.js";
|
|
11
11
|
import { isMarkdownFile } from "../core/util.js";
|
|
12
12
|
import { shorthash } from "../runtime/server/shorthash.js";
|
|
13
13
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
14
14
|
import { getMarkdownCodeForImages } from "./images.js";
|
|
15
|
-
function safeMatter(source, id) {
|
|
16
|
-
try {
|
|
17
|
-
return matter(source);
|
|
18
|
-
} catch (err) {
|
|
19
|
-
const markdownError = new MarkdownError({
|
|
20
|
-
name: "MarkdownError",
|
|
21
|
-
message: err.message,
|
|
22
|
-
stack: err.stack,
|
|
23
|
-
location: {
|
|
24
|
-
file: id
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
if (err.name === "YAMLException") {
|
|
28
|
-
markdownError.setLocation({
|
|
29
|
-
file: id,
|
|
30
|
-
line: err.mark.line,
|
|
31
|
-
column: err.mark.column
|
|
32
|
-
});
|
|
33
|
-
markdownError.setMessage(err.reason);
|
|
34
|
-
}
|
|
35
|
-
throw markdownError;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
15
|
const astroServerRuntimeModulePath = normalizePath(
|
|
39
16
|
fileURLToPath(new URL("../runtime/server/index.js", import.meta.url))
|
|
40
17
|
);
|
|
@@ -57,7 +34,7 @@ function markdown({ settings, logger }) {
|
|
|
57
34
|
if (isMarkdownFile(id)) {
|
|
58
35
|
const { fileId, fileUrl } = getFileInfo(id, settings.config);
|
|
59
36
|
const rawFile = await fs.promises.readFile(fileId, "utf-8");
|
|
60
|
-
const raw =
|
|
37
|
+
const raw = safeParseFrontmatter(rawFile, id);
|
|
61
38
|
const fileURL = pathToFileURL(fileId);
|
|
62
39
|
const renderResult = await processor.render(raw.content, {
|
|
63
40
|
// @ts-expect-error passing internal prop
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.8",
|
|
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",
|
|
@@ -163,8 +163,8 @@
|
|
|
163
163
|
"yargs-parser": "^21.1.1",
|
|
164
164
|
"zod": "^3.22.4",
|
|
165
165
|
"@astrojs/internal-helpers": "0.2.1",
|
|
166
|
-
"@astrojs/
|
|
167
|
-
"@astrojs/
|
|
166
|
+
"@astrojs/telemetry": "3.0.4",
|
|
167
|
+
"@astrojs/markdown-remark": "4.2.1"
|
|
168
168
|
},
|
|
169
169
|
"optionalDependencies": {
|
|
170
170
|
"sharp": "^0.32.6"
|