#Why cant I change blogpost mdx files to portfolio?

31 messages · Page 1 of 1 (latest)

true ether
#

Im using:

# Astro Starter Kit: Blog

```sh
npm create astro@latest -- --template blog

Open in StackBlitz
Open with CodeSandbox
Open in GitHub Codespaces


And im unable to have 2 blogpost folders, one is called **blog** and the other is **portfolio**
Why can't I change it?

See screenshot
#
type DataEntryMap = {
        "blog": Record<string, {
  id: string;
  body?: string;
  collection: "blog";
  data: InferEntrySchema<"blog">;
  rendered?: RenderedContent;
  filePath?: string;
}>;

    };
mint pike
#

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?

true ether
# mint pike You'll need to create a new collection for `portfolio` in `src/content.config.ts...

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

mint pike
#

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?

true ether
#

It doesnt link

mint pike
#

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?

true ether
#

What you have is completely different

This is mine

mint pike
#

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.

true ether
#

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

mint pike
#

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...

true ether
#

Copy and paste? or?

#

Mine is wayyyyy different

#

Please itss so different

mint pike
#

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.

true ether
#

It worked by the way, I looked at the wrong file and such

#

Thank you @mint pike

mint pike
#

No problem, glad you were able to solve your issue!