0

My markdown has some extra remarks and looks like this:

---
path: "/"
date: "2018-10-12"
title: "xxxx"
description: "desccc"
---

some of the text

How can I get the description?

{
  allMarkdownRemark(
    sort: { order: DESC, fields: [frontmatter___date] }
    limit: 1000
  ) {
    edges {
      node {
        frontmatter {
          path
          title
          date
        }
      }
    }
  }
}
Totty.js
  • 15,563
  • 31
  • 103
  • 175

1 Answers1

1

Well, that head part of the markdown document is most commonly referred as frontmatter and is automatically transformed for you so just add the description field to your graphql query inside the frontmatter { ... } structure and use it as your would use the title field for example.

Z. Zlatev
  • 4,757
  • 1
  • 33
  • 37
  • Thanks, that's what I've already tried but I don't have the field there. Are you sure it works out of the box or I need to do something else? Cheers – Totty.js Oct 14 '18 at 01:40
  • Yes, as long as you're using the `gatsby-transformer-remark` and I believe you are. – Z. Zlatev Oct 14 '18 at 11:12
  • Thank you but it doesn't work. I add custom fields and they are undefined. If I remove the "date" I get the "date" as null, therefore I think there is something that knows about what fields is expecting. Any other suggestion? – Totty.js Oct 15 '18 at 10:45
  • Just read another post ( https://stackoverflow.com/questions/48329511/custom-frontmatter-variables-with-markdown-remark-in-gatsby-js ) and I need to restart the gatsby server. – Totty.js Oct 15 '18 at 10:54
  • Lol, I remember leaving a comment on that one – Z. Zlatev Oct 15 '18 at 10:58
  • Yes you did, I forgot to mention haha – Totty.js Oct 15 '18 at 12:05