/**
* 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 CWD = process.cwd();
const React = require("react");
const fs = require("fs");
const siteConfig = require(CWD + "/siteConfig.js");
const translation = require("../../server/translation.js");
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
let versions;
if (ENABLE_VERSIONING) {
versions = require(CWD + "/versions.json");
}
require("../../server/readMetadata.js").generateDocsMetadata();
const Metadata = require("../metadata.js");
// language dropdown nav item for when translations are enabled
class LanguageDropDown extends React.Component {
render() {
const enabledLanguages = [];
let currentLanguage = "English";
// add all enabled languages to dropdown
translation["languages"].map(lang => {
if (lang.tag == this.props.language) {
currentLanguage = lang.name;
}
if (lang.tag == this.props.language) {
return;
}
enabledLanguages.push(
);
});
// if no languages are enabled besides English, return null
if (enabledLanguages.length < 1) {
return null;
}
// add Crowdin project recruiting link
if (siteConfig.recruitingLink) {
enabledLanguages.push(
);
}
}
// header navbar used by all pages generated with docusaurus
class HeaderNav extends React.Component {
constructor() {
super();
this.state = {
slideoutActive: false
};
}
// function to generate each header link, used with each object in siteConfig.headerLinks
makeLinks(link) {
let href;
if (link.search && this.props.config.algolia) {
// return algolia search bar
return (
);
} else if (link.languages) {
return (
// return language dropdown
);
} else if (link.doc) {
// set link to document with current page's language/version
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;
}
if (!Metadata[id]) {
if (id != link.doc) {
throw new Error(
"It looks like you've enabled language support, but haven't provided translated files. The document with id: '" +
id +
"' doesn't exist."
);
}
throw new Error(
"A headerLink is specified with a document that does not exist. No document exists with id: " +
link.doc
);
}
href = this.props.config.baseUrl + Metadata[id].permalink;
} else if (link.page) {
// set link to page with current page's language if appropriate
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) {
// set link to specified href
href = link.href;
} else if (link.blog) {
// set link to blog url
href = this.props.baseUrl + "blog";
}
return (
);
}
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 });
}
let search = false;
headerLinks.forEach(link => {
if (link.doc && !fs.existsSync(CWD + "/../docs/")) {
throw new Error(
"You have 'doc' in your headerLinks, but no 'docs' folder exists one level up from " +
"'website' folder. Are you running the examples? If so, make sure you rename " +
"'docs-examples-from-docusaurus' to 'docs'."
);
}
if (link.blog && !fs.existsSync(CWD + "/blog/")) {
throw new Error(
"You have 'blog' in your headerLinks, but no 'blog' folder exists in your " +
"website folder. Are you running the examples? If so, make sure you rename " +
"'blog-examples-from-docusaurus' to 'blog'."
);
}
if (link.page && !fs.existsSync(CWD + "/pages/")) {
throw new Error(
"You have 'page' in your headerLinks, but no 'pages' folder exists in your " +
"'website' folder."
);
}
// We will add search bar to end if location not specified
if (link.search) {
search = true;
}
});
if (!search && this.props.config.algolia) {
headerLinks.push({ search: true });
}
return (