Skip to content

Fix Learn Sidebar #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,24 @@ 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) {
currentCategory && categories.push(currentCategory)
if (currentCategory) {
if (!(currentCategory.name in categoriesMap)) {
categoriesMap[currentCategory.name] = currentCategory
}
}
currentCategory = {
name: category,
links: [],
Expand All @@ -165,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);
})
)

Expand Down