#Why cant I change blogpost mdx files to portfolio?
31 messages · Page 1 of 1 (latest)
type DataEntryMap = {
"blog": Record<string, {
id: string;
body?: string;
collection: "blog";
data: InferEntrySchema<"blog">;
rendered?: RenderedContent;
filePath?: string;
}>;
};
You'll need to create a new collection for portfolio in src/content.config.ts. I guess you can copy what is defined for blog and replace blog with portfolio?
I that and it doesnt work
type ContentEntryMap = {
};
type DataEntryMap = {
"blog": Record<string, {
id: string;
body?: string;
collection: "blog";
data: InferEntrySchema<"blog">;
rendered?: RenderedContent;
filePath?: string;
}>;
"portfolio": Record<string, {
id: string;
body?: string;
collection: "portfolio";
data: InferEntrySchema<"portfolio">;
rendered?: RenderedContent;
filePath?: string;
}>;
};
Gone
Given your first screenshot, it seems to recognize the collection.... but the last screenshot seems to tell otherwise. I'm confuse.
And what is gone? The blog?
Sorry I'm trying to understand what is the issue exactly so I can help.
And you have restarted the dev server when I've added the new collection?
Can you show your src/content.config.ts file?
Given your first screenshot, it seems to recognize the collection.... but the last screenshot seems to tell otherwise. I'm confuse.
And what is gone? The blog?
The example posts I dont see them
Sorry I'm trying to understand what is the issue exactly so I can help.
I want 2 blog post... one called blog and the other portfolio
It doesnt link
I'm still a bit confused with your screenshots because I see you're using "blog" in your "portfolio" route, which I assume should fetch the "portfolio" collection?
But this doesn't explain why your blog posts are gone... Are you sure you where on your /blog or /portfolio route in the browser?
Looking at the default blog template, src/content.config.ts contains:
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
// Load Markdown and MDX files in the `src/content/blog/` directory.
loader: glob({ base: './src/content/blog', pattern: '**/*.{md,mdx}' }),
// Type-check frontmatter using a schema
schema: ({ image }) =>
z.object({
title: z.string(),
description: z.string(),
// Transform string to Date object
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
heroImage: image().optional(),
}),
});
export const collections = { blog };
If you want a second collection named portfolio, you'll need the following changes:
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const blog = defineCollection({
// Load Markdown and MDX files in the `src/content/blog/` directory.
loader: glob({ base: './src/content/blog', pattern: '**/*.{md,mdx}' }),
// Type-check frontmatter using a schema
schema: ({ image }) =>
z.object({
title: z.string(),
description: z.string(),
// Transform string to Date object
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
heroImage: image().optional(),
}),
});
+const portfolio = defineCollection({
+ // Load Markdown and MDX files in the `src/content/portfolio/` directory.
+ loader: glob({ base: './src/content/portfolio', pattern: '**/*.{md,mdx}' }),
+ // Type-check frontmatter using a schema
+ schema: ({ image }) =>
+ z.object({
+ title: z.string(),
+ description: z.string(),
+ // Transform string to Date object
+ pubDate: z.coerce.date(),
+ updatedDate: z.coerce.date().optional(),
+ heroImage: image().optional(),
+ }),
+});
-export const collections = { blog };
+export const collections = { blog, portfolio };
Do you have that in your config file?
This is not src/content.config.ts but a file in .astro you've shared, that's why you don't have the same content, and if you're editing .astro/content.d.ts that could explain why your blog posts are gone. You're not supposed to edit it manually, this is an auto generated file.
So I just want a blog and a portfolio what do I need to do?
An extra blog page thing with mdx
Blog and blog 2 after that I just name it portfolio
You'll need to create a new collection in your existing src/content.config.ts with the same addition displayed in my diff above and as explained in "Defining Collections" in the docs.
Once this is done, you'll need to restart the dev server for your collection to be recognized and Astro will generate the proper files in .astro (you don't need to edit them).
And what you have should work...
This is still not src/content.config.ts but the .astro/content.d.ts file from earlier.
Sure, you can copy paste what I've wrote in the RIGHT file, but you might need to remove all the +/- manually.
No problem, glad you were able to solve your issue!