astro 2.5.5 → 2.5.7
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 +9 -2
- package/dist/assets/services/service.js +6 -0
- package/dist/assets/utils/emitAsset.d.ts +1 -3
- package/dist/assets/utils/emitAsset.js +4 -15
- package/dist/assets/vite-plugin-assets.js +5 -5
- package/dist/config/index.js +11 -3
- package/dist/config/vite-plugin-content-listen.d.ts +18 -0
- package/dist/config/vite-plugin-content-listen.js +26 -0
- package/dist/content/consts.d.ts +2 -1
- package/dist/content/consts.js +8 -1
- package/dist/content/runtime-assets.d.ts +1 -2
- package/dist/content/runtime-assets.js +2 -3
- package/dist/content/runtime.js +67 -47
- package/dist/content/types-generator.js +9 -5
- package/dist/content/utils.d.ts +2 -2
- package/dist/content/utils.js +4 -4
- package/dist/content/vite-plugin-content-assets.js +26 -10
- package/dist/content/vite-plugin-content-imports.js +113 -150
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +3 -3
- package/dist/content/vite-plugin-content-virtual-mod.js +21 -8
- package/dist/core/app/index.d.ts +0 -2
- package/dist/core/app/index.js +5 -7
- package/dist/core/app/node.js +4 -3
- package/dist/core/app/types.d.ts +3 -2
- package/dist/core/build/generate.js +16 -11
- package/dist/core/build/graph.js +3 -2
- package/dist/core/build/internal.d.ts +8 -4
- package/dist/core/build/internal.js +19 -1
- package/dist/core/build/plugins/plugin-css.js +9 -14
- package/dist/core/build/plugins/plugin-middleware.d.ts +0 -1
- package/dist/core/build/plugins/plugin-middleware.js +3 -16
- package/dist/core/build/plugins/plugin-pages.d.ts +10 -0
- package/dist/core/build/plugins/plugin-pages.js +40 -24
- package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
- package/dist/core/build/plugins/plugin-ssr.js +46 -20
- package/dist/core/build/static-build.js +18 -5
- package/dist/core/build/types.d.ts +2 -2
- package/dist/core/config/schema.d.ts +170 -170
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +57 -8
- package/dist/core/errors/errors-data.js +57 -12
- package/dist/core/messages.js +2 -2
- package/dist/core/render/dev/index.js +1 -2
- package/dist/core/render/dev/vite.js +12 -13
- package/dist/prerender/routing.d.ts +13 -0
- package/dist/prerender/routing.js +49 -0
- package/dist/runtime/server/astro-global.js +11 -1
- package/dist/runtime/server/index.d.ts +1 -1
- package/dist/runtime/server/index.js +9 -1
- package/dist/runtime/server/render/any.js +4 -2
- package/dist/runtime/server/render/astro/instance.js +3 -0
- package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
- package/dist/runtime/server/render/astro/render-template.js +5 -9
- package/dist/runtime/server/render/util.d.ts +6 -0
- package/dist/runtime/server/render/util.js +8 -0
- package/dist/runtime/server/scripts.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +3 -11
- package/dist/vite-plugin-head/index.js +1 -1
- package/dist/vite-plugin-markdown/content-entry-type.js +6 -1
- package/dist/vite-plugin-utils/index.js +1 -1
- package/package.json +4 -4
- package/src/content/template/virtual-mod.mjs +1 -1
package/dist/@types/astro.d.ts
CHANGED
|
@@ -1166,10 +1166,17 @@ export interface ContentEntryType {
|
|
|
1166
1166
|
contents: string;
|
|
1167
1167
|
}): GetContentEntryInfoReturnType | Promise<GetContentEntryInfoReturnType>;
|
|
1168
1168
|
getRenderModule?(this: rollup.PluginContext, params: {
|
|
1169
|
+
contents: string;
|
|
1170
|
+
fileUrl: URL;
|
|
1169
1171
|
viteId: string;
|
|
1170
|
-
entry: ContentEntryModule;
|
|
1171
1172
|
}): rollup.LoadResult | Promise<rollup.LoadResult>;
|
|
1172
1173
|
contentModuleTypes?: string;
|
|
1174
|
+
/**
|
|
1175
|
+
* Handle asset propagation for rendered content to avoid bleed.
|
|
1176
|
+
* Ex. MDX content can import styles and scripts, so `handlePropagation` should be true.
|
|
1177
|
+
* @default true
|
|
1178
|
+
*/
|
|
1179
|
+
handlePropagation?: boolean;
|
|
1173
1180
|
}
|
|
1174
1181
|
type GetContentEntryInfoReturnType = {
|
|
1175
1182
|
data: Record<string, unknown>;
|
|
@@ -1528,7 +1535,7 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
|
|
|
1528
1535
|
*
|
|
1529
1536
|
* export const onRequest = defineMiddleware((context, next) => {
|
|
1530
1537
|
* context.locals.greeting = "Hello!";
|
|
1531
|
-
* next();
|
|
1538
|
+
* return next();
|
|
1532
1539
|
* });
|
|
1533
1540
|
* ```
|
|
1534
1541
|
* Inside a `.astro` file:
|
|
@@ -24,6 +24,12 @@ const baseService = {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
if (!isESMImportedImage(options.src)) {
|
|
27
|
+
if (options.src.startsWith("/@fs/")) {
|
|
28
|
+
throw new AstroError({
|
|
29
|
+
...AstroErrorData.LocalImageUsedWrongly,
|
|
30
|
+
message: AstroErrorData.LocalImageUsedWrongly.message(options.src)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
27
33
|
let missingDimension;
|
|
28
34
|
if (!options.width && !options.height) {
|
|
29
35
|
missingDimension = "both";
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import type { AstroSettings } from '../../@types/astro';
|
|
2
1
|
import { type Metadata } from './metadata.js';
|
|
3
|
-
export declare function emitESMImage(id: string | undefined, watchMode: boolean, fileEmitter: any
|
|
4
|
-
export declare function emoji(char: string, fallback: string): string;
|
|
2
|
+
export declare function emitESMImage(id: string | undefined, watchMode: boolean, fileEmitter: any): Promise<Metadata | undefined>;
|
|
@@ -2,8 +2,9 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import slash from "slash";
|
|
5
|
+
import { prependForwardSlash } from "../../core/path.js";
|
|
5
6
|
import { imageMetadata } from "./metadata.js";
|
|
6
|
-
async function emitESMImage(id, watchMode, fileEmitter
|
|
7
|
+
async function emitESMImage(id, watchMode, fileEmitter) {
|
|
7
8
|
if (!id) {
|
|
8
9
|
return void 0;
|
|
9
10
|
}
|
|
@@ -25,25 +26,13 @@ async function emitESMImage(id, watchMode, fileEmitter, settings) {
|
|
|
25
26
|
url.searchParams.append("origWidth", meta.width.toString());
|
|
26
27
|
url.searchParams.append("origHeight", meta.height.toString());
|
|
27
28
|
url.searchParams.append("origFormat", meta.format);
|
|
28
|
-
meta.src =
|
|
29
|
+
meta.src = `/@fs` + prependForwardSlash(fileURLToNormalizedPath(url));
|
|
29
30
|
}
|
|
30
31
|
return meta;
|
|
31
32
|
}
|
|
32
|
-
function rootRelativePath(config, url) {
|
|
33
|
-
const basePath = fileURLToNormalizedPath(url);
|
|
34
|
-
const rootPath = fileURLToNormalizedPath(config.root);
|
|
35
|
-
return prependForwardSlash(basePath.slice(rootPath.length));
|
|
36
|
-
}
|
|
37
|
-
function prependForwardSlash(filePath) {
|
|
38
|
-
return filePath[0] === "/" ? filePath : "/" + filePath;
|
|
39
|
-
}
|
|
40
33
|
function fileURLToNormalizedPath(filePath) {
|
|
41
34
|
return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, "/");
|
|
42
35
|
}
|
|
43
|
-
function emoji(char, fallback) {
|
|
44
|
-
return process.platform !== "win32" ? char : fallback;
|
|
45
|
-
}
|
|
46
36
|
export {
|
|
47
|
-
emitESMImage
|
|
48
|
-
emoji
|
|
37
|
+
emitESMImage
|
|
49
38
|
};
|
|
@@ -87,17 +87,17 @@ function assets({
|
|
|
87
87
|
// Handle serving images during development
|
|
88
88
|
configureServer(server) {
|
|
89
89
|
server.middlewares.use(async (req, res, next) => {
|
|
90
|
-
var _a2;
|
|
90
|
+
var _a2, _b;
|
|
91
91
|
if ((_a2 = req.url) == null ? void 0 : _a2.startsWith("/_image")) {
|
|
92
92
|
if (!isLocalService(globalThis.astroAsset.imageService)) {
|
|
93
93
|
return next();
|
|
94
94
|
}
|
|
95
95
|
const url = new URL(req.url, "file:");
|
|
96
|
-
|
|
97
|
-
if (!filePath) {
|
|
96
|
+
if (!url.searchParams.has("href")) {
|
|
98
97
|
return next();
|
|
99
98
|
}
|
|
100
|
-
const
|
|
99
|
+
const filePath = (_b = url.searchParams.get("href")) == null ? void 0 : _b.slice("/@fs".length);
|
|
100
|
+
const filePathURL = new URL("." + filePath, "file:");
|
|
101
101
|
const file = await fs.readFile(filePathURL);
|
|
102
102
|
let meta = getOrigQueryParams(filePathURL.searchParams);
|
|
103
103
|
if (!meta) {
|
|
@@ -196,7 +196,7 @@ function assets({
|
|
|
196
196
|
}
|
|
197
197
|
const cleanedUrl = removeQueryString(id);
|
|
198
198
|
if (/\.(jpeg|jpg|png|tiff|webp|gif|svg)$/.test(cleanedUrl)) {
|
|
199
|
-
const meta = await emitESMImage(id, this.meta.watchMode, this.emitFile
|
|
199
|
+
const meta = await emitESMImage(id, this.meta.watchMode, this.emitFile);
|
|
200
200
|
return `export default ${JSON.stringify(meta)}`;
|
|
201
201
|
}
|
|
202
202
|
}
|
package/dist/config/index.js
CHANGED
|
@@ -5,17 +5,21 @@ function getViteConfig(inlineConfig) {
|
|
|
5
5
|
return async ({ mode, command }) => {
|
|
6
6
|
const cmd = command === "serve" ? "dev" : command;
|
|
7
7
|
const [
|
|
8
|
+
fs,
|
|
8
9
|
{ mergeConfig },
|
|
9
10
|
{ nodeLogDestination },
|
|
10
11
|
{ openConfig, createSettings },
|
|
11
12
|
{ createVite },
|
|
12
|
-
{ runHookConfigSetup, runHookConfigDone }
|
|
13
|
+
{ runHookConfigSetup, runHookConfigDone },
|
|
14
|
+
{ astroContentListenPlugin }
|
|
13
15
|
] = await Promise.all([
|
|
16
|
+
import("fs"),
|
|
14
17
|
import("vite"),
|
|
15
18
|
import("../core/logger/node.js"),
|
|
16
19
|
import("../core/config/index.js"),
|
|
17
20
|
import("../core/create-vite.js"),
|
|
18
|
-
import("../integrations/index.js")
|
|
21
|
+
import("../integrations/index.js"),
|
|
22
|
+
import("./vite-plugin-content-listen.js")
|
|
19
23
|
]);
|
|
20
24
|
const logging = {
|
|
21
25
|
dest: nodeLogDestination,
|
|
@@ -29,7 +33,11 @@ function getViteConfig(inlineConfig) {
|
|
|
29
33
|
await runHookConfigSetup({ settings, command: cmd, logging });
|
|
30
34
|
const viteConfig = await createVite(
|
|
31
35
|
{
|
|
32
|
-
mode
|
|
36
|
+
mode,
|
|
37
|
+
plugins: [
|
|
38
|
+
// Initialize the content listener
|
|
39
|
+
astroContentListenPlugin({ settings, logging, fs })
|
|
40
|
+
]
|
|
33
41
|
},
|
|
34
42
|
{ settings, logging, mode }
|
|
35
43
|
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fsMod from 'node:fs';
|
|
3
|
+
import type { Plugin } from 'vite';
|
|
4
|
+
import type { AstroSettings } from '../@types/astro';
|
|
5
|
+
import type { LogOptions } from '../core/logger/core.js';
|
|
6
|
+
/**
|
|
7
|
+
* Listen for Astro content directory changes and generate types.
|
|
8
|
+
*
|
|
9
|
+
* This is a separate plugin for `getViteConfig` as the `attachContentServerListeners` API
|
|
10
|
+
* needs to be called at different times in `astro dev` and `getViteConfig`. For `astro dev`,
|
|
11
|
+
* it needs to be called after the Astro server is started (packages/astro/src/core/dev/dev.ts).
|
|
12
|
+
* For `getViteConfig`, it needs to be called after the Vite server is started.
|
|
13
|
+
*/
|
|
14
|
+
export declare function astroContentListenPlugin({ settings, logging, fs, }: {
|
|
15
|
+
settings: AstroSettings;
|
|
16
|
+
logging: LogOptions;
|
|
17
|
+
fs: typeof fsMod;
|
|
18
|
+
}): Plugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { attachContentServerListeners } from "../content/server-listeners.js";
|
|
2
|
+
function astroContentListenPlugin({
|
|
3
|
+
settings,
|
|
4
|
+
logging,
|
|
5
|
+
fs
|
|
6
|
+
}) {
|
|
7
|
+
let server;
|
|
8
|
+
return {
|
|
9
|
+
name: "astro:content-listen",
|
|
10
|
+
apply: "serve",
|
|
11
|
+
configureServer(_server) {
|
|
12
|
+
server = _server;
|
|
13
|
+
},
|
|
14
|
+
async buildStart() {
|
|
15
|
+
await attachContentServerListeners({
|
|
16
|
+
fs,
|
|
17
|
+
settings,
|
|
18
|
+
logging,
|
|
19
|
+
viteServer: server
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
astroContentListenPlugin
|
|
26
|
+
};
|
package/dist/content/consts.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
2
|
+
export declare const CONTENT_RENDER_FLAG = "astroRenderContent";
|
|
2
3
|
export declare const CONTENT_FLAG = "astroContentCollectionEntry";
|
|
3
4
|
export declare const DATA_FLAG = "astroDataCollectionEntry";
|
|
4
|
-
export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroDataCollectionEntry", "astroPropagatedAssets"];
|
|
5
5
|
export declare const VIRTUAL_MODULE_ID = "astro:content";
|
|
6
6
|
export declare const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
|
|
7
7
|
export declare const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
|
|
8
8
|
export declare const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
|
|
9
|
+
export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroRenderContent", "astroDataCollectionEntry", "astroPropagatedAssets"];
|
|
9
10
|
export declare const CONTENT_TYPES_FILE = "types.d.ts";
|
package/dist/content/consts.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
2
|
+
const CONTENT_RENDER_FLAG = "astroRenderContent";
|
|
2
3
|
const CONTENT_FLAG = "astroContentCollectionEntry";
|
|
3
4
|
const DATA_FLAG = "astroDataCollectionEntry";
|
|
4
|
-
const CONTENT_FLAGS = [CONTENT_FLAG, DATA_FLAG, PROPAGATED_ASSET_FLAG];
|
|
5
5
|
const VIRTUAL_MODULE_ID = "astro:content";
|
|
6
6
|
const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
|
|
7
7
|
const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
|
|
8
8
|
const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
|
|
9
|
+
const CONTENT_FLAGS = [
|
|
10
|
+
CONTENT_FLAG,
|
|
11
|
+
CONTENT_RENDER_FLAG,
|
|
12
|
+
DATA_FLAG,
|
|
13
|
+
PROPAGATED_ASSET_FLAG
|
|
14
|
+
];
|
|
9
15
|
const CONTENT_TYPES_FILE = "types.d.ts";
|
|
10
16
|
export {
|
|
11
17
|
CONTENT_FLAG,
|
|
12
18
|
CONTENT_FLAGS,
|
|
19
|
+
CONTENT_RENDER_FLAG,
|
|
13
20
|
CONTENT_TYPES_FILE,
|
|
14
21
|
DATA_FLAG,
|
|
15
22
|
LINKS_PLACEHOLDER,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { PluginContext } from 'rollup';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
export declare function createImage(settings: Pick<AstroSettings, 'config'>, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
|
|
3
|
+
export declare function createImage(pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { emitESMImage } from "../assets/index.js";
|
|
3
|
-
function createImage(
|
|
3
|
+
function createImage(pluginContext, entryFilePath) {
|
|
4
4
|
return () => {
|
|
5
5
|
return z.string().transform(async (imagePath, ctx) => {
|
|
6
6
|
var _a;
|
|
@@ -8,8 +8,7 @@ function createImage(settings, pluginContext, entryFilePath) {
|
|
|
8
8
|
const metadata = await emitESMImage(
|
|
9
9
|
resolvedFilePath,
|
|
10
10
|
pluginContext.meta.watchMode,
|
|
11
|
-
pluginContext.emitFile
|
|
12
|
-
settings
|
|
11
|
+
pluginContext.emitFile
|
|
13
12
|
);
|
|
14
13
|
if (!metadata) {
|
|
15
14
|
ctx.addIssue({
|
package/dist/content/runtime.js
CHANGED
|
@@ -184,7 +184,7 @@ async function render({
|
|
|
184
184
|
id,
|
|
185
185
|
renderEntryImport
|
|
186
186
|
}) {
|
|
187
|
-
var _a;
|
|
187
|
+
var _a, _b;
|
|
188
188
|
const UnexpectedRenderError = new AstroError({
|
|
189
189
|
...AstroErrorData.UnknownContentCollectionError,
|
|
190
190
|
message: `Unexpected error while rendering ${String(collection)} \u2192 ${String(id)}.`
|
|
@@ -194,53 +194,70 @@ async function render({
|
|
|
194
194
|
const baseMod = await renderEntryImport();
|
|
195
195
|
if (baseMod == null || typeof baseMod !== "object")
|
|
196
196
|
throw UnexpectedRenderError;
|
|
197
|
-
const {
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
const { default: defaultMod } = baseMod;
|
|
198
|
+
if (isPropagatedAssetsModule(defaultMod)) {
|
|
199
|
+
const { collectedStyles, collectedLinks, collectedScripts, getMod } = defaultMod;
|
|
200
|
+
if (typeof getMod !== "function")
|
|
201
|
+
throw UnexpectedRenderError;
|
|
202
|
+
const propagationMod = await getMod();
|
|
203
|
+
if (propagationMod == null || typeof propagationMod !== "object")
|
|
204
|
+
throw UnexpectedRenderError;
|
|
205
|
+
const Content = createComponent({
|
|
206
|
+
factory(result, baseProps, slots) {
|
|
207
|
+
let styles = "", links = "", scripts = "";
|
|
208
|
+
if (Array.isArray(collectedStyles)) {
|
|
209
|
+
styles = collectedStyles.map((style) => {
|
|
210
|
+
return renderUniqueStylesheet(result, {
|
|
211
|
+
type: "inline",
|
|
212
|
+
content: style
|
|
213
|
+
});
|
|
214
|
+
}).join("");
|
|
215
|
+
}
|
|
216
|
+
if (Array.isArray(collectedLinks)) {
|
|
217
|
+
links = collectedLinks.map((link) => {
|
|
218
|
+
return renderUniqueStylesheet(result, {
|
|
219
|
+
type: "external",
|
|
220
|
+
src: prependForwardSlash(link)
|
|
221
|
+
});
|
|
222
|
+
}).join("");
|
|
223
|
+
}
|
|
224
|
+
if (Array.isArray(collectedScripts)) {
|
|
225
|
+
scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
|
|
226
|
+
}
|
|
227
|
+
let props = baseProps;
|
|
228
|
+
if (id.endsWith("mdx")) {
|
|
229
|
+
props = {
|
|
230
|
+
components: propagationMod.components ?? {},
|
|
231
|
+
...baseProps
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return createHeadAndContent(
|
|
235
|
+
unescapeHTML(styles + links + scripts),
|
|
236
|
+
renderTemplate`${renderComponent(
|
|
237
|
+
result,
|
|
238
|
+
"Content",
|
|
239
|
+
propagationMod.Content,
|
|
240
|
+
props,
|
|
241
|
+
slots
|
|
242
|
+
)}`
|
|
243
|
+
);
|
|
244
|
+
},
|
|
245
|
+
propagation: "self"
|
|
246
|
+
});
|
|
247
|
+
return {
|
|
248
|
+
Content,
|
|
249
|
+
headings: ((_a = propagationMod.getHeadings) == null ? void 0 : _a.call(propagationMod)) ?? [],
|
|
250
|
+
remarkPluginFrontmatter: propagationMod.frontmatter ?? {}
|
|
251
|
+
};
|
|
252
|
+
} else if (baseMod.Content && typeof baseMod.Content === "function") {
|
|
253
|
+
return {
|
|
254
|
+
Content: baseMod.Content,
|
|
255
|
+
headings: ((_b = baseMod.getHeadings) == null ? void 0 : _b.call(baseMod)) ?? [],
|
|
256
|
+
remarkPluginFrontmatter: baseMod.frontmatter ?? {}
|
|
257
|
+
};
|
|
258
|
+
} else {
|
|
202
259
|
throw UnexpectedRenderError;
|
|
203
|
-
|
|
204
|
-
factory(result, baseProps, slots) {
|
|
205
|
-
let styles = "", links = "", scripts = "";
|
|
206
|
-
if (Array.isArray(collectedStyles)) {
|
|
207
|
-
styles = collectedStyles.map((style) => {
|
|
208
|
-
return renderUniqueStylesheet(result, {
|
|
209
|
-
type: "inline",
|
|
210
|
-
content: style
|
|
211
|
-
});
|
|
212
|
-
}).join("");
|
|
213
|
-
}
|
|
214
|
-
if (Array.isArray(collectedLinks)) {
|
|
215
|
-
links = collectedLinks.map((link) => {
|
|
216
|
-
return renderUniqueStylesheet(result, {
|
|
217
|
-
type: "external",
|
|
218
|
-
src: prependForwardSlash(link)
|
|
219
|
-
});
|
|
220
|
-
}).join("");
|
|
221
|
-
}
|
|
222
|
-
if (Array.isArray(collectedScripts)) {
|
|
223
|
-
scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
|
|
224
|
-
}
|
|
225
|
-
let props = baseProps;
|
|
226
|
-
if (id.endsWith("mdx")) {
|
|
227
|
-
props = {
|
|
228
|
-
components: mod.components ?? {},
|
|
229
|
-
...baseProps
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
return createHeadAndContent(
|
|
233
|
-
unescapeHTML(styles + links + scripts),
|
|
234
|
-
renderTemplate`${renderComponent(result, "Content", mod.Content, props, slots)}`
|
|
235
|
-
);
|
|
236
|
-
},
|
|
237
|
-
propagation: "self"
|
|
238
|
-
});
|
|
239
|
-
return {
|
|
240
|
-
Content,
|
|
241
|
-
headings: ((_a = mod.getHeadings) == null ? void 0 : _a.call(mod)) ?? [],
|
|
242
|
-
remarkPluginFrontmatter: mod.frontmatter ?? {}
|
|
243
|
-
};
|
|
260
|
+
}
|
|
244
261
|
}
|
|
245
262
|
function createReference({ lookupMap }) {
|
|
246
263
|
return function reference(collection) {
|
|
@@ -271,6 +288,9 @@ function createReference({ lookupMap }) {
|
|
|
271
288
|
});
|
|
272
289
|
};
|
|
273
290
|
}
|
|
291
|
+
function isPropagatedAssetsModule(module) {
|
|
292
|
+
return typeof module === "object" && module != null && "__astroPropagation" in module;
|
|
293
|
+
}
|
|
274
294
|
export {
|
|
275
295
|
createCollectionToGlobResultMap,
|
|
276
296
|
createGetCollection,
|
|
@@ -9,12 +9,12 @@ import { info, warn } from "../core/logger/core.js";
|
|
|
9
9
|
import { isRelativePath } from "../core/path.js";
|
|
10
10
|
import { CONTENT_TYPES_FILE, VIRTUAL_MODULE_ID } from "./consts.js";
|
|
11
11
|
import {
|
|
12
|
-
getContentEntryConfigByExtMap,
|
|
13
12
|
getContentEntryIdAndSlug,
|
|
14
13
|
getContentPaths,
|
|
15
14
|
getDataEntryExts,
|
|
16
15
|
getDataEntryId,
|
|
17
16
|
getEntryCollectionName,
|
|
17
|
+
getEntryConfigByExtMap,
|
|
18
18
|
getEntrySlug,
|
|
19
19
|
getEntryType,
|
|
20
20
|
reloadContentConfigObserver
|
|
@@ -30,7 +30,7 @@ async function createContentTypesGenerator({
|
|
|
30
30
|
}) {
|
|
31
31
|
const collectionEntryMap = {};
|
|
32
32
|
const contentPaths = getContentPaths(settings.config, fs);
|
|
33
|
-
const contentEntryConfigByExt =
|
|
33
|
+
const contentEntryConfigByExt = getEntryConfigByExtMap(settings.contentEntryTypes);
|
|
34
34
|
const contentEntryExts = [...contentEntryConfigByExt.keys()];
|
|
35
35
|
const dataEntryExts = getDataEntryExts(settings);
|
|
36
36
|
let events = [];
|
|
@@ -327,7 +327,7 @@ async function writeContentFiles({
|
|
|
327
327
|
for (const collectionKey of Object.keys(collectionEntryMap).sort()) {
|
|
328
328
|
const collectionConfig = contentConfig == null ? void 0 : contentConfig.collections[JSON.parse(collectionKey)];
|
|
329
329
|
const collection = collectionEntryMap[collectionKey];
|
|
330
|
-
if ((collectionConfig == null ? void 0 : collectionConfig.type) && collection.type !== collectionConfig.type) {
|
|
330
|
+
if ((collectionConfig == null ? void 0 : collectionConfig.type) && collection.type !== "unknown" && collection.type !== collectionConfig.type) {
|
|
331
331
|
viteServer.ws.send({
|
|
332
332
|
type: "error",
|
|
333
333
|
err: new AstroError({
|
|
@@ -346,7 +346,12 @@ async function writeContentFiles({
|
|
|
346
346
|
});
|
|
347
347
|
return;
|
|
348
348
|
}
|
|
349
|
-
|
|
349
|
+
const resolvedType = collection.type === "unknown" ? (
|
|
350
|
+
// Add empty / unknown collections to the data type map by default
|
|
351
|
+
// This ensures `getCollection('empty-collection')` doesn't raise a type error
|
|
352
|
+
(collectionConfig == null ? void 0 : collectionConfig.type) ?? "data"
|
|
353
|
+
) : collection.type;
|
|
354
|
+
switch (resolvedType) {
|
|
350
355
|
case "content":
|
|
351
356
|
contentTypesStr += `${collectionKey}: {
|
|
352
357
|
`;
|
|
@@ -370,7 +375,6 @@ async function writeContentFiles({
|
|
|
370
375
|
`;
|
|
371
376
|
break;
|
|
372
377
|
case "data":
|
|
373
|
-
case "unknown":
|
|
374
378
|
dataTypesStr += `${collectionKey}: {
|
|
375
379
|
`;
|
|
376
380
|
for (const entryKey of Object.keys(collection.entries).sort()) {
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import fsMod from 'node:fs';
|
|
|
4
4
|
import type { PluginContext } from 'rollup';
|
|
5
5
|
import { type ViteDevServer } from 'vite';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import type { AstroConfig, AstroSettings, ContentEntryType } from '../@types/astro.js';
|
|
7
|
+
import type { AstroConfig, AstroSettings, ContentEntryType, DataEntryType } from '../@types/astro.js';
|
|
8
8
|
import { CONTENT_FLAGS } from './consts.js';
|
|
9
9
|
/**
|
|
10
10
|
* Amap from a collection + slug to the local file path.
|
|
@@ -102,7 +102,7 @@ export declare function getEntryData(entry: {
|
|
|
102
102
|
}, collectionConfig: CollectionConfig, pluginContext: PluginContext, config: AstroConfig): Promise<any>;
|
|
103
103
|
export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
|
|
104
104
|
export declare function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>): string[];
|
|
105
|
-
export declare function
|
|
105
|
+
export declare function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(entryTypes: TEntryType[]): Map<string, TEntryType>;
|
|
106
106
|
export declare function getEntryCollectionName({ contentDir, entry, }: Pick<ContentPaths, 'contentDir'> & {
|
|
107
107
|
entry: string | URL;
|
|
108
108
|
}): string | undefined;
|
package/dist/content/utils.js
CHANGED
|
@@ -65,7 +65,7 @@ async function getEntryData(entry, collectionConfig, pluginContext, config) {
|
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
schema = schema({
|
|
68
|
-
image: createImage(
|
|
68
|
+
image: createImage(pluginContext, entry._internal.filePath)
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
if (schema) {
|
|
@@ -114,9 +114,9 @@ function getContentEntryExts(settings) {
|
|
|
114
114
|
function getDataEntryExts(settings) {
|
|
115
115
|
return settings.dataEntryTypes.map((t) => t.extensions).flat();
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function getEntryConfigByExtMap(entryTypes) {
|
|
118
118
|
const map = /* @__PURE__ */ new Map();
|
|
119
|
-
for (const entryType of
|
|
119
|
+
for (const entryType of entryTypes) {
|
|
120
120
|
for (const ext of entryType.extensions) {
|
|
121
121
|
map.set(ext, entryType);
|
|
122
122
|
}
|
|
@@ -340,7 +340,6 @@ export {
|
|
|
340
340
|
collectionConfigParser,
|
|
341
341
|
contentConfigParser,
|
|
342
342
|
contentObservable,
|
|
343
|
-
getContentEntryConfigByExtMap,
|
|
344
343
|
getContentEntryExts,
|
|
345
344
|
getContentEntryIdAndSlug,
|
|
346
345
|
getContentPaths,
|
|
@@ -348,6 +347,7 @@ export {
|
|
|
348
347
|
getDataEntryId,
|
|
349
348
|
getDotAstroTypeReference,
|
|
350
349
|
getEntryCollectionName,
|
|
350
|
+
getEntryConfigByExtMap,
|
|
351
351
|
getEntryData,
|
|
352
352
|
getEntrySlug,
|
|
353
353
|
getEntryType,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { extname } from "node:path";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
2
3
|
import { moduleIsTopLevelPage, walkParentInfos } from "../core/build/graph.js";
|
|
3
4
|
import { getPageDataByViteID } from "../core/build/internal.js";
|
|
4
5
|
import { createViteLoader } from "../core/module-loader/vite.js";
|
|
@@ -6,15 +7,13 @@ import { joinPaths, prependForwardSlash } from "../core/path.js";
|
|
|
6
7
|
import { getStylesForURL } from "../core/render/dev/css.js";
|
|
7
8
|
import { getScriptsForURL } from "../core/render/dev/scripts.js";
|
|
8
9
|
import {
|
|
10
|
+
CONTENT_RENDER_FLAG,
|
|
9
11
|
LINKS_PLACEHOLDER,
|
|
10
12
|
PROPAGATED_ASSET_FLAG,
|
|
11
13
|
SCRIPTS_PLACEHOLDER,
|
|
12
14
|
STYLES_PLACEHOLDER
|
|
13
15
|
} from "./consts.js";
|
|
14
|
-
|
|
15
|
-
const flags = new URLSearchParams(viteId.split("?")[1]);
|
|
16
|
-
return flags.has(PROPAGATED_ASSET_FLAG);
|
|
17
|
-
}
|
|
16
|
+
import { hasContentFlag } from "./utils.js";
|
|
18
17
|
function astroContentAssetPropagationPlugin({
|
|
19
18
|
mode,
|
|
20
19
|
settings
|
|
@@ -22,6 +21,21 @@ function astroContentAssetPropagationPlugin({
|
|
|
22
21
|
let devModuleLoader;
|
|
23
22
|
return {
|
|
24
23
|
name: "astro:content-asset-propagation",
|
|
24
|
+
enforce: "pre",
|
|
25
|
+
async resolveId(id, importer, opts) {
|
|
26
|
+
if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
|
|
27
|
+
const base = id.split("?")[0];
|
|
28
|
+
for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {
|
|
29
|
+
if (handlePropagation && extensions.includes(extname(base))) {
|
|
30
|
+
return this.resolve(`${base}?${PROPAGATED_ASSET_FLAG}`, importer, {
|
|
31
|
+
skipSelf: true,
|
|
32
|
+
...opts
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return this.resolve(base, importer, { skipSelf: true, ...opts });
|
|
37
|
+
}
|
|
38
|
+
},
|
|
25
39
|
configureServer(server) {
|
|
26
40
|
if (mode === "dev") {
|
|
27
41
|
devModuleLoader = createViteLoader(server);
|
|
@@ -29,7 +43,7 @@ function astroContentAssetPropagationPlugin({
|
|
|
29
43
|
},
|
|
30
44
|
async transform(_, id, options) {
|
|
31
45
|
var _a;
|
|
32
|
-
if (
|
|
46
|
+
if (hasContentFlag(id, PROPAGATED_ASSET_FLAG)) {
|
|
33
47
|
const basePath = id.split("?")[0];
|
|
34
48
|
let stringifiedLinks, stringifiedStyles, stringifiedScripts;
|
|
35
49
|
if ((options == null ? void 0 : options.ssr) && devModuleLoader) {
|
|
@@ -55,12 +69,14 @@ function astroContentAssetPropagationPlugin({
|
|
|
55
69
|
stringifiedScripts = JSON.stringify(SCRIPTS_PLACEHOLDER);
|
|
56
70
|
}
|
|
57
71
|
const code = `
|
|
58
|
-
|
|
72
|
+
async function getMod() {
|
|
59
73
|
return import(${JSON.stringify(basePath)});
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
const collectedLinks = ${stringifiedLinks};
|
|
76
|
+
const collectedStyles = ${stringifiedStyles};
|
|
77
|
+
const collectedScripts = ${stringifiedScripts};
|
|
78
|
+
const defaultMod = { __astroPropagation: true, getMod, collectedLinks, collectedStyles, collectedScripts };
|
|
79
|
+
export default defaultMod;
|
|
64
80
|
`;
|
|
65
81
|
return { code, map: { mappings: "" } };
|
|
66
82
|
}
|