-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add separate on-page navigation sidebar (#475)
- Loading branch information
1 parent
f093790
commit 4ff2fe2
Showing
5 changed files
with
127 additions
and
2 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const React = require('react'); | ||
|
||
const siteConfig = require(process.cwd() + '/siteConfig.js'); | ||
const getTOC = require('../getTOC'); | ||
|
||
const Link = ({hashLink, text}) => <a href={`#${hashLink}`}>{text}</a>; | ||
|
||
const Headings = ({headings}) => { | ||
if (!headings.length) return null; | ||
return ( | ||
<ul className="toc-headings"> | ||
{headings.map((heading, i) => ( | ||
<li key={i}> | ||
<Link hashLink={heading.hashLink} text={heading.text} /> | ||
<Headings headings={heading.children} /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
class OnPageNav extends React.Component { | ||
render() { | ||
const customTags = siteConfig.onPageNavHeadings; | ||
const headings = customTags | ||
? getTOC(this.props.rawContent, customTags.topLevel, customTags.sub) | ||
: getTOC(this.props.rawContent); | ||
|
||
return <Headings headings={headings} />; | ||
} | ||
} | ||
|
||
module.exports = OnPageNav; |
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