Skip to content

Language format for the date in GraphQL #3529

@MaralS

Description

@MaralS

Description

For a client, I'm using this amazing framework to build a fast web app. However, I'm beginning with GraphQL. I noticed that the date is formatted to display months in English. I wanted to know which parameters is necessary to display the date in french.

Environment

Gatsby version: 1.1.27
Node.js version: 8.9.3
Operating System: OS X El Capitan 10.11.6

File contents (if changed):

gatsby-node.js:

const path = require('path');

exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators;

const blogPostTemplate = path.resolve(`src/templates/blog-post.js`);

return graphql(`{
allMarkdownRemark(
  sort: { order: DESC, fields: [frontmatter___date] }
  limit: 1000
) {
  edges {
    node {
      excerpt(pruneLength: 250)
      html
      id
      frontmatter {
        date
        path
        title
      
      }
    }
  }
}

}`)
.then(result => {
if (result.errors) {
return Promise.reject(result.errors);
}

        result.data.allMarkdownRemark.edges
            .forEach(({ node }) => {
                createPage({
                    path: node.frontmatter.path,
                    component: blogPostTemplate,
                    context: {} // additional data can be passed via context
                });
            });
    });

}

GraphQL Query :

export const pageQuery = graphql`

query BlogPostByPath($path: String!) {
markdownRemark(frontmatter: { path: { eq: $path } }) {
html
frontmatter {
date(formatString: "DD/MM/YYYY")
path
title

    image{
      childImageSharp{
        sizes(maxWidth: 1000, quality: 100, cropFocus: CENTER, toFormat: JPG) {
            ...GatsbyImageSharpSizes
        }
        responsiveSizes(quality: 70){
          src
          srcSet
        }
      }
    }
  }
}

}
`;

Actual result

I just have the month date like DD/MM/YYYY with numbers like 12/05/2017.

Expected behavior

I wanted to show the date like : 12 mai 2017

Thank you in advance for your help,

kind regards,

Maral.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions