Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/young-banks-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'astro': major
---

Removes legacy content collection support.

This PR removes a number of APIs and options related to legacy content collections that were deprecated in Astro 5, including:

- The `legacy.collections` option, which was added in Astro 5 and caused the old content collections system to be used instead of the new one.
- Deprecated functions from `astro:content`: `getEntryBySlug` and `getDataEntryById` are both replaced by `getEntry()`, which is a drop-in replacement for both.
- Support for the old `src/content/config.*` file location. You must now use `src/content.config.*`.
- Automatically generating collections when a `src/content/` directory is present and no content config file exists. You must now explicitly define collections in `src/content.config.*`.
- Support for collections without a loader. You must now use the `glob()` loader to create collections from filesystem content. This will also mean that generated entries use the new entry format:
- The `id` field is now a slug, not a filename. You can access the filename via `entry.filePath`, which is the path relative to the site root.
- There is no longer a `slug` field – use `id` instead.
- You can no longer call `entry.render()` on content entries. Use `render(entry)` instead, imported from `astro:content`.

For full details, see [the Astro 6 upgrade guide](https://docs.astro.build/en/guides/upgrade-to/v6/#removed-legacy-content-collections).
24 changes: 21 additions & 3 deletions benchmark/make-project/markdown-cc1.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ ${loremIpsumMd}
new URL(`./src/pages/blog/[...slug].astro`, projectDir),
`\
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';
export async function getStaticPaths() {
const blogEntries = await getCollection('blog');
return blogEntries.map(entry => ({
params: { slug: entry.slug }, props: { entry },
params: { slug: entry.id }, props: { entry },
}));
}
const { entry } = Astro.props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---
<h1>{entry.data.title}</h1>
<Content />
Expand All @@ -52,6 +52,24 @@ const { Content } = await entry.render();

await Promise.all(promises);

await fs.writeFile(
new URL(`./src/content.config.ts`, projectDir),
`\
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
}),
});
export const collections = { blog };
`,
'utf-8',
);

await fs.writeFile(
new URL('./astro.config.js', projectDir),
`\
Expand Down
2 changes: 1 addition & 1 deletion benchmark/make-project/markdown-cc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ${loremIpsumMd}
}

await fs.writeFile(
new URL(`./src/content/config.ts`, projectDir),
new URL(`./src/content.config.ts`, projectDir),
/*ts */ `
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
Expand Down
24 changes: 21 additions & 3 deletions benchmark/make-project/mdx-cc1.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ ${loremIpsumMd}
new URL(`./src/pages/blog/[...slug].astro`, projectDir),
`\
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';
export async function getStaticPaths() {
const blogEntries = await getCollection('blog');
return blogEntries.map(entry => ({
params: { slug: entry.slug }, props: { entry },
params: { slug: entry.id }, props: { entry },
}));
}
const { entry } = Astro.props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---
<h1>{entry.data.title}</h1>
<Content />
Expand All @@ -52,6 +52,24 @@ const { Content } = await entry.render();

await Promise.all(promises);

await fs.writeFile(
new URL(`./src/content.config.ts`, projectDir),
`\
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
}),
});
export const collections = { blog };
`,
'utf-8',
);

await fs.writeFile(
new URL('./astro.config.js', projectDir),
`\
Expand Down
2 changes: 1 addition & 1 deletion benchmark/make-project/mdx-cc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ${loremIpsumMd}
}

await fs.writeFile(
new URL(`./src/content/config.ts`, projectDir),
new URL(`./src/content.config.ts`, projectDir),
/*ts */ `
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
Expand Down
24 changes: 21 additions & 3 deletions benchmark/make-project/memory-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ ${loremIpsum}
new URL(`./src/pages/blog/[...slug].astro`, projectDir),
`\
---
import { getCollection } from 'astro:content';
import { getCollection, render } from 'astro:content';
export async function getStaticPaths() {
const blogEntries = await getCollection('blog');
return blogEntries.map(entry => ({
params: { slug: entry.slug }, props: { entry },
params: { slug: entry.id }, props: { entry },
}));
}
const { entry } = Astro.props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---
<h1>{entry.data.title}</h1>
<Content />
Expand All @@ -68,6 +68,24 @@ const { Content } = await entry.render();

await Promise.all(promises);

await fs.writeFile(
new URL(`./src/content.config.ts`, projectDir),
`\
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
}),
});
export const collections = { blog };
`,
'utf-8',
);

await fs.writeFile(
new URL('./astro.config.js', projectDir),
`\
Expand Down
5 changes: 4 additions & 1 deletion examples/with-markdoc/src/content.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';

export const collections = {
docs: defineCollection({}),
docs: defineCollection({
loader: glob({ pattern: '**/*.mdoc', base: './src/content/docs' }),
}),
};
4 changes: 2 additions & 2 deletions examples/with-markdoc/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
import { getEntry } from 'astro:content';
import { getEntry, render } from 'astro:content';
import Layout from '../layouts/Layout.astro';
const intro = await getEntry('docs', 'intro');
if (!intro) {
return Astro.redirect('/404');
}
const { Content } = await intro.render();
const { Content } = await render(intro);
---

<Layout title={intro.data.title}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';

const blog = defineCollection({
type: 'content',
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
// Type-check frontmatter using a schema
schema: z.object({
title: z.string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';

const blog = defineCollection({
type: 'content',
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
// Type-check frontmatter using a schema
schema: z.object({
title: z.string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineCollection } from "astro:content";
import { glob } from "astro/loaders";


const posts = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/posts' }),
});

export const collections = { posts };

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import { getEntryBySlug } from 'astro:content'
import { getEntry, render } from 'astro:content'
const post = await getEntryBySlug('posts', 'post-1')
const { Content } = await post.render();
const post = await getEntry('posts', 'post-1')
const { Content } = await render(post);
---

<Content/>
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
import type { CollectionEntry } from 'astro:content';
import { render } from 'astro:content';
type Props = {
entry: CollectionEntry<'generated'>;
}
const { entry } = Astro.props as Props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---

<Content />
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
import type { CollectionEntry } from 'astro:content';
import { render } from 'astro:content';
import { Aside, Heading, HydratedLikeButton, LikeButton } from '@performance/utils';
type Props = {
entry: CollectionEntry<'generated'>;
}
const { entry } = Astro.props as Props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---

{entry.data.type === 'with-astro-components'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
import type { CollectionEntry } from 'astro:content';
import { render } from 'astro:content';
import Title from './Title.astro';
type Props = {
entry: CollectionEntry<'generated'>;
}
const { entry } = Astro.props as Props;
const { Content } = await entry.render();
const { Content } = await render(entry);
---

{entry.data.type === 'with-astro-components'
Expand Down
13 changes: 1 addition & 12 deletions packages/astro/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,17 @@ export function getViteConfig(

// Use dynamic import to avoid pulling in deps unless used
const [
fs,
{ mergeConfig },
{ createNodeLogger },
{ resolveConfig, createSettings },
{ createVite },
{ runHookConfigSetup, runHookConfigDone },
{ astroContentListenPlugin },
] = await Promise.all([
import('node:fs'),
import('vite'),
import('../core/config/logging.js'),
import('../core/config/index.js'),
import('../core/create-vite.js'),
import('../integrations/hooks.js'),
import('./vite-plugin-content-listen.js'),
]);
const logger = createNodeLogger(inlineAstroConfig);
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
Expand All @@ -58,14 +54,7 @@ export function getViteConfig(
const routesList = await createRoutesList({ settings }, logger);
const manifest = createDevelopmentManifest(settings);
const viteConfig = await createVite(
{
plugins: config.legacy.collections
? [
// Initialize the content listener
astroContentListenPlugin({ settings, logger, fs }),
]
: [],
},
{},
{ settings, command: cmd, logger, mode, sync: false, manifest, routesList },
);
await runHookConfigDone({ settings, logger });
Expand Down
41 changes: 0 additions & 41 deletions packages/astro/src/config/vite-plugin-content-listen.ts

This file was deleted.

Loading
Loading