Skip to content

Commit

Permalink
fix(astro): support content/config.mts (#8484)
Browse files Browse the repository at this point in the history
Co-authored-by: Erika <[email protected]>
  • Loading branch information
bb010g and Princesseuh authored Sep 11, 2023
1 parent a6a516d commit 78b82bb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/calm-houses-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

fix(astro): add support for `src/content/config.mts` files
2 changes: 1 addition & 1 deletion packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions packages/astro/test/content-collections.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/content-collections-with-config-mts",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: 10000
---

# Hi there!
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { z, defineCollection } from 'astro:content';

const blog = defineCollection({
schema: z.object({
title: z.string(),
}),
});

export const collections = {
blog
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
import {getEntryBySlug} from "astro:content"
const blogEntry = await getEntryBySlug("blog", "introduction");
---
{blogEntry.data.title}
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78b82bb

Please sign in to comment.