Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gatsby GraphQL custom date formatString

I have this:

export const pageQuery = graphql`
  query {
    site {
      siteMetadata {
        title
      }
    }
    allMdx(sort: { fields: [frontmatter___date], order: DESC }) {
      edges {
        node {
          excerpt
          fields {
            slug
          }
          frontmatter {
            date(formatString: "DD 'de'  MMMM, YYYY", locale: "pt")
            title
            description
          }
        }
      }
    }
  }
`

in the line ->> date(formatString: "DD 'de' MMMM, YYYY", locale: "pt") I have to insert strings but this 'de' isnt working. I know I want to display the date like: 25 de March, 2020. But the result is: 25 '32' March, 2020. I know this isnt working, i know why, but I can't make it right. I'm Using Gatsbyjs with graphql

like image 481
Iago Barreto Avatar asked Jan 26 '23 05:01

Iago Barreto


1 Answers

Gatsby relies on moment.js to format dates.

To escape characters in format strings, you can wrap the custom string in square brackets.

date(formatString: "DD [de]  MMMM, YYYY", locale: "pt")
like image 152
ksav Avatar answered Feb 05 '23 07:02

ksav