Upgrade to Astro 6.1.9 and migrate to content layer API
Moves content config from src/content/config.ts to src/content.config.ts with glob loaders as required by Astro 6. Replaces entry.slug with entry.id and entry.render() with render(entry) throughout. Removes legacy collections option from astro.config.mjs.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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(),
|
||||
description: z.string(),
|
||||
pubDate: z.coerce.date(),
|
||||
updatedDate: z.coerce.date().optional(),
|
||||
heroImage: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
const entries = defineCollection({
|
||||
loader: glob({
|
||||
pattern: '**/*.md',
|
||||
base: './src/content/entries',
|
||||
generateId: ({ entry }) => entry.replace(/^_wiki\//, '').replace(/\.mdx?$/, ''),
|
||||
}),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
pubDate: z.coerce.date().optional(),
|
||||
updatedDate: z.coerce.date().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
const index = defineCollection({
|
||||
loader: glob({ pattern: '**/*.md', base: './src/content/index' }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const collections = { blog, entries, index };
|
||||
@@ -1,32 +0,0 @@
|
||||
import { defineCollection, z } from 'astro:content';
|
||||
|
||||
const blog = defineCollection({
|
||||
// Type-check frontmatter using a schema
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
description: z.string(),
|
||||
// Transform string to Date object
|
||||
pubDate: z.coerce.date(),
|
||||
updatedDate: z.coerce.date().optional(),
|
||||
heroImage: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
const entries = defineCollection({
|
||||
// Type-check frontmatter using a schema
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
// Transform string to Date object
|
||||
pubDate: z.coerce.date().optional(),
|
||||
updatedDate: z.coerce.date().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
const index = defineCollection({
|
||||
// Type-check frontmatter using a schema
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const collections = { blog, entries, index };
|
||||
@@ -1,18 +1,18 @@
|
||||
---
|
||||
import { type CollectionEntry, getCollection } from 'astro:content';
|
||||
import { type CollectionEntry, getCollection, render } from 'astro:content';
|
||||
import BlogPost from '../../layouts/BlogPost.astro';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection('blog');
|
||||
return posts.map((post) => ({
|
||||
params: { slug: post.slug },
|
||||
params: { slug: post.id },
|
||||
props: post,
|
||||
}));
|
||||
}
|
||||
type Props = CollectionEntry<'blog'>;
|
||||
|
||||
const post = Astro.props;
|
||||
const { Content } = await post.render();
|
||||
const { Content } = await render(post);
|
||||
---
|
||||
|
||||
<BlogPost {...post.data}>
|
||||
|
||||
@@ -19,7 +19,7 @@ const posts = (await getCollection('blog')).sort(
|
||||
{posts.map(post => (
|
||||
<li>
|
||||
<a
|
||||
href={`/blog/${post.slug}/`}
|
||||
href={`/blog/${post.id}/`}
|
||||
class="block px-4 py-3 rounded-lg hover:bg-zinc-800 transition-colors group"
|
||||
style="background: var(--bg-card)"
|
||||
>
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
---
|
||||
import { type CollectionEntry, getCollection } from 'astro:content';
|
||||
import { type CollectionEntry, getCollection, render } from 'astro:content';
|
||||
import Entry from '../../layouts/Entry.astro';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const entries = await getCollection('entries');
|
||||
return entries.map((entry) => ({
|
||||
params: { slug: entry.slug },
|
||||
params: { slug: entry.id },
|
||||
props: entry,
|
||||
}));
|
||||
}
|
||||
type Props = CollectionEntry<'entries'>;
|
||||
|
||||
const entry = Astro.props;
|
||||
const { Content, remarkPluginFrontmatter } = await entry.render();
|
||||
const { Content, remarkPluginFrontmatter } = await render(entry);
|
||||
entry.data.frontmatter = remarkPluginFrontmatter;
|
||||
---
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ const entries = (await getCollection('entries'))
|
||||
{entries.map(entry => (
|
||||
<li>
|
||||
<a
|
||||
href={`/entries/${entry.slug}/`}
|
||||
href={`/entries/${entry.id}/`}
|
||||
class="flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-zinc-800 transition-colors group"
|
||||
style="background: var(--bg-card)"
|
||||
>
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function generateBlogBackRefs(thisFileName: string) {
|
||||
}
|
||||
backattrs[typeStr].push({
|
||||
filenames: thatFName,
|
||||
htmlHref: '/blog/' + thatDoc.slug,
|
||||
htmlHref: '/blog/' + thatDoc.id,
|
||||
htmlText: thatFName,
|
||||
});
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export async function generateBlogBackRefs(thisFileName: string) {
|
||||
if (fnameStr === thisFileName) {
|
||||
backlinks.push({
|
||||
linktype: typeStr,
|
||||
htmlHref: '/blog/' + thatDoc.slug,
|
||||
htmlHref: '/blog/' + thatDoc.id,
|
||||
htmlText: thatFName,
|
||||
});
|
||||
}
|
||||
@@ -87,7 +87,7 @@ export async function generateEntryBackRefs(thisFileName: string) {
|
||||
}
|
||||
backattrs[typeStr].push({
|
||||
filenames: thatFName,
|
||||
htmlHref: '/entries/' + thatDoc.slug,
|
||||
htmlHref: '/entries/' + thatDoc.id,
|
||||
htmlText: thatFName,
|
||||
});
|
||||
}
|
||||
@@ -101,7 +101,7 @@ export async function generateEntryBackRefs(thisFileName: string) {
|
||||
if (fnameStr === thisFileName) {
|
||||
backlinks.push({
|
||||
linktype: typeStr,
|
||||
htmlHref: '/entries/' + thatDoc.slug,
|
||||
htmlHref: '/entries/' + thatDoc.id,
|
||||
htmlText: thatFName,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function buildBonsai(): Promise<SemTree | undefined> {
|
||||
for (const node of bonsai.nodes) {
|
||||
const doc: any = allEntryDocs.find((doc) => path.basename(doc.id, '.md') == node.text);
|
||||
if (doc !== undefined) {
|
||||
node.url = '/entries/' + doc.slug;
|
||||
node.url = '/entries/' + doc.id;
|
||||
}
|
||||
}
|
||||
// uncomment if 'virtualBranches' is set to 'false'
|
||||
|
||||
Reference in New Issue
Block a user