astro 4.13.4 → 4.14.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/components/Code.astro +9 -0
- package/dist/@types/astro.d.ts +249 -1
- package/dist/actions/consts.d.ts +1 -1
- package/dist/actions/consts.js +1 -1
- package/dist/actions/index.js +12 -21
- package/dist/assets/utils/resolveImports.d.ts +9 -0
- package/dist/assets/utils/resolveImports.js +22 -0
- package/dist/cli/add/index.d.ts +2 -2
- package/dist/cli/add/index.js +2 -2
- package/dist/cli/build/index.d.ts +2 -2
- package/dist/cli/build/index.js +5 -1
- package/dist/cli/check/index.d.ts +2 -2
- package/dist/cli/check/index.js +5 -2
- package/dist/cli/db/index.d.ts +4 -3
- package/dist/cli/db/index.js +10 -3
- package/dist/cli/dev/index.d.ts +2 -2
- package/dist/cli/dev/index.js +1 -0
- package/dist/cli/docs/index.d.ts +2 -2
- package/dist/cli/flags.d.ts +3 -1
- package/dist/cli/flags.js +2 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +26 -13
- package/dist/cli/info/index.d.ts +2 -2
- package/dist/cli/preferences/index.d.ts +2 -2
- package/dist/cli/preferences/index.js +1 -1
- package/dist/cli/preview/index.d.ts +2 -2
- package/dist/cli/sync/index.d.ts +2 -2
- package/dist/cli/sync/index.js +5 -2
- package/dist/cli/telemetry/index.d.ts +2 -2
- package/dist/content/consts.d.ts +16 -2
- package/dist/content/consts.js +32 -2
- package/dist/content/content-layer.d.ts +40 -0
- package/dist/content/content-layer.js +253 -0
- package/dist/content/data-store.d.ts +114 -0
- package/dist/content/data-store.js +323 -0
- package/dist/content/loaders/file.d.ts +7 -0
- package/dist/content/loaders/file.js +72 -0
- package/dist/content/loaders/glob.d.ts +25 -0
- package/dist/content/loaders/glob.js +218 -0
- package/dist/content/loaders/index.d.ts +3 -0
- package/dist/content/loaders/index.js +7 -0
- package/dist/content/loaders/types.d.ts +36 -0
- package/dist/content/loaders/types.js +0 -0
- package/dist/content/runtime.d.ts +46 -8
- package/dist/content/runtime.js +225 -31
- package/dist/content/types-generator.js +125 -35
- package/dist/content/utils.d.ts +306 -2
- package/dist/content/utils.js +93 -7
- package/dist/content/vite-plugin-content-assets.js +9 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +94 -2
- package/dist/core/build/index.js +14 -7
- package/dist/core/build/plugins/plugin-ssr.js +32 -4
- package/dist/core/config/config.d.ts +2 -5
- package/dist/core/config/config.js +0 -12
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/index.js +0 -2
- package/dist/core/config/schema.d.ts +34 -0
- package/dist/core/config/schema.js +6 -2
- package/dist/core/config/settings.js +5 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +1 -1
- package/dist/core/dev/container.js +2 -1
- package/dist/core/dev/dev.js +34 -2
- package/dist/core/dev/restart.js +25 -10
- package/dist/core/errors/errors-data.d.ts +21 -0
- package/dist/core/errors/errors-data.js +13 -0
- package/dist/core/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/sync/constants.d.ts +1 -0
- package/dist/core/sync/constants.js +4 -0
- package/dist/core/sync/index.d.ts +12 -4
- package/dist/core/sync/index.js +56 -25
- package/dist/core/sync/write-files.d.ts +4 -0
- package/dist/core/sync/write-files.js +69 -0
- package/dist/core/util.js +1 -1
- package/dist/env/sync.js +6 -4
- package/dist/integrations/hooks.d.ts +7 -1
- package/dist/integrations/hooks.js +54 -0
- package/dist/preferences/index.d.ts +1 -1
- package/dist/preferences/index.js +2 -2
- package/dist/runtime/server/render/server-islands.js +2 -1
- package/dist/vite-plugin-env/index.d.ts +3 -1
- package/dist/vite-plugin-env/index.js +11 -1
- package/dist/vite-plugin-markdown/content-entry-type.js +25 -2
- package/dist/vite-plugin-scanner/index.js +15 -5
- package/package.json +9 -4
- package/templates/content/module.mjs +6 -1
- package/templates/content/types.d.ts +18 -5
- package/types/content.d.ts +34 -1
- package/dist/core/sync/setup-env-ts.d.ts +0 -8
- package/dist/core/sync/setup-env-ts.js +0 -79
package/dist/content/utils.d.ts
CHANGED
|
@@ -37,6 +37,126 @@ declare const collectionConfigParser: z.ZodUnion<[z.ZodObject<{
|
|
|
37
37
|
}, {
|
|
38
38
|
type: "data";
|
|
39
39
|
schema?: any;
|
|
40
|
+
}>, z.ZodObject<{
|
|
41
|
+
type: z.ZodLiteral<"content_layer">;
|
|
42
|
+
schema: z.ZodOptional<z.ZodAny>;
|
|
43
|
+
loader: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnion<[z.ZodArray<z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
}, "strip", z.ZodUnknown, z.objectOutputType<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
}, z.ZodUnknown, "strip">, z.objectInputType<{
|
|
48
|
+
id: z.ZodString;
|
|
49
|
+
}, z.ZodUnknown, "strip">>, "many">, z.ZodPromise<z.ZodArray<z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
}, "strip", z.ZodUnknown, z.objectOutputType<{
|
|
52
|
+
id: z.ZodString;
|
|
53
|
+
}, z.ZodUnknown, "strip">, z.objectInputType<{
|
|
54
|
+
id: z.ZodString;
|
|
55
|
+
}, z.ZodUnknown, "strip">>, "many">>]>>, z.ZodObject<{
|
|
56
|
+
name: z.ZodString;
|
|
57
|
+
load: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
|
|
58
|
+
collection: z.ZodString;
|
|
59
|
+
store: z.ZodAny;
|
|
60
|
+
meta: z.ZodAny;
|
|
61
|
+
logger: z.ZodAny;
|
|
62
|
+
settings: z.ZodAny;
|
|
63
|
+
parseData: z.ZodAny;
|
|
64
|
+
generateDigest: z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>;
|
|
65
|
+
watcher: z.ZodOptional<z.ZodAny>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
collection: string;
|
|
68
|
+
generateDigest: (args_0: any) => unknown;
|
|
69
|
+
settings?: any;
|
|
70
|
+
meta?: any;
|
|
71
|
+
logger?: any;
|
|
72
|
+
store?: any;
|
|
73
|
+
parseData?: any;
|
|
74
|
+
watcher?: any;
|
|
75
|
+
}, {
|
|
76
|
+
collection: string;
|
|
77
|
+
generateDigest: (args_0: any) => unknown;
|
|
78
|
+
settings?: any;
|
|
79
|
+
meta?: any;
|
|
80
|
+
logger?: any;
|
|
81
|
+
store?: any;
|
|
82
|
+
parseData?: any;
|
|
83
|
+
watcher?: any;
|
|
84
|
+
}>], null>, z.ZodUnknown>;
|
|
85
|
+
schema: z.ZodOptional<z.ZodAny>;
|
|
86
|
+
render: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>>;
|
|
87
|
+
}, "strip", z.ZodTypeAny, {
|
|
88
|
+
name: string;
|
|
89
|
+
load: (args_0: {
|
|
90
|
+
collection: string;
|
|
91
|
+
generateDigest: (args_0: any) => unknown;
|
|
92
|
+
settings?: any;
|
|
93
|
+
meta?: any;
|
|
94
|
+
logger?: any;
|
|
95
|
+
store?: any;
|
|
96
|
+
parseData?: any;
|
|
97
|
+
watcher?: any;
|
|
98
|
+
}) => unknown;
|
|
99
|
+
schema?: any;
|
|
100
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
101
|
+
}, {
|
|
102
|
+
name: string;
|
|
103
|
+
load: (args_0: {
|
|
104
|
+
collection: string;
|
|
105
|
+
generateDigest: (args_0: any) => unknown;
|
|
106
|
+
settings?: any;
|
|
107
|
+
meta?: any;
|
|
108
|
+
logger?: any;
|
|
109
|
+
store?: any;
|
|
110
|
+
parseData?: any;
|
|
111
|
+
watcher?: any;
|
|
112
|
+
}) => unknown;
|
|
113
|
+
schema?: any;
|
|
114
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
115
|
+
}>]>;
|
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
|
117
|
+
type: "content_layer";
|
|
118
|
+
loader: ((...args: unknown[]) => z.objectOutputType<{
|
|
119
|
+
id: z.ZodString;
|
|
120
|
+
}, z.ZodUnknown, "strip">[] | Promise<z.objectOutputType<{
|
|
121
|
+
id: z.ZodString;
|
|
122
|
+
}, z.ZodUnknown, "strip">[]>) | {
|
|
123
|
+
name: string;
|
|
124
|
+
load: (args_0: {
|
|
125
|
+
collection: string;
|
|
126
|
+
generateDigest: (args_0: any) => unknown;
|
|
127
|
+
settings?: any;
|
|
128
|
+
meta?: any;
|
|
129
|
+
logger?: any;
|
|
130
|
+
store?: any;
|
|
131
|
+
parseData?: any;
|
|
132
|
+
watcher?: any;
|
|
133
|
+
}) => unknown;
|
|
134
|
+
schema?: any;
|
|
135
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
136
|
+
};
|
|
137
|
+
schema?: any;
|
|
138
|
+
}, {
|
|
139
|
+
type: "content_layer";
|
|
140
|
+
loader: ((...args: unknown[]) => z.objectInputType<{
|
|
141
|
+
id: z.ZodString;
|
|
142
|
+
}, z.ZodUnknown, "strip">[] | Promise<z.objectInputType<{
|
|
143
|
+
id: z.ZodString;
|
|
144
|
+
}, z.ZodUnknown, "strip">[]>) | {
|
|
145
|
+
name: string;
|
|
146
|
+
load: (args_0: {
|
|
147
|
+
collection: string;
|
|
148
|
+
generateDigest: (args_0: any) => unknown;
|
|
149
|
+
settings?: any;
|
|
150
|
+
meta?: any;
|
|
151
|
+
logger?: any;
|
|
152
|
+
store?: any;
|
|
153
|
+
parseData?: any;
|
|
154
|
+
watcher?: any;
|
|
155
|
+
}) => unknown;
|
|
156
|
+
schema?: any;
|
|
157
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
158
|
+
};
|
|
159
|
+
schema?: any;
|
|
40
160
|
}>]>;
|
|
41
161
|
declare const contentConfigParser: z.ZodObject<{
|
|
42
162
|
collections: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
|
|
@@ -57,6 +177,126 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
57
177
|
}, {
|
|
58
178
|
type: "data";
|
|
59
179
|
schema?: any;
|
|
180
|
+
}>, z.ZodObject<{
|
|
181
|
+
type: z.ZodLiteral<"content_layer">;
|
|
182
|
+
schema: z.ZodOptional<z.ZodAny>;
|
|
183
|
+
loader: z.ZodUnion<[z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnion<[z.ZodArray<z.ZodObject<{
|
|
184
|
+
id: z.ZodString;
|
|
185
|
+
}, "strip", z.ZodUnknown, z.objectOutputType<{
|
|
186
|
+
id: z.ZodString;
|
|
187
|
+
}, z.ZodUnknown, "strip">, z.objectInputType<{
|
|
188
|
+
id: z.ZodString;
|
|
189
|
+
}, z.ZodUnknown, "strip">>, "many">, z.ZodPromise<z.ZodArray<z.ZodObject<{
|
|
190
|
+
id: z.ZodString;
|
|
191
|
+
}, "strip", z.ZodUnknown, z.objectOutputType<{
|
|
192
|
+
id: z.ZodString;
|
|
193
|
+
}, z.ZodUnknown, "strip">, z.objectInputType<{
|
|
194
|
+
id: z.ZodString;
|
|
195
|
+
}, z.ZodUnknown, "strip">>, "many">>]>>, z.ZodObject<{
|
|
196
|
+
name: z.ZodString;
|
|
197
|
+
load: z.ZodFunction<z.ZodTuple<[z.ZodObject<{
|
|
198
|
+
collection: z.ZodString;
|
|
199
|
+
store: z.ZodAny;
|
|
200
|
+
meta: z.ZodAny;
|
|
201
|
+
logger: z.ZodAny;
|
|
202
|
+
settings: z.ZodAny;
|
|
203
|
+
parseData: z.ZodAny;
|
|
204
|
+
generateDigest: z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>;
|
|
205
|
+
watcher: z.ZodOptional<z.ZodAny>;
|
|
206
|
+
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
collection: string;
|
|
208
|
+
generateDigest: (args_0: any) => unknown;
|
|
209
|
+
settings?: any;
|
|
210
|
+
meta?: any;
|
|
211
|
+
logger?: any;
|
|
212
|
+
store?: any;
|
|
213
|
+
parseData?: any;
|
|
214
|
+
watcher?: any;
|
|
215
|
+
}, {
|
|
216
|
+
collection: string;
|
|
217
|
+
generateDigest: (args_0: any) => unknown;
|
|
218
|
+
settings?: any;
|
|
219
|
+
meta?: any;
|
|
220
|
+
logger?: any;
|
|
221
|
+
store?: any;
|
|
222
|
+
parseData?: any;
|
|
223
|
+
watcher?: any;
|
|
224
|
+
}>], null>, z.ZodUnknown>;
|
|
225
|
+
schema: z.ZodOptional<z.ZodAny>;
|
|
226
|
+
render: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodUnknown>>;
|
|
227
|
+
}, "strip", z.ZodTypeAny, {
|
|
228
|
+
name: string;
|
|
229
|
+
load: (args_0: {
|
|
230
|
+
collection: string;
|
|
231
|
+
generateDigest: (args_0: any) => unknown;
|
|
232
|
+
settings?: any;
|
|
233
|
+
meta?: any;
|
|
234
|
+
logger?: any;
|
|
235
|
+
store?: any;
|
|
236
|
+
parseData?: any;
|
|
237
|
+
watcher?: any;
|
|
238
|
+
}) => unknown;
|
|
239
|
+
schema?: any;
|
|
240
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
241
|
+
}, {
|
|
242
|
+
name: string;
|
|
243
|
+
load: (args_0: {
|
|
244
|
+
collection: string;
|
|
245
|
+
generateDigest: (args_0: any) => unknown;
|
|
246
|
+
settings?: any;
|
|
247
|
+
meta?: any;
|
|
248
|
+
logger?: any;
|
|
249
|
+
store?: any;
|
|
250
|
+
parseData?: any;
|
|
251
|
+
watcher?: any;
|
|
252
|
+
}) => unknown;
|
|
253
|
+
schema?: any;
|
|
254
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
255
|
+
}>]>;
|
|
256
|
+
}, "strip", z.ZodTypeAny, {
|
|
257
|
+
type: "content_layer";
|
|
258
|
+
loader: ((...args: unknown[]) => z.objectOutputType<{
|
|
259
|
+
id: z.ZodString;
|
|
260
|
+
}, z.ZodUnknown, "strip">[] | Promise<z.objectOutputType<{
|
|
261
|
+
id: z.ZodString;
|
|
262
|
+
}, z.ZodUnknown, "strip">[]>) | {
|
|
263
|
+
name: string;
|
|
264
|
+
load: (args_0: {
|
|
265
|
+
collection: string;
|
|
266
|
+
generateDigest: (args_0: any) => unknown;
|
|
267
|
+
settings?: any;
|
|
268
|
+
meta?: any;
|
|
269
|
+
logger?: any;
|
|
270
|
+
store?: any;
|
|
271
|
+
parseData?: any;
|
|
272
|
+
watcher?: any;
|
|
273
|
+
}) => unknown;
|
|
274
|
+
schema?: any;
|
|
275
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
276
|
+
};
|
|
277
|
+
schema?: any;
|
|
278
|
+
}, {
|
|
279
|
+
type: "content_layer";
|
|
280
|
+
loader: ((...args: unknown[]) => z.objectInputType<{
|
|
281
|
+
id: z.ZodString;
|
|
282
|
+
}, z.ZodUnknown, "strip">[] | Promise<z.objectInputType<{
|
|
283
|
+
id: z.ZodString;
|
|
284
|
+
}, z.ZodUnknown, "strip">[]>) | {
|
|
285
|
+
name: string;
|
|
286
|
+
load: (args_0: {
|
|
287
|
+
collection: string;
|
|
288
|
+
generateDigest: (args_0: any) => unknown;
|
|
289
|
+
settings?: any;
|
|
290
|
+
meta?: any;
|
|
291
|
+
logger?: any;
|
|
292
|
+
store?: any;
|
|
293
|
+
parseData?: any;
|
|
294
|
+
watcher?: any;
|
|
295
|
+
}) => unknown;
|
|
296
|
+
schema?: any;
|
|
297
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
298
|
+
};
|
|
299
|
+
schema?: any;
|
|
60
300
|
}>]>>;
|
|
61
301
|
}, "strip", z.ZodTypeAny, {
|
|
62
302
|
collections: Record<string, {
|
|
@@ -65,6 +305,28 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
65
305
|
} | {
|
|
66
306
|
type: "data";
|
|
67
307
|
schema?: any;
|
|
308
|
+
} | {
|
|
309
|
+
type: "content_layer";
|
|
310
|
+
loader: ((...args: unknown[]) => z.objectOutputType<{
|
|
311
|
+
id: z.ZodString;
|
|
312
|
+
}, z.ZodUnknown, "strip">[] | Promise<z.objectOutputType<{
|
|
313
|
+
id: z.ZodString;
|
|
314
|
+
}, z.ZodUnknown, "strip">[]>) | {
|
|
315
|
+
name: string;
|
|
316
|
+
load: (args_0: {
|
|
317
|
+
collection: string;
|
|
318
|
+
generateDigest: (args_0: any) => unknown;
|
|
319
|
+
settings?: any;
|
|
320
|
+
meta?: any;
|
|
321
|
+
logger?: any;
|
|
322
|
+
store?: any;
|
|
323
|
+
parseData?: any;
|
|
324
|
+
watcher?: any;
|
|
325
|
+
}) => unknown;
|
|
326
|
+
schema?: any;
|
|
327
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
328
|
+
};
|
|
329
|
+
schema?: any;
|
|
68
330
|
}>;
|
|
69
331
|
}, {
|
|
70
332
|
collections: Record<string, {
|
|
@@ -73,10 +335,34 @@ declare const contentConfigParser: z.ZodObject<{
|
|
|
73
335
|
} | {
|
|
74
336
|
type: "data";
|
|
75
337
|
schema?: any;
|
|
338
|
+
} | {
|
|
339
|
+
type: "content_layer";
|
|
340
|
+
loader: ((...args: unknown[]) => z.objectInputType<{
|
|
341
|
+
id: z.ZodString;
|
|
342
|
+
}, z.ZodUnknown, "strip">[] | Promise<z.objectInputType<{
|
|
343
|
+
id: z.ZodString;
|
|
344
|
+
}, z.ZodUnknown, "strip">[]>) | {
|
|
345
|
+
name: string;
|
|
346
|
+
load: (args_0: {
|
|
347
|
+
collection: string;
|
|
348
|
+
generateDigest: (args_0: any) => unknown;
|
|
349
|
+
settings?: any;
|
|
350
|
+
meta?: any;
|
|
351
|
+
logger?: any;
|
|
352
|
+
store?: any;
|
|
353
|
+
parseData?: any;
|
|
354
|
+
watcher?: any;
|
|
355
|
+
}) => unknown;
|
|
356
|
+
schema?: any;
|
|
357
|
+
render?: ((args_0: any) => unknown) | undefined;
|
|
358
|
+
};
|
|
359
|
+
schema?: any;
|
|
76
360
|
}>;
|
|
77
361
|
}>;
|
|
78
362
|
export type CollectionConfig = z.infer<typeof collectionConfigParser>;
|
|
79
|
-
export type ContentConfig = z.infer<typeof contentConfigParser
|
|
363
|
+
export type ContentConfig = z.infer<typeof contentConfigParser> & {
|
|
364
|
+
digest?: string;
|
|
365
|
+
};
|
|
80
366
|
type EntryInternal = {
|
|
81
367
|
rawData: string | undefined;
|
|
82
368
|
filePath: string;
|
|
@@ -87,12 +373,21 @@ export declare function parseEntrySlug({ id, collection, generatedSlug, frontmat
|
|
|
87
373
|
generatedSlug: string;
|
|
88
374
|
frontmatterSlug?: unknown;
|
|
89
375
|
}): string;
|
|
376
|
+
export declare function getEntryDataAndImages<TInputData extends Record<string, unknown> = Record<string, unknown>, TOutputData extends TInputData = TInputData>(entry: {
|
|
377
|
+
id: string;
|
|
378
|
+
collection: string;
|
|
379
|
+
unvalidatedData: TInputData;
|
|
380
|
+
_internal: EntryInternal;
|
|
381
|
+
}, collectionConfig: CollectionConfig, shouldEmitFile: boolean, pluginContext?: PluginContext): Promise<{
|
|
382
|
+
data: TOutputData;
|
|
383
|
+
imageImports: Array<string>;
|
|
384
|
+
}>;
|
|
90
385
|
export declare function getEntryData(entry: {
|
|
91
386
|
id: string;
|
|
92
387
|
collection: string;
|
|
93
388
|
unvalidatedData: Record<string, unknown>;
|
|
94
389
|
_internal: EntryInternal;
|
|
95
|
-
}, collectionConfig: CollectionConfig, shouldEmitFile: boolean, pluginContext
|
|
390
|
+
}, collectionConfig: CollectionConfig, shouldEmitFile: boolean, pluginContext?: PluginContext): Promise<Record<string, unknown>>;
|
|
96
391
|
export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
|
|
97
392
|
export declare function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>): string[];
|
|
98
393
|
export declare function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(entryTypes: TEntryType[]): Map<string, TEntryType>;
|
|
@@ -130,6 +425,7 @@ export declare function safeParseFrontmatter(source: string, id?: string): matte
|
|
|
130
425
|
export declare const globalContentConfigObserver: ContentObservable;
|
|
131
426
|
export declare function hasAnyContentFlag(viteId: string): boolean;
|
|
132
427
|
export declare function hasContentFlag(viteId: string, flag: (typeof CONTENT_FLAGS)[number]): boolean;
|
|
428
|
+
export declare function isDeferredModule(viteId: string): boolean;
|
|
133
429
|
export declare function reloadContentConfigObserver({ observer, ...loadContentConfigOpts }: {
|
|
134
430
|
fs: typeof fsMod;
|
|
135
431
|
settings: AstroSettings;
|
|
@@ -181,4 +477,12 @@ export declare function getEntrySlug({ id, collection, generatedSlug, contentEnt
|
|
|
181
477
|
}): Promise<string>;
|
|
182
478
|
export declare function getExtGlob(exts: string[]): string;
|
|
183
479
|
export declare function hasAssetPropagationFlag(id: string): boolean;
|
|
480
|
+
/**
|
|
481
|
+
* Convert a platform path to a posix path.
|
|
482
|
+
*/
|
|
483
|
+
export declare function posixifyPath(filePath: string): string;
|
|
484
|
+
/**
|
|
485
|
+
* Unlike `path.posix.relative`, this function will accept a platform path and return a posix path.
|
|
486
|
+
*/
|
|
487
|
+
export declare function posixRelative(from: string, to: string): string;
|
|
184
488
|
export {};
|
package/dist/content/utils.js
CHANGED
|
@@ -4,10 +4,17 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
4
4
|
import { slug as githubSlug } from "github-slugger";
|
|
5
5
|
import matter from "gray-matter";
|
|
6
6
|
import { normalizePath } from "vite";
|
|
7
|
+
import xxhash from "xxhash-wasm";
|
|
7
8
|
import { z } from "zod";
|
|
8
9
|
import { AstroError, AstroErrorData, MarkdownError, errorMap } from "../core/errors/index.js";
|
|
9
10
|
import { isYAMLException } from "../core/errors/utils.js";
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
CONTENT_FLAGS,
|
|
13
|
+
CONTENT_LAYER_TYPE,
|
|
14
|
+
CONTENT_MODULE_FLAG,
|
|
15
|
+
IMAGE_IMPORT_PREFIX,
|
|
16
|
+
PROPAGATED_ASSET_FLAG
|
|
17
|
+
} from "./consts.js";
|
|
11
18
|
import { createImage } from "./runtime-assets.js";
|
|
12
19
|
const collectionConfigParser = z.union([
|
|
13
20
|
z.object({
|
|
@@ -17,6 +24,50 @@ const collectionConfigParser = z.union([
|
|
|
17
24
|
z.object({
|
|
18
25
|
type: z.literal("data"),
|
|
19
26
|
schema: z.any().optional()
|
|
27
|
+
}),
|
|
28
|
+
z.object({
|
|
29
|
+
type: z.literal(CONTENT_LAYER_TYPE),
|
|
30
|
+
schema: z.any().optional(),
|
|
31
|
+
loader: z.union([
|
|
32
|
+
z.function().returns(
|
|
33
|
+
z.union([
|
|
34
|
+
z.array(
|
|
35
|
+
z.object({
|
|
36
|
+
id: z.string()
|
|
37
|
+
}).catchall(z.unknown())
|
|
38
|
+
),
|
|
39
|
+
z.promise(
|
|
40
|
+
z.array(
|
|
41
|
+
z.object({
|
|
42
|
+
id: z.string()
|
|
43
|
+
}).catchall(z.unknown())
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
])
|
|
47
|
+
),
|
|
48
|
+
z.object({
|
|
49
|
+
name: z.string(),
|
|
50
|
+
load: z.function(
|
|
51
|
+
z.tuple(
|
|
52
|
+
[
|
|
53
|
+
z.object({
|
|
54
|
+
collection: z.string(),
|
|
55
|
+
store: z.any(),
|
|
56
|
+
meta: z.any(),
|
|
57
|
+
logger: z.any(),
|
|
58
|
+
settings: z.any(),
|
|
59
|
+
parseData: z.any(),
|
|
60
|
+
generateDigest: z.function(z.tuple([z.any()], z.string())),
|
|
61
|
+
watcher: z.any().optional()
|
|
62
|
+
})
|
|
63
|
+
],
|
|
64
|
+
z.unknown()
|
|
65
|
+
)
|
|
66
|
+
),
|
|
67
|
+
schema: z.any().optional(),
|
|
68
|
+
render: z.function(z.tuple([z.any()], z.unknown())).optional()
|
|
69
|
+
})
|
|
70
|
+
])
|
|
20
71
|
})
|
|
21
72
|
]);
|
|
22
73
|
const contentConfigParser = z.object({
|
|
@@ -37,19 +88,29 @@ function parseEntrySlug({
|
|
|
37
88
|
});
|
|
38
89
|
}
|
|
39
90
|
}
|
|
40
|
-
async function
|
|
91
|
+
async function getEntryDataAndImages(entry, collectionConfig, shouldEmitFile, pluginContext) {
|
|
41
92
|
let data;
|
|
42
|
-
if (collectionConfig.type === "data") {
|
|
93
|
+
if (collectionConfig.type === "data" || collectionConfig.type === CONTENT_LAYER_TYPE) {
|
|
43
94
|
data = entry.unvalidatedData;
|
|
44
95
|
} else {
|
|
45
96
|
const { slug, ...unvalidatedData } = entry.unvalidatedData;
|
|
46
97
|
data = unvalidatedData;
|
|
47
98
|
}
|
|
48
99
|
let schema = collectionConfig.schema;
|
|
100
|
+
const imageImports = /* @__PURE__ */ new Set();
|
|
49
101
|
if (typeof schema === "function") {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
102
|
+
if (pluginContext) {
|
|
103
|
+
schema = schema({
|
|
104
|
+
image: createImage(pluginContext, shouldEmitFile, entry._internal.filePath)
|
|
105
|
+
});
|
|
106
|
+
} else if (collectionConfig.type === CONTENT_LAYER_TYPE) {
|
|
107
|
+
schema = schema({
|
|
108
|
+
image: () => z.string().transform((val) => {
|
|
109
|
+
imageImports.add(val);
|
|
110
|
+
return `${IMAGE_IMPORT_PREFIX}${val}`;
|
|
111
|
+
})
|
|
112
|
+
});
|
|
113
|
+
}
|
|
53
114
|
}
|
|
54
115
|
if (schema) {
|
|
55
116
|
if (collectionConfig.type === "content" && typeof schema === "object" && "shape" in schema && schema.shape.slug) {
|
|
@@ -88,6 +149,15 @@ async function getEntryData(entry, collectionConfig, shouldEmitFile, pluginConte
|
|
|
88
149
|
throw formattedError;
|
|
89
150
|
}
|
|
90
151
|
}
|
|
152
|
+
return { data, imageImports: Array.from(imageImports) };
|
|
153
|
+
}
|
|
154
|
+
async function getEntryData(entry, collectionConfig, shouldEmitFile, pluginContext) {
|
|
155
|
+
const { data } = await getEntryDataAndImages(
|
|
156
|
+
entry,
|
|
157
|
+
collectionConfig,
|
|
158
|
+
shouldEmitFile,
|
|
159
|
+
pluginContext
|
|
160
|
+
);
|
|
91
161
|
return data;
|
|
92
162
|
}
|
|
93
163
|
function getContentEntryExts(settings) {
|
|
@@ -268,6 +338,10 @@ function hasContentFlag(viteId, flag) {
|
|
|
268
338
|
const flags = new URLSearchParams(viteId.split("?")[1] ?? "");
|
|
269
339
|
return flags.has(flag);
|
|
270
340
|
}
|
|
341
|
+
function isDeferredModule(viteId) {
|
|
342
|
+
const flags = new URLSearchParams(viteId.split("?")[1] ?? "");
|
|
343
|
+
return flags.has(CONTENT_MODULE_FLAG);
|
|
344
|
+
}
|
|
271
345
|
async function loadContentConfig({
|
|
272
346
|
fs,
|
|
273
347
|
settings,
|
|
@@ -282,7 +356,9 @@ async function loadContentConfig({
|
|
|
282
356
|
unparsedConfig = await viteServer.ssrLoadModule(configPathname);
|
|
283
357
|
const config = contentConfigParser.safeParse(unparsedConfig);
|
|
284
358
|
if (config.success) {
|
|
285
|
-
|
|
359
|
+
const hasher = await xxhash();
|
|
360
|
+
const digest = await hasher.h64ToString(await fs.promises.readFile(configPathname, "utf-8"));
|
|
361
|
+
return { ...config.data, digest };
|
|
286
362
|
} else {
|
|
287
363
|
return void 0;
|
|
288
364
|
}
|
|
@@ -383,6 +459,12 @@ function hasAssetPropagationFlag(id) {
|
|
|
383
459
|
return false;
|
|
384
460
|
}
|
|
385
461
|
}
|
|
462
|
+
function posixifyPath(filePath) {
|
|
463
|
+
return filePath.split(path.sep).join("/");
|
|
464
|
+
}
|
|
465
|
+
function posixRelative(from, to) {
|
|
466
|
+
return posixifyPath(path.relative(from, to));
|
|
467
|
+
}
|
|
386
468
|
export {
|
|
387
469
|
contentObservable,
|
|
388
470
|
getContentEntryExts,
|
|
@@ -393,6 +475,7 @@ export {
|
|
|
393
475
|
getEntryCollectionName,
|
|
394
476
|
getEntryConfigByExtMap,
|
|
395
477
|
getEntryData,
|
|
478
|
+
getEntryDataAndImages,
|
|
396
479
|
getEntrySlug,
|
|
397
480
|
getEntryType,
|
|
398
481
|
getExtGlob,
|
|
@@ -401,7 +484,10 @@ export {
|
|
|
401
484
|
hasAnyContentFlag,
|
|
402
485
|
hasAssetPropagationFlag,
|
|
403
486
|
hasContentFlag,
|
|
487
|
+
isDeferredModule,
|
|
404
488
|
parseEntrySlug,
|
|
489
|
+
posixRelative,
|
|
490
|
+
posixifyPath,
|
|
405
491
|
reloadContentConfigObserver,
|
|
406
492
|
reverseSymlink,
|
|
407
493
|
safeParseFrontmatter
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
3
|
import { getAssetsPrefix } from "../assets/utils/getAssetsPrefix.js";
|
|
4
4
|
import { createViteLoader } from "../core/module-loader/vite.js";
|
|
5
5
|
import { joinPaths, prependForwardSlash } from "../core/path.js";
|
|
6
6
|
import { getStylesForURL } from "../vite-plugin-astro-server/css.js";
|
|
7
7
|
import { getScriptsForURL } from "../vite-plugin-astro-server/scripts.js";
|
|
8
8
|
import {
|
|
9
|
+
CONTENT_IMAGE_FLAG,
|
|
9
10
|
CONTENT_RENDER_FLAG,
|
|
10
11
|
LINKS_PLACEHOLDER,
|
|
11
12
|
PROPAGATED_ASSET_FLAG,
|
|
@@ -22,6 +23,13 @@ function astroContentAssetPropagationPlugin({
|
|
|
22
23
|
name: "astro:content-asset-propagation",
|
|
23
24
|
enforce: "pre",
|
|
24
25
|
async resolveId(id, importer, opts) {
|
|
26
|
+
if (hasContentFlag(id, CONTENT_IMAGE_FLAG)) {
|
|
27
|
+
const [base, query] = id.split("?");
|
|
28
|
+
const params = new URLSearchParams(query);
|
|
29
|
+
const importerParam = params.get("importer");
|
|
30
|
+
const importerPath = importerParam ? fileURLToPath(new URL(importerParam, settings.config.root)) : importer;
|
|
31
|
+
return this.resolve(base, importerPath, { skipSelf: true, ...opts });
|
|
32
|
+
}
|
|
25
33
|
if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
|
|
26
34
|
const base = id.split("?")[0];
|
|
27
35
|
for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {
|