From bcb03a6c53f2563138726f3040c53703df0e44af Mon Sep 17 00:00:00 2001 From: Anthony Marcar Date: Fri, 23 Nov 2018 04:29:48 +1100 Subject: [PATCH] add secondary fields to www query sorts (#10085) While working on loki (#9919), I've run into lots of fun edge cases to do with sorting. One is that some connection queries specify a sort order, but some returned fields have the same value for the sort field. The behavior here is undefined, but by default sift will order by the order they were added to Gatsby. While that's not a terrible default, it makes testing sift and loki compatibility hard, since loki has undefined ordering for this case. So this PR adds a specific secondary sort key to various `www` queries, mainly for the purpose of testing sift/loki compatibility, but also because it makes sense. --- www/gatsby-node.js | 2 +- www/src/pages/index.js | 3 ++- www/src/templates/tags.js | 2 +- www/src/templates/template-blog-list.js | 2 +- www/src/templates/template-contributor-page.js | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/www/gatsby-node.js b/www/gatsby-node.js index a274256641e24..5e73aa91b9252 100644 --- a/www/gatsby-node.js +++ b/www/gatsby-node.js @@ -144,7 +144,7 @@ exports.createPages = ({ graphql, actions }) => { graphql(` query { allMarkdownRemark( - sort: { order: DESC, fields: [frontmatter___date] } + sort: { order: DESC, fields: [frontmatter___date, fields___slug] } limit: 10000 filter: { fileAbsolutePath: { ne: null } } ) { diff --git a/www/src/pages/index.js b/www/src/pages/index.js index 620134ea78c2d..1de1fa9eadfe8 100644 --- a/www/src/pages/index.js +++ b/www/src/pages/index.js @@ -301,7 +301,7 @@ export const pageQuery = graphql` } } allMarkdownRemark( - sort: { order: DESC, fields: [frontmatter___date] } + sort: { order: DESC, fields: [frontmatter___date, fields___slug] } limit: 3 filter: { frontmatter: { draft: { ne: true } } @@ -319,6 +319,7 @@ export const pageQuery = graphql` filter: { fields: { starterShowcase: { slug: { in: $featuredStarters } } } } + sort: { fields: [fields___starterShowcase___slug] } ) { edges { node { diff --git a/www/src/templates/tags.js b/www/src/templates/tags.js index eae1d5840b124..e0353071fdec3 100644 --- a/www/src/templates/tags.js +++ b/www/src/templates/tags.js @@ -61,7 +61,7 @@ export const pageQuery = graphql` query($tag: String) { allMarkdownRemark( limit: 2000 - sort: { fields: [frontmatter___date], order: DESC } + sort: { fields: [frontmatter___date, fields___slug], order: DESC } filter: { frontmatter: { tags: { in: [$tag] } } fileAbsolutePath: { regex: "/docs.blog/" } diff --git a/www/src/templates/template-blog-list.js b/www/src/templates/template-blog-list.js index 22859a6864cce..d38971a732965 100644 --- a/www/src/templates/template-blog-list.js +++ b/www/src/templates/template-blog-list.js @@ -112,7 +112,7 @@ export default BlogPostsIndex export const pageQuery = graphql` query blogListQuery($skip: Int!, $limit: Int!) { allMarkdownRemark( - sort: { order: DESC, fields: [frontmatter___date] } + sort: { order: DESC, fields: [frontmatter___date, fields___slug] } filter: { frontmatter: { draft: { ne: true } } fileAbsolutePath: { regex: "/docs.blog/" } diff --git a/www/src/templates/template-contributor-page.js b/www/src/templates/template-contributor-page.js index c36caf6a479db..6bb6691622f8a 100644 --- a/www/src/templates/template-contributor-page.js +++ b/www/src/templates/template-contributor-page.js @@ -105,7 +105,7 @@ export const pageQuery = graphql` } } allMarkdownRemark( - sort: { order: DESC, fields: [frontmatter___date] } + sort: { order: DESC, fields: [frontmatter___date, fields___slug] } filter: { fileAbsolutePath: { regex: "/blog/" } frontmatter: { draft: { ne: true } }