From 1b6ad56edabd9e6979e53a1b6fe55b8cebebdae5 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 4 Nov 2020 10:29:45 +0300 Subject: [PATCH 1/3] Fix Learn Sidebar --- gatsby-node.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gatsby-node.js b/gatsby-node.js index 9f0a7139cb..c6f164fbd4 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -148,7 +148,6 @@ exports.createPages = async ({ graphql, actions }) => { const { category: definedCategory, next: definedNextPageUrl } = frontmatter let category = definedCategory || folder if (!currentCategory || category !== currentCategory.name) { - currentCategory && categories.push(currentCategory) currentCategory = { name: category, links: [], From ff651ae71cf751b2fdc87be29e54c6316821a72c Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 4 Nov 2020 13:25:02 +0300 Subject: [PATCH 2/3] Another attempt --- gatsby-node.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gatsby-node.js b/gatsby-node.js index c6f164fbd4..1ec448e564 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -148,6 +148,9 @@ exports.createPages = async ({ graphql, actions }) => { const { category: definedCategory, next: definedNextPageUrl } = frontmatter let category = definedCategory || folder if (!currentCategory || category !== currentCategory.name) { + if (currentCategory) { + categories.push(currentCategory); + } currentCategory = { name: category, links: [], From 3dfb1ccd4dff44a635e530a623fc010991d35021 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 4 Nov 2020 13:47:42 +0300 Subject: [PATCH 3/3] Force deduplication --- gatsby-node.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 1ec448e564..1f01018018 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -138,18 +138,23 @@ exports.createPages = async ({ graphql, actions }) => { throw new Error(`First page not found in ${folder}`) } - let categories = [] + let categoriesMap = {} let currentCategory = null let page = firstPage let i = 0 while (page && i++ < 1000) { const { frontmatter } = page - const { category: definedCategory, next: definedNextPageUrl } = frontmatter + const { + category: definedCategory, + next: definedNextPageUrl, + } = frontmatter let category = definedCategory || folder if (!currentCategory || category !== currentCategory.name) { if (currentCategory) { - categories.push(currentCategory); + if (!(currentCategory.name in categoriesMap)) { + categoriesMap[currentCategory.name] = currentCategory + } } currentCategory = { name: category, @@ -167,9 +172,11 @@ exports.createPages = async ({ graphql, actions }) => { } } - categories.push(currentCategory) + if (!(currentCategory.name in categoriesMap)) { + categoriesMap[currentCategory.name] = currentCategory + } - sideBardata[folder] = categories + sideBardata[folder] = Object.values(categoriesMap); }) )