mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
Add Prettier Formatting (#258)
* Add Prettier formatting to source files and example files, and check that Prettier formatting is maintained on PRs * Remove trailing-comma as we are using Node 6 on Circle * Use latest Node 6 LTS version in Circle * Remove unused test
This commit is contained in:
parent
0cead4b6f9
commit
65421db62e
50 changed files with 1376 additions and 1350 deletions
|
@ -7,35 +7,35 @@
|
|||
|
||||
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 React = require('react');
|
||||
const fs = require('fs');
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const translation = require('../../server/translation.js');
|
||||
|
||||
const translate = require("../../server/translate.js").translate;
|
||||
const setLanguage = require("../../server/translate.js").setLanguage;
|
||||
const translate = require('../../server/translate.js').translate;
|
||||
const setLanguage = require('../../server/translate.js').setLanguage;
|
||||
|
||||
const ENABLE_TRANSLATION = fs.existsSync(CWD + "/languages.js");
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
|
||||
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");
|
||||
versions = require(CWD + '/versions.json');
|
||||
}
|
||||
const readMetadata = require("../../server/readMetadata.js");
|
||||
const readMetadata = require('../../server/readMetadata.js');
|
||||
readMetadata.generateMetadataDocs();
|
||||
const Metadata = require("../metadata.js");
|
||||
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";
|
||||
let currentLanguage = 'English';
|
||||
setLanguage(this.props.language);
|
||||
let helpTranslateString = translate(
|
||||
"Help Translate|recruit community translators for your project"
|
||||
'Help Translate|recruit community translators for your project'
|
||||
);
|
||||
// add all enabled languages to dropdown
|
||||
translation["languages"].map(lang => {
|
||||
translation['languages'].map(lang => {
|
||||
if (lang.tag == this.props.language) {
|
||||
currentLanguage = lang.name;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class LanguageDropDown extends React.Component {
|
|||
<a id="languages-menu" href="#">
|
||||
<img
|
||||
className="languages-icon"
|
||||
src={this.props.baseUrl + "img/language.svg"}
|
||||
src={this.props.baseUrl + 'img/language.svg'}
|
||||
/>
|
||||
{currentLanguage}
|
||||
</a>
|
||||
|
@ -89,7 +89,7 @@ class LanguageDropDown extends React.Component {
|
|||
languagesDropDown.className = "hide";
|
||||
}
|
||||
});
|
||||
`
|
||||
`,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
|
@ -102,7 +102,7 @@ class HeaderNav extends React.Component {
|
|||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
slideoutActive: false
|
||||
slideoutActive: false,
|
||||
};
|
||||
}
|
||||
// function to generate each header link, used with each object in siteConfig.headerLinks
|
||||
|
@ -127,14 +127,14 @@ class HeaderNav extends React.Component {
|
|||
} 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;
|
||||
if (!ENABLE_VERSIONING || this.props.version === 'next') {
|
||||
id = this.props.language + '-' + link.doc;
|
||||
} else {
|
||||
id =
|
||||
this.props.language +
|
||||
"-version-" +
|
||||
'-version-' +
|
||||
(this.props.version || versions[0]) +
|
||||
"-" +
|
||||
'-' +
|
||||
link.doc;
|
||||
}
|
||||
if (!Metadata[id]) {
|
||||
|
@ -146,31 +146,31 @@ class HeaderNav extends React.Component {
|
|||
);
|
||||
}
|
||||
throw new Error(
|
||||
"A headerLink is specified with a document that does not exist. No document exists with id: " +
|
||||
'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")) {
|
||||
if (fs.existsSync(CWD + '/pages/en/' + link.page + '.js')) {
|
||||
href =
|
||||
siteConfig.baseUrl + this.props.language + "/" + link.page + ".html";
|
||||
siteConfig.baseUrl + this.props.language + '/' + link.page + '.html';
|
||||
} else {
|
||||
href = siteConfig.baseUrl + link.page + ".html";
|
||||
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";
|
||||
href = this.props.baseUrl + 'blog';
|
||||
}
|
||||
return (
|
||||
<li key={link.label + "page"}>
|
||||
<a href={href} target={link.external ? "_blank" : "_self"}>
|
||||
<li key={link.label + 'page'}>
|
||||
<a href={href} target={link.external ? '_blank' : '_self'}>
|
||||
{translation[this.props.language]
|
||||
? translation[this.props.language]["localized-strings"][link.label]
|
||||
? translation[this.props.language]['localized-strings'][link.label]
|
||||
: link.label}
|
||||
</a>
|
||||
</li>
|
||||
|
@ -181,8 +181,8 @@ class HeaderNav extends React.Component {
|
|||
const versionsLink =
|
||||
this.props.baseUrl +
|
||||
(ENABLE_TRANSLATION
|
||||
? this.props.language + "/versions.html"
|
||||
: "versions.html");
|
||||
? this.props.language + '/versions.html'
|
||||
: 'versions.html');
|
||||
return (
|
||||
<div className="fixedHeaderContainer">
|
||||
<div className="headerWrapper wrapper">
|
||||
|
@ -218,26 +218,30 @@ class HeaderNav extends React.Component {
|
|||
}
|
||||
});
|
||||
if (!languages) {
|
||||
headerLinks.push({ languages: true });
|
||||
headerLinks.push({languages: true});
|
||||
}
|
||||
let search = false;
|
||||
headerLinks.forEach(link => {
|
||||
if (link.doc && !fs.existsSync(CWD + "/../" + readMetadata.getDocsPath() + "/")) {
|
||||
if (
|
||||
link.doc &&
|
||||
!fs.existsSync(CWD + '/../' + readMetadata.getDocsPath() + '/')
|
||||
) {
|
||||
throw new Error(
|
||||
"You have 'doc' in your headerLinks, but no '" + readMetadata.getDocsPath() +
|
||||
"You have 'doc' in your headerLinks, but no '" +
|
||||
readMetadata.getDocsPath() +
|
||||
"' folder exists one level up from " +
|
||||
"'website' folder. Did you run `docusaurus-init` or `npm run examples`? If so, " +
|
||||
"make sure you rename 'docs-examples-from-docusaurus' to 'docs'."
|
||||
);
|
||||
}
|
||||
if (link.blog && !fs.existsSync(CWD + "/blog/")) {
|
||||
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. Did you run `docusaurus-init` or `npm run examples`? If so, " +
|
||||
"make sure you rename 'blog-examples-from-docusaurus' to 'blog'."
|
||||
);
|
||||
}
|
||||
if (link.page && !fs.existsSync(CWD + "/pages/")) {
|
||||
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."
|
||||
|
@ -249,7 +253,7 @@ class HeaderNav extends React.Component {
|
|||
}
|
||||
});
|
||||
if (!search && this.props.config.algolia) {
|
||||
headerLinks.push({ search: true });
|
||||
headerLinks.push({search: true});
|
||||
}
|
||||
return (
|
||||
<div className="navigationWrapper navigationSlider">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue