Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering bullet points results in [object Object] #380

Open
huzailhassan opened this issue Sep 24, 2022 · 0 comments
Open

Rendering bullet points results in [object Object] #380

huzailhassan opened this issue Sep 24, 2022 · 0 comments

Comments

@huzailhassan
Copy link

huzailhassan commented Sep 24, 2022

I am trying to render the bulletpoints, however, the result is the following screenshot, where the bullet point list I want to result becomes [object Object]:

image

The following is my code:

<script>
import { documentToHtmlString } from '@contentful/rich-text-html-renderer'
import { BLOCKS } from '@contentful/rich-text-types'

const contentful = require('contentful')
const config = {
  space: '341l220skrs9',
  accessToken: 'a2kEigyr-81a4J8sPyN1-UNU9R9eO3cPQDdKb0GkRWc',
}
const client = contentful.createClient(config)
export default {
  async asyncData({ params }) {
    const projects = await client.getEntries({
      'fields.slug': params.post,
      content_type: 'blogPost',
    })
    const newProjects = projects.items[0].fields
    console.log('DDD', projects)
    return {
      newProjectss: newProjects,
    }
  },
  data() {
    return {
      options: {
        renderNode: {
          [BLOCKS.EMBEDDED_ASSET]: ({
            data: {
              target: { fields },
            },
          }) =>
            `<img src="${fields.file.url}" height="${fields.file.details.image.height}" width="${fields.file.details.image.width}" alt="${fields.description}"/>`,
          [BLOCKS.UL_LIST]: (node, children) => <ul>{children}</ul>,
          [BLOCKS.OL_LIST]: (node, children) => <ol>{children}</ol>,
          [BLOCKS.LIST_ITEM]: (node, children) => <li>{children}</li>,
        },
      },
    }
  },
  methods: {
    documentToHtmlString(text) {
      return documentToHtmlString(text.body, this.options)
    },
  },
}
</script>

And this is what I am trying to render:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant