mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 13:37:05 +02:00
Add separate on-page navigation sidebar (#475)
This commit is contained in:
parent
f093790947
commit
4ff2fe280e
5 changed files with 127 additions and 2 deletions
40
lib/core/nav/OnPageNav.js
Normal file
40
lib/core/nav/OnPageNav.js
Normal file
|
@ -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;
|
Loading…
Add table
Add a link
Reference in a new issue