sdorra / content-collections

Transform your content into type-safe data collections
https://content-collections.dev
MIT License
423 stars 18 forks source link

The content is not displaying on the right way #193

Closed Kinfe123 closed 2 months ago

Kinfe123 commented 2 months ago

this for displaying the markdownx <MDXContent code={post.body} /> this for contentcollection config -

const posts = defineCollection({
  name: "Blogs",
  directory: "content/blogs",
  include: "*.mdx",
  schema: (z) => ({
    title: z.string(),
    description: z.string(),
    date: z.coerce.date(),
    published: z.boolean(),
    image: z.string(),
    authors: z.array(z.string())
  }),
  transform: async (document, context) => {
    const body = await compileMDX(context, document);
    return {
      ...document,
      body,
    };
  },
});

i also have used it in combination with rehype and remark plugin from fumadocs-core but the contnt is being displayed like the image below. is there any mistake i made here ? image

sdorra commented 2 months ago

Can you double check if the imports are correct? Does the imports for MDXContent and compileMDX come from "@content-collections/*" packages? How does the body field look in .content-collections/generated/allPosts.js?

Kinfe123 commented 2 months ago

yeah it is imported from the right packate and i crossed checked that , i also even checked the generated file and it body do have js in it but when passing to the MdxContent component that u export from react fm it is displaying like the abov one

Kinfe123 commented 2 months ago

or let me try it with html transformer if that works out generating html.

sdorra commented 2 months ago

@Kinfe123 is the repository public? Or can you give me access to it? I would like to take a look at the problem myself.

AbePlays commented 2 months ago

@Kinfe123 FWIW I have this content-collections config that works for me.

import { defineCollection, defineConfig } from '@content-collections/core'
import { compileMDX } from '@content-collections/mdx'
import rehypePrettyCode from 'rehype-pretty-code'

export const posts = defineCollection({
  name: 'posts',
  directory: 'content/writing',
  include: '*.mdx',
  schema: (z) => ({
    title: z.string(),
    description: z.string(),
    publishedAt: z.string(),
  }),
  transform: async (document, context) => {
    const mdx = await compileMDX(context, document, {
      rehypePlugins: [[rehypePrettyCode, { theme: 'github-dark-dimmed' }]],
    })
    return { ...document, mdx }
  },
})

export default defineConfig({
  collections: [posts],
})
sdorra commented 2 months ago

@Kinfe123 the code you have posted looks correct, but it is possible that you've documentation issue #198

Can you double check that you use body and not content, because if you use the content instead the result looks exactly as in your screenshot.

Kinfe123 commented 2 months ago

Now it is working by injecting html transformed file to in the Jsx as dangerouslySetInnerHTML

sdorra commented 2 months ago

I'm closing this issue for now, but it should also work with compileMDX. If you can provide me access to a repository where I can reproduce the issue, please reopen the issue, and I'll take a look.