Skip to content

Commit

Permalink
chore(nextra-theme-blog): refactor traverse.ts (#523)
Browse files Browse the repository at this point in the history
* chore(nextra-theme-blog): refactor `traverse.ts`

* add changeset
  • Loading branch information
Dimitri POSTOLOV committed Jul 22, 2022
1 parent 7053959 commit 4edca5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-toes-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nextra-theme-blog': patch
---

chore(nextra-theme-blog): refactor `traverse.ts`
11 changes: 6 additions & 5 deletions packages/nextra-theme-blog/src/utils/traverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ export default function traverse(
pageMap: PageMapItem[],
matcher: (page: PageMapItem) => boolean | void
): PageMapItem | null {
for (let i = 0; i < pageMap.length; i++) {
if (matcher(pageMap[i])) {
return pageMap[i]
for (const pageMapItem of pageMap) {
if (matcher(pageMapItem)) {
return pageMapItem
}
}
for (let i = 0; i < pageMap.length; i++) {
const { children } = pageMap[i]

for (const pageMapItem of pageMap) {
const { children } = pageMapItem
if (children) {
const matched = traverse(children, matcher)
if (matched) {
Expand Down

0 comments on commit 4edca5e

Please sign in to comment.