fix(astro): support content/config.mts
(#8484)
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
parent
a6a516d944
commit
78b82bb392
8 changed files with 55 additions and 1 deletions
5
.changeset/calm-houses-carry.md
Normal file
5
.changeset/calm-houses-carry.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
fix(astro): add support for `src/content/config.mts` files
|
|
@ -448,7 +448,7 @@ export function getContentPaths(
|
|||
};
|
||||
}
|
||||
function search(fs: typeof fsMod, srcDir: URL) {
|
||||
const paths = ['config.mjs', 'config.js', 'config.ts'].map(
|
||||
const paths = ['config.mjs', 'config.js', 'config.mts', 'config.ts'].map(
|
||||
(p) => new URL(`./content/${p}`, srcDir)
|
||||
);
|
||||
for (const file of paths) {
|
||||
|
|
|
@ -214,6 +214,20 @@ describe('Content Collections', () => {
|
|||
expect(error).to.include('**title**: Expected type `"string"`, received "number"');
|
||||
});
|
||||
});
|
||||
describe('With config.mts', () => {
|
||||
it("Errors when frontmatter doesn't match schema", async () => {
|
||||
const fixture = await loadFixture({
|
||||
root: './fixtures/content-collections-with-config-mts/',
|
||||
});
|
||||
let error;
|
||||
try {
|
||||
await fixture.build();
|
||||
} catch (e) {
|
||||
error = e.message;
|
||||
}
|
||||
expect(error).to.include('**title**: Expected type `"string"`, received "number"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('With empty markdown file', () => {
|
||||
it('Throws the right error', async () => {
|
||||
|
|
8
packages/astro/test/fixtures/content-collections-with-config-mts/package.json
vendored
Normal file
8
packages/astro/test/fixtures/content-collections-with-config-mts/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "@test/content-collections-with-config-mts",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: 10000
|
||||
---
|
||||
|
||||
# Hi there!
|
11
packages/astro/test/fixtures/content-collections-with-config-mts/src/content/config.mts
vendored
Normal file
11
packages/astro/test/fixtures/content-collections-with-config-mts/src/content/config.mts
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { z, defineCollection } from 'astro:content';
|
||||
|
||||
const blog = defineCollection({
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const collections = {
|
||||
blog
|
||||
}
|
5
packages/astro/test/fixtures/content-collections-with-config-mts/src/pages/index.astro
vendored
Normal file
5
packages/astro/test/fixtures/content-collections-with-config-mts/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
import {getEntryBySlug} from "astro:content"
|
||||
const blogEntry = await getEntryBySlug("blog", "introduction");
|
||||
---
|
||||
{blogEntry.data.title}
|
|
@ -2373,6 +2373,12 @@ importers:
|
|||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/content-collections-with-config-mts:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/content-mixed-errors:
|
||||
dependencies:
|
||||
astro:
|
||||
|
|
Loading…
Reference in a new issue