GraphQL 自定义日期和格式字符串

Iag*_*eto 3 javascript date-formatting graphql template-literals gatsby

我有这个:

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
          }
        }
      }
    }
  }
`
Run Code Online (Sandbox Code Playgroud)

在该行中 ->> date(formatString: "DD 'de' MMMM, YYYY", locale: "pt") 我必须插入字符串,但此“de”不起作用。我知道我想显示这样的日期: 25 de March, 2020. 但结果是: 25 '32' March, 2020. 我知道这行不通,我知道为什么,但我做对了。我正在使用 Gatsbyjs 和 graphql

ksa*_*sav 5

Gatsby 依赖于moment.js 来格式化日期

要转义格式字符串中的字符,您可以将字符括在方括号中。

date(formatString: "DD [de]  MMMM, YYYY", locale: "pt")
Run Code Online (Sandbox Code Playgroud)