Richer frontmatter support in gatsby-plugin-mdx #16865
Replies: 12 comments
-
Is this still actual? |
Beta Was this translation helpful? Give feedback.
-
Yeah, its still an issue. It would be nice to pass options to grayMatter from the mdx plugin. |
Beta Was this translation helpful? Give feedback.
-
I'd love to see this supported. I had a go at trying to implement it, and it's not easy. I attempted:
EDIT: I have come up with a simple, and non-intrusive solution in the meantime. Instead of using a separator like Now, comes the hacks. I then use <MDXRenderer onlyExcerpt={true}>{node.body}</MDXRenderer> You can configure what gets rendered through changing the wrapper: <MDXProvider
components={{
wrapper: ({ onlyExcerpt = false, children }) => {
let updatedChildren = [ ...children ];
if (onlyExcerpt) {
updatedChildren = children.filter((child, _) => {
return child.props && child.props["data-excerpt"];
});
}
return (
<>{updatedChildren}</>
);
},
})
/> This also guarantees MDX processing on your content, with your options / remark plugins too. I'm sure you can configure this for even finer grain content filtering. |
Beta Was this translation helpful? Give feedback.
-
We should take the same approach as |
Beta Was this translation helpful? Give feedback.
-
@MrSaints Thank you for this tip. I managed to implement much better excerpts for my blog than it used to be with remark. |
Beta Was this translation helpful? Give feedback.
-
Blocker from adopting
|
Beta Was this translation helpful? Give feedback.
-
@joyfulelement I'm not exactly sure why it's not working for you, but there are two things I'd suggest from what I can see (lacking additional context):
In your code:
I'm not sure how you obtained
Instead of:
Try:
Otherwise, it's implemented exactly as how I shared it. And it's currently powering my blog. |
Beta Was this translation helpful? Give feedback.
-
Thanks @MrSaints for the guidance~
The reason I am asking is because I had GraphQL queries deliberately not querying for the full I will give it a try with the
Thanks for the pointer about spacing. Didn't know the spacing could have contributed the issue. I'll try to verify this behaviour as well.
I am grateful to have your validation on the implementation details~ It's a beautiful website you got there 👍 I did notice the link |
Beta Was this translation helpful? Give feedback.
-
Apologies for the late response @joyfulelement.
AFAIK, no. You have to use the body. Because the
I'd see how well it performs before optimising. Personally, didn't have too much of an issue on this front.
Thanks for your kind words. And yes, it is intentional, for now. I'm in the process of cleaning up before I make it public. |
Beta Was this translation helpful? Give feedback.
-
Is there any update here? |
Beta Was this translation helpful? Give feedback.
-
To those who are still looking for a solution until something is implemented in the library itself, you can read my short blog where I gave a fix (temporary) for this: |
Beta Was this translation helpful? Give feedback.
-
If the problem is determining a way to customize content excerpts, why not just add an // This is located in the render function of the excerpt displaying component
const excerpt = post.frontmatter.excerpt && post.frontmatter.excerpt.length > 0
? post.frontmatter.excerpt
: post.excerpt; I'm sure there's good reasons for solving this problem at the resolver level, I just don't know what those are yet. The above approach gets me the desired end result with the least amount of complexity. This may not be the case for everyone with this same issue. I've only tested with text, but it should be easy to use HTML or Markdown in the frontmatter excerpt and render them accordingly. |
Beta Was this translation helpful? Give feedback.
-
Summary
We use gray-matter for gatsby-plugin-mdx frontmatter support. We should passthrough the
excerpt_separator
option.Basic example
We would likely just enable passthrough in the options as such:
Would set this mdx content:
to this result:
Open Questions
Motivation
When porting from other ecosystems it can be easier if we support their frontmatter delimiters and excerpt formats. That was the use case in the original gatsby-mdx issues
ported from ChristopherBiscardi/gatsby-mdx#386
Beta Was this translation helpful? Give feedback.
All reactions