0

Same question as this: GraphQL sorting case insensitive i.e. I need to sort the results of the query alphabetically but it is returning the posts starting with capital letters first, then lowercase. I just want completely alphabetical.

But I don't know how to make the answer in the above work with Gatsby.

My query looks like this:

query {
  allMdx(
    sort: {fields: frontmatter___title, order: ASC}
  ) {
    nodes {
      frontmatter {
        title
        slug
      }
      id
    }
  }
}

My component looks like this:

const AlphabeticalIndex = ({data}) => {
  return (
    <Layout pageTitle="Alphabetical Index">
    <div>
      {
        data.allMdx.nodes.map(node => (
          <p key={node.frontmatter.title} className={listLink}>
            <Link to={"/" + node.frontmatter.slug}>
            {node.frontmatter.title}
            </Link>
          </p>
        ))
      }
      </div>
    </Layout>
  )
}

The site is live and you can see the current result of the query here https://ausdict.translatableenglish.com/entry-index (content warning for swear words).

Thanks for the help.

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
Hibou
  • 1
  • You should sort `data.allMdx.nodes` before mapping it, as described in this answer: https://stackoverflow.com/a/21700845/6808605 – Normal Aug 08 '21 at 05:32
  • Thanks! The answers in that post didn't work, but the overall principle did – Hibou Aug 09 '21 at 06:05

0 Answers0