mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 15:17:23 +02:00
Allow external link target (e.g. _blank)
This commit is contained in:
parent
f72144e988
commit
da4b381df4
2 changed files with 30 additions and 4 deletions
|
@ -91,7 +91,7 @@ class HeaderNav extends React.Component {
|
|||
};
|
||||
}
|
||||
|
||||
makeLinks(link) {
|
||||
makeInternalLinks(link) {
|
||||
const linkWithLang = link.href.replace(
|
||||
/\/LANGUAGE\//,
|
||||
"/" + this.props.language + "/"
|
||||
|
@ -110,6 +110,26 @@ class HeaderNav extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
makeExternalLinks(link) {
|
||||
const linkWithLang = link.href.replace(
|
||||
/\/LANGUAGE\//,
|
||||
"/" + this.props.language + "/"
|
||||
);
|
||||
return (
|
||||
<li key={link.section}>
|
||||
<a
|
||||
href={linkWithLang}
|
||||
className={link.section === this.props.section ? "active" : ""}
|
||||
target={siteConfig.externalLinkTarget || "_self"}
|
||||
>
|
||||
{translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"][link.text]
|
||||
: link.text}
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="fixedHeaderContainer">
|
||||
|
@ -134,7 +154,10 @@ class HeaderNav extends React.Component {
|
|||
<div className="navigationWrapper navigationSlider">
|
||||
<nav className="slidingNav">
|
||||
<ul className="nav-site nav-site-internal">
|
||||
{this.props.config.headerLinksInternal.map(this.makeLinks, this)}
|
||||
{this.props.config.headerLinksInternal.map(
|
||||
this.makeInternalLinks,
|
||||
this
|
||||
)}
|
||||
<LanguageDropDown
|
||||
baseUrl={this.props.baseUrl}
|
||||
language={this.props.language}
|
||||
|
@ -147,7 +170,10 @@ class HeaderNav extends React.Component {
|
|||
placeholder="Search"
|
||||
/>
|
||||
</li>}
|
||||
{this.props.config.headerLinksExternal.map(this.makeLinks, this)}
|
||||
{this.props.config.headerLinksExternal.map(
|
||||
this.makeExternalLinks,
|
||||
this
|
||||
)}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue