-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
101 additions
and
49 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import { Link } from 'gatsby'; | ||
|
||
function getLevels(nodes) { | ||
const potentialValues = []; | ||
nodes.forEach((node) => { | ||
if (!potentialValues.includes(node.frontmatter.level)) { | ||
potentialValues.push(node.frontmatter.level); | ||
} | ||
}); | ||
return potentialValues; | ||
} | ||
|
||
const ExerciseNav = ({ location, nodes, toc }) => { | ||
const levels = getLevels(nodes); | ||
|
||
const ExerciseListItems = ({ location, nodes, toc }) => { | ||
return nodes.map((node) => { | ||
const current = location.pathname.includes(node.fields.slug); | ||
const title = node.frontmatter.title; | ||
return ( | ||
<li className={current ? 'current' : ''}> | ||
<Link to={node.fields.slug}> | ||
{node.frontmatter.exercise} ) {title} | ||
</Link> | ||
{current && toc && ( | ||
<nav className="nav exercise-content-nav"> | ||
<ul> | ||
{toc.map((item) => ( | ||
<li> | ||
<Link to={item.url}>{item.title}</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
)} | ||
</li> | ||
); | ||
}); | ||
}; | ||
|
||
return ( | ||
<nav className="nav exercise-nav"> | ||
{levels.map((level) => { | ||
const currentLevel = nodes.filter( | ||
(node) => node.frontmatter.level === level | ||
); | ||
return ( | ||
<> | ||
{levels.length > 1 && <h3>Level {level}</h3>} | ||
<ul> | ||
<ExerciseListItems | ||
location={location} | ||
nodes={currentLevel} | ||
toc={toc} | ||
/> | ||
</ul> | ||
</> | ||
); | ||
})} | ||
</nav> | ||
); | ||
}; | ||
|
||
export default ExerciseNav; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { Link } from 'gatsby'; | ||
|
||
const ExerciseList = ({ nodes }) => { | ||
let currentLevel; | ||
return nodes.map((node) => { | ||
currentLevel = | ||
currentLevel === node.frontmatter.level | ||
? currentLevel | ||
: node.frontmatter.level; | ||
return ( | ||
<article key={node.fields.slug} className="content"> | ||
<header> | ||
<h3> | ||
<Link to={node.fields.slug}> | ||
Exercise {node.frontmatter.exercise} | {node.frontmatter.title} | ||
</Link> | ||
</h3> | ||
<p>{node.frontmatter.description}</p> | ||
</header> | ||
</article> | ||
); | ||
}); | ||
}; | ||
|
||
export default ExerciseList; |
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
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
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
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