-
Notifications
You must be signed in to change notification settings - Fork 41
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
[help] Acessing data via trasformer-remark #44
Comments
I don't believe we supply data in a way that can be used by the gatsby remark plugins, but this is something that I'd like to add! If you have an idea on how to do it (or code & a PR) that would be great! |
I don't know how to do it, but looks like we only need to specify the mime type of graphcms nodes as text/markdown and the transformer-remark plugins will work. I think source-contentful do this, I saw some projects using remark-images. |
To the best of my knowledge, there's no way to tell via introspection if a post is markdown. I've brought it up in the GraphCMS Slack so while that conversation happens, I've been brainstorming some ways for users to define properties for custom post types.
propertyMap: {
Post: {
body: {
mediaType: 'text/markdown'
}
}
} This would have the benefit of being easy to code for, but introduces another (albeit optional) step for users.
query myConfigQuery {
allPosts {
title
body #= mediaType: text/markdown
date
}
} This would be a bit trickier to program but is definitely more convenient for the user as they have one less configuration option to create -- They just have to comment their already existing query and they're good to go. This, of course, should be a last resort. Ideally we'd be able to get what we need through introspection. But there might not be a way to introspect the appearance of a string field in graphcms. We shall see. @rdela thoughts? |
I am fine with option [2], annotating the query with a comment. @hmeissner in Slack:
Prior art (think these commits are what he refers to above): This is interesting for us, maybe not here, possibly elsewhere:
And here is SO thread on GQL string literal field descriptions vs comments |
You can actually leverage transformer remark for your markdown data pretty easily, the only downside being that we really have no way of knowing which fields are markdown out of the box. To make this work you simply have to specify this in exports.onCreateNode = ({ node, boundActionCreators }) => {
const { createNode } = boundActionCreators
// Reviews here is the node you'd like to create your markdown from
if (node.internal.type === `Reviews`) {
createNode({
id: `md-${node.id}`,
parent: node.id,
children: [],
internal: {
type: `${node.internal.type}Markdown`,
mediaType: `text/markdown`,
content: node.review,
contentDigest: node.internal.contentDigest
}
})
}
} |
Thank you @hmeissner, your solution solved my problem perfectly. |
@rdricco thanks that was kind of you to close the issue, but I’m reopening because I think at the very least we should add something like what Hugo wrote to the readme and adjust the example to be like this. What do you think? |
Yes, at the very least we should include that snippet (or a similar one) here or in the example repo |
Great! I think this example is very useful, maybe we need something like this on Gatsby Docs as this one could be used for other purposes, like merging sources too. |
Thanks @rdricco @hmeissner @Redmega hygraph/gatsby-source-graphcms#44 #3 Also select by ID instead of slug decaporg/gatsby-starter-decap-cms#47 rdela/voidcluster@5bc432b *remarkable*
Relevant source files Closing this issue but feel free to reopen or ping me with ?s Thanks @rdricco + @hmeissner + @Redmega!!! |
Hi, it is possible to access graphcms data via MarkdownRemark? I want to use some remark plugins.
The text was updated successfully, but these errors were encountered: