forked from chromaui/learnstorybook.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simply don't render a tocEntry if we don't yet have a translation
- Loading branch information
Tom Coleman
committed
Sep 5, 2018
1 parent
e89ae99
commit 033430d
Showing
2 changed files
with
11 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
export default function tocEntries(toc, pages) { | ||
return toc.map(slug => { | ||
const node = pages.edges.map(e => e.node).find(({ fields }) => fields.chapter === slug); | ||
return toc | ||
.map(slug => { | ||
const node = pages.edges.map(e => e.node).find(({ fields }) => fields.chapter === slug); | ||
|
||
if (!node) { | ||
throw new Error( | ||
`Didn't find chapter for slug:"${slug}" -- is the config's TOC in sync with the chapters?` | ||
); | ||
} | ||
const { tocTitle, title, description } = node.frontmatter; | ||
// Just don't include a sidebar link if we do not have this chapter | ||
if (!node) { | ||
return null; | ||
} | ||
const { tocTitle, title, description } = node.frontmatter; | ||
|
||
return { slug: node.fields.slug, title: tocTitle || title, description }; | ||
}); | ||
return { slug: node.fields.slug, title: tocTitle || title, description }; | ||
}) | ||
.filter(e => !!e); | ||
} |