Skip to content

Commit 3dfb1cc

Browse files
committed
Force deduplication
1 parent ff651ae commit 3dfb1cc

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

gatsby-node.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,23 @@ 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) {
151154
if (currentCategory) {
152-
categories.push(currentCategory);
155+
if (!(currentCategory.name in categoriesMap)) {
156+
categoriesMap[currentCategory.name] = currentCategory
157+
}
153158
}
154159
currentCategory = {
155160
name: category,
@@ -167,9 +172,11 @@ exports.createPages = async ({ graphql, actions }) => {
167172
}
168173
}
169174

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

172-
sideBardata[folder] = categories
179+
sideBardata[folder] = Object.values(categoriesMap);
173180
})
174181
)
175182

0 commit comments

Comments
 (0)