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

support also non-file markdown remark nodes #43

Open
rburgst opened this issue Sep 10, 2020 · 1 comment · May be fixed by #46
Open

support also non-file markdown remark nodes #43

rburgst opened this issue Sep 10, 2020 · 1 comment · May be fixed by #46
Labels
enhancement New feature or request

Comments

@rburgst
Copy link

rburgst commented Sep 10, 2020

Currently it is not easily possible to have markdown in frontmatter tags while using this plugin (e.g. using netlifyCMS with a markdown fields other than Body).
Currently I am creating new nodes for these frontmatter fields

exports.onCreateNode = async ({ node, actions, getNode }) => {
  const { createNode, createNodeField } = actions;

  if (node.internal.type === `MarkdownRemark`) {
    if (node.frontmatter && node.frontmatter.myMarkDownField) {
      const infoNode = await createNode({
        id: `md-${node.id}-info`,
        parent: node.id,
        children: [],
        internal: {
          type: `InfoMarkdown`,
          mediaType: `text/markdown`,
          content: node.frontmatter.myMarkDownField,
          contentDigest: node.internal.contentDigest,
        },
      });

(similar to the suggestion here hygraph/gatsby-source-graphcms#44 (comment))

However transformer remark only copies the absolutePath in case its a File node (which it clearly isnt).
So I would need some way to indicate the absolute path in the remark node or maybe have some other field conveying the path.
Currently the code only works if the markdown node has a fileAbsolutePath (see https://github.com/danielmahon/gatsby-remark-relative-images/blob/master/src/on-create-node.ts#L29), which is not the case for me and therefore the plugin crashes currently.


"gatsby-remark-relative-images" threw an error while running the onCreateNode lifecycle:

The "path" argument must be of type string. Received type undefined



  Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

  - validators.js:112 validateString
    internal/validators.js:112:11

  - on-create-node.js:15 Object.exports.onCreateNode
    [gatsby-starter-netlify-cms]/[gatsby-remark-relative-images]/dist/on-create-node.js:15:42

  - api-runner-node.js:330 runAPI
    [gatsby-starter-netlify-cms]/[gatsby]/src/utils/api-runner-node.js:330:22

  - api-runner-node.js:440 Promise.catch.decorateEvent.pluginName
    [gatsby-starter-netlify-cms]/[gatsby]/src/utils/api-runner-node.js:440:17

  - From previous event:

  - api-runner-node.js:440 Promise.catch.decorateEvent.pluginName
    [gatsby-starter-netlify-cms]/[gatsby]/src/utils/api-runner-node.js:440:9

  - From previous event:

  - api-runner-node.js:439
    [gatsby-starter-netlify-cms]/[gatsby]/src/utils/api-runner-node.js:439:14
@danielmahon danielmahon added the enhancement New feature or request label Sep 10, 2020
rburgst pushed a commit to rburgst/gatsby-remark-relative-images that referenced this issue Sep 12, 2020
in case you created markdown nodes
programmatically (e.g. since you want
to process markdown content in
frontmatter fields), you can
 now provide a custom resolver function
that calculates the correct path for
the markdown content.
Fixes danielmahon#43
@rburgst rburgst linked a pull request Sep 12, 2020 that will close this issue
@rburgst
Copy link
Author

rburgst commented Nov 14, 2020

I added a PR fixing this months ago, any chance to get this merged?

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

Successfully merging a pull request may close this issue.

2 participants