Update headerLinks API

This commit is contained in:
Frank Li 2017-08-08 13:46:11 -07:00
parent bba7edd80f
commit 6ca90610f4
7 changed files with 74 additions and 79 deletions

View file

@ -28,7 +28,6 @@ const BlogPageLayout = React.createClass({
const page = this.props.metadata.page;
return (
<Site
section="blog"
title="Blog"
language="en"
config={this.props.config}

View file

@ -18,7 +18,6 @@ class BlogPostLayout extends React.Component {
return (
<Site
className="sideNavVisible"
section="blog"
url={"blog/" + this.props.metadata.path}
title={this.props.metadata.title}
language={"en"}

View file

@ -23,7 +23,6 @@ class DocsLayout extends React.Component {
<Site
config={this.props.config}
className="sideNavVisible"
section="docs"
title={
i18n
? translation[this.props.metadata.language]["localized-strings"][

View file

@ -63,7 +63,6 @@ class Site extends React.Component {
<HeaderNav
config={this.props.config}
baseUrl={this.props.config.baseUrl}
section={this.props.section}
title={this.props.config.title}
language={this.props.language}
version={this.props.version}

View file

@ -13,6 +13,7 @@ const React = require("react");
const fs = require("fs");
const siteConfig = require(CWD + "/siteConfig.js");
const translation = require("../../server/translation.js");
const Metadata = require("../metadata.js");
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
@ -100,44 +101,51 @@ class HeaderNav extends React.Component {
};
}
makeInternalLinks(link) {
let updatedLink = link.href.replace(
/\/LANGUAGE\//,
"/" + this.props.language + "/"
);
if (this.props.version) {
updatedLink = updatedLink.replace(
/\/VERSION\//,
"/" + this.props.version + "/"
);
} else {
updatedLink = updatedLink.replace(/\/VERSION\//, "/");
}
makeLinks(link) {
let href;
if (link.search && this.props.config.algolia) {
return (
<li key={link.section}>
<a
href={updatedLink}
className={link.section === this.props.section ? "active" : ""}
>
{translation[this.props.language]
? translation[this.props.language]["localized-strings"][link.text]
: link.text}
</a>
<li className="navSearchWrapper reactNavSearchWrapper">
<input id="search_input_react" type="text" placeholder="Search" />
</li>
);
}
makeExternalLinks(link) {
} else if (link.languages) {
return (
<li key={link.section}>
<a
href={link.href}
className={link.section === this.props.section ? "active" : ""}
target={siteConfig.externalLinkTarget || "_self"}
>
<LanguageDropDown
baseUrl={this.props.baseUrl}
language={this.props.language}
/>
);
} else if (link.doc) {
let id;
if (!ENABLE_VERSIONING || this.props.version === "next") {
id = this.props.language + "-" + link.doc;
} else {
id =
this.props.language +
"-version-" +
(this.props.version || versions[0]) +
"-" +
link.doc;
}
console.log(id);
href = this.props.config.baseUrl + Metadata[id].permalink;
} else if (link.page) {
if (fs.existsSync(CWD + "/pages/en/" + link.page + ".js")) {
href =
siteConfig.baseUrl + this.props.language + "/" + link.page + ".html";
} else {
href = siteConfig.baseUrl + link.page + ".html";
}
} else if (link.href) {
href = link.href;
}
return (
<li>
<a href={href} target={link.external ? "_blank" : "_self"}>
{translation[this.props.language]
? translation[this.props.language]["localized-strings"][link.text]
: link.text}
? translation[this.props.language]["localized-strings"][link.label]
: link.label}
</a>
</li>
);
@ -174,30 +182,32 @@ class HeaderNav extends React.Component {
}
renderResponsiveNav() {
const headerLinks = this.props.config.headerLinks;
// add language drop down to end if location not specified
let languages = false;
headerLinks.forEach(link => {
if (link.languages) {
languages = true;
}
});
if (!languages) {
headerLinks.push({ languages: true });
}
// add search bar to end if location not specified
let search = false;
headerLinks.forEach(link => {
if (link.search) {
search = true;
}
});
if (!search && this.props.config.algolia) {
headerLinks.push({ search: true });
}
return (
<div className="navigationWrapper navigationSlider">
<nav className="slidingNav">
<ul className="nav-site nav-site-internal">
{this.props.config.headerLinksInternal.map(
this.makeInternalLinks,
this
)}
<LanguageDropDown
baseUrl={this.props.baseUrl}
language={this.props.language}
/>
{this.props.config.algolia &&
<li className="navSearchWrapper reactNavSearchWrapper">
<input
id="search_input_react"
type="text"
placeholder="Search"
/>
</li>}
{this.props.config.headerLinksExternal.map(
this.makeExternalLinks,
this
)}
{headerLinks.map(this.makeLinks, this)}
</ul>
</nav>
</div>

View file

@ -57,14 +57,11 @@ function execute() {
}
});
/* look through header links for text to translate */
for (let i = 0; i < siteConfig.headerLinksInternal.length; i++) {
translations["localized-strings"][siteConfig.headerLinksInternal[i].text] =
siteConfig.headerLinksInternal[i].text;
}
for (let i = 0; i < siteConfig.headerLinksExternal.length; i++) {
translations["localized-strings"][siteConfig.headerLinksExternal[i].text] =
siteConfig.headerLinksExternal[i].text;
siteConfig.headerLinks.forEach(link => {
if (link.label) {
translations["localized-strings"][link.label] = link.label;
}
});
/* find sidebar category titles to translate */
Object.keys(sidebars).forEach(sb => {

View file

@ -26,19 +26,12 @@ const siteConfig = {
users,
editUrl:
"https://github.com/facebookexperimental/docusaurus/edit/master/docs/",
headerLinksInternal: [
headerLinks: [
{ doc: "installation", label: "Docs" },
{ page: "help", label: "Help" },
{
section: "docs",
href: "/docusaurus/docs/getting-started.html",
text: "Docs"
},
{ section: "help", href: "/docusaurus/LANGUAGE/help.html", text: "Help" }
],
headerLinksExternal: [
{
section: "github",
href: "https://github.com/facebookexperimental/docusaurus",
text: "GitHub"
label: "GitHub"
}
],
headerIcon: "img/docusaurus.svg",
@ -55,8 +48,7 @@ const siteConfig = {
colors: {
primaryColor: "#2E8555",
secondaryColor: "#205C3B",
prismColor:
"rgba(46, 133, 85, 0.03)"
prismColor: "rgba(46, 133, 85, 0.03)"
}
};