Skip to content

Commit eb02094

Browse files
committed
Merge pull request graphql#940 from ardatan/update-dependencies
Update dependencies
1 parent baa877c commit eb02094

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

gatsby-node.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,24 @@ exports.createPages = async ({ graphql, actions }) => {
138138
throw new Error(`First page not found in ${folder}`)
139139
}
140140

141-
let categories = []
141+
let categoriesMap = {}
142142
let currentCategory = null
143143

144144
let page = firstPage
145145
let i = 0
146146
while (page && i++ < 1000) {
147147
const { frontmatter } = page
148-
const { category: definedCategory, next: definedNextPageUrl } = frontmatter
148+
const {
149+
category: definedCategory,
150+
next: definedNextPageUrl,
151+
} = frontmatter
149152
let category = definedCategory || folder
150153
if (!currentCategory || category !== currentCategory.name) {
151-
currentCategory && categories.push(currentCategory)
154+
if (currentCategory) {
155+
if (!(currentCategory.name in categoriesMap)) {
156+
categoriesMap[currentCategory.name] = currentCategory
157+
}
158+
}
152159
currentCategory = {
153160
name: category,
154161
links: [],
@@ -165,9 +172,11 @@ exports.createPages = async ({ graphql, actions }) => {
165172
}
166173
}
167174

168-
categories.push(currentCategory)
175+
if (!(currentCategory.name in categoriesMap)) {
176+
categoriesMap[currentCategory.name] = currentCategory
177+
}
169178

170-
sideBardata[folder] = categories
179+
sideBardata[folder] = Object.values(categoriesMap);
171180
})
172181
)
173182

0 commit comments

Comments
 (0)