ChristopherBiscardi / gatsby-mdx

Gatsby+MDX • Transformers, CMS UI Extensions, and Ecosystem Components for ambitious projects
https://gatsby-mdx.netlify.com/
715 stars 100 forks source link

About using node.excerpt onCreateNode #418

Closed artmadeit closed 5 years ago

artmadeit commented 5 years ago

Describe the bug Just as the title says, I have tried to use node.excerpt inside the onCreateNode method of gatsby, however it's value is undefined

To Reproduce Link https://github.com/artmadeit/gatsby-mdx-excerpt-issue It's a very basic example of gatsby mdx using a programmatic page creation

  1. Run the application with: npm run develop
  2. See the console, you will see (apart of the log provided by Gatsby), something like:
    onCreatePage
    Excerpt:
    Trying out MDX
    Excerpt:
    default description

    This refers to https://github.com/artmadeit/gatsby-mdx-excerpt-issue/blob/e9ae2f4575995ce1c7d4adf96ecfc57e6aaf5b96/gatsby-node.js#L60

Meaning that excerpt is undefined , because onCreateNode sets the field.description to node.excerpt, see:

createNodeField({
      node,
      name: "description",
      value: node.excerpt || "default description"
    })

https://github.com/artmadeit/gatsby-mdx-excerpt-issue/blob/e9ae2f4575995ce1c7d4adf96ecfc57e6aaf5b96/gatsby-node.js#L20

  1. You can also access to http://localhost:8000/blog/hi/ to see the same output (description and a excerpt).

Expected behavior Use non-undefined node.excerpt onCreateNode method

Additional context Well, i really haven't read the process of how gatsby-mdx get the excerpt of an mdx file...so is more a question than a bug: Is it possible to use node.excerpt onCreateNode?.

This is useful, for example, If you have an optional description in the frontmatter of your mdx files and you want to use it as a description that one or else use node.excerpt. Something like:

createNodeField({
      node,
      name: "description",
      value: "description" in node.frontmatter? node.frontmatter.description: node.excerpt
   })

Then just access to fields.description in my components, instead of excerpt or frontmatter.description.

Sorry for my bad english, I'm from :peru: , so spanish is what I speak... Anyway, thanks for gatsby-mdx, i've been using since it's beginnings :)