1

I've added a new page to the config.yml file from the gatsby netlify started repo:

  - name: "pages"
    label: "Pages"
    files:
      - file: "src/pages/CV/index.md"
        label: "CV"
        name: "CV"
        fields:
          - {
              label: "Template Key",
              name: "templateKey",
              widget: "hidden",
              default: "cv-page",
            }
          - { label: "Name", name: "name", widget: "string" }
          - { label: "Portrait", name: "portrait", widget: "image" }
          - label: "Categories"
            name: "categories"
            widget: "list"
            fields:
              - { label: Title, name: title, widget: string }
              - { label: "Body", name: "body", widget: "markdown" }

And then I query for the data in my cv-page component:

export const cvPageQuery = graphql`
  query CVPage($id: String!) {
    markdownRemark(id: { eq: $id }) {
      frontmatter {
        name
        portrait
        categories {
          title
          body
        }
      }
    }
  }
`;

now I would like gatsby-transformer-remark to parse the categories body from markdown to html - but the query is just returning a markdown string (for example body: "* one↵* two↵* three↵* four").

Before when I had the markdown widget directly on the page as a field, I would just query for html outside of frontmatter and the data would be there. Why is this not working with the widget being nested in a list?

Thanks for the help.

EDIT: repo with my code for reference

Miha Šušteršič
  • 9,742
  • 25
  • 92
  • 163

1 Answers1

0

The gatsby-transformer-remark transform will only transform the markdown within the body of your .md file. It does not know to transform fields within your frontmatter.

pages/CV/index.md

---
templateKey: cv-page
name: Miha Šušteršič
portrait: /img/headshot.png
categories:
  - body: |-
      * one
      * two
      * three
      * four
    title: Work experience
  - body: |-
      * one
      * two 
      * three
      * four
    title: Education and training
---

From query:

{
  "markdownRemark": {
    "html": "",
    "frontmatter": {
      "name": "Miha Šušteršič",
      "portrait": "/img/headshot.png",
      "categories": [{
          "title": "Work experience",
          "body": "* one\n* two\n* three\n* four"
        },
        {
          "title": "Education and training",
          "body": "* one\n* two \n* three\n* four"
        }
      ]
    }
  }
}

As you can see from the query results above, your html is empty because the body is empty.

talves
  • 13,993
  • 5
  • 40
  • 63