mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-07 11:57:55 +02:00
ESLintify Part 3 (#846)
* ESLintify Part 3 * ESLintify Part 3 * ESLintify Part 3
This commit is contained in:
parent
5ac2cee658
commit
a7a214fb3a
54 changed files with 435 additions and 497 deletions
|
@ -11,7 +11,7 @@ const React = require('react');
|
|||
const fs = require('fs');
|
||||
const classNames = require('classnames');
|
||||
|
||||
const siteConfig = require(CWD + '/siteConfig.js');
|
||||
const siteConfig = require(`${CWD}/siteConfig.js`);
|
||||
const translation = require('../../server/translation.js');
|
||||
const env = require('../../server/env.js');
|
||||
|
||||
|
@ -52,7 +52,7 @@ class LanguageDropDown extends React.Component {
|
|||
`/${lang.tag}/`
|
||||
);
|
||||
} else if (this.props.current.id && this.props.current.id !== 'index') {
|
||||
href = siteConfig.baseUrl + lang.tag + '/' + this.props.current.id;
|
||||
href = `${siteConfig.baseUrl + lang.tag}/${this.props.current.id}`;
|
||||
}
|
||||
return (
|
||||
<li key={lang.tag}>
|
||||
|
@ -91,7 +91,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`}
|
||||
alt="Languages icon"
|
||||
/>
|
||||
{currentLanguage}
|
||||
|
@ -162,33 +162,27 @@ class HeaderNav extends React.Component {
|
|||
if (link.doc) {
|
||||
// set link to document with current page's language/version
|
||||
const langPart = env.translation.enabled
|
||||
? (this.props.language || 'en') + '-'
|
||||
? `${this.props.language || 'en'}-`
|
||||
: '';
|
||||
const versionPart =
|
||||
env.versioning.enabled && this.props.version !== 'next'
|
||||
? 'version-' +
|
||||
(this.props.version || env.versioning.defaultVersion) +
|
||||
'-'
|
||||
? `version-${this.props.version || env.versioning.defaultVersion}-`
|
||||
: '';
|
||||
const id = langPart + versionPart + link.doc;
|
||||
if (!Metadata[id]) {
|
||||
let errorStr =
|
||||
"Processing the following `doc` field in `headerLinks` within `siteConfig.js`: '" +
|
||||
link.doc +
|
||||
"'";
|
||||
let errorStr = `Processing the following \`doc\` field in \`headerLinks\` within \`siteConfig.js\`: '${
|
||||
link.doc
|
||||
}'`;
|
||||
if (id === link.doc) {
|
||||
errorStr +=
|
||||
' It looks like there is no document with that id that exists in your docs directory. Please double check the spelling of your `doc` field and the `id` fields of your docs.';
|
||||
} else {
|
||||
errorStr +=
|
||||
'. Check the spelling of your `doc` field. If that seems sane, and a document in your docs folder exists with that `id` value, \nthen this is likely a bug in Docusaurus.' +
|
||||
' Docusaurus thinks one or both of translations (currently set to: ' +
|
||||
env.translation.enabled +
|
||||
') or versioning (currently set to: ' +
|
||||
env.versioning.enabled +
|
||||
") is enabled when maybe they should not be. \nThus my internal id for this doc is: '" +
|
||||
id +
|
||||
"'. Please file an issue for this possible bug on GitHub.";
|
||||
errorStr += `${'. Check the spelling of your `doc` field. If that seems sane, and a document in your docs folder exists with that `id` value, \nthen this is likely a bug in Docusaurus.' +
|
||||
' Docusaurus thinks one or both of translations (currently set to: '}${
|
||||
env.translation.enabled
|
||||
}) or versioning (currently set to: ${
|
||||
env.versioning.enabled
|
||||
}) is enabled when maybe they should not be. \nThus my internal id for this doc is: '${id}'. Please file an issue for this possible bug on GitHub.`;
|
||||
}
|
||||
throw new Error(errorStr);
|
||||
}
|
||||
|
@ -202,10 +196,10 @@ class HeaderNav extends React.Component {
|
|||
} else if (link.page) {
|
||||
// set link to page with current page's language if appropriate
|
||||
const language = this.props.language || '';
|
||||
if (fs.existsSync(CWD + '/pages/en/' + link.page + '.js')) {
|
||||
if (fs.existsSync(`${CWD}/pages/en/${link.page}.js`)) {
|
||||
href =
|
||||
siteConfig.baseUrl +
|
||||
(language ? language + '/' : '') +
|
||||
(language ? `${language}/` : '') +
|
||||
link.page +
|
||||
extension;
|
||||
} else {
|
||||
|
@ -216,7 +210,7 @@ class HeaderNav extends React.Component {
|
|||
href = link.href;
|
||||
} else if (link.blog) {
|
||||
// set link to blog url
|
||||
href = this.props.baseUrl + 'blog';
|
||||
href = `${this.props.baseUrl}blog`;
|
||||
}
|
||||
const itemClasses = classNames({
|
||||
siteNavGroupActive:
|
||||
|
@ -227,7 +221,7 @@ class HeaderNav extends React.Component {
|
|||
(link.page && link.page === this.props.current.id),
|
||||
});
|
||||
return (
|
||||
<li key={link.label + 'page'} className={itemClasses}>
|
||||
<li key={`${link.label}page`} className={itemClasses}>
|
||||
<a href={href} target={link.external ? '_blank' : '_self'}>
|
||||
{translation[this.props.language]
|
||||
? translation[this.props.language]['localized-strings'][link.label]
|
||||
|
@ -253,24 +247,22 @@ class HeaderNav extends React.Component {
|
|||
headerLinks.forEach(link => {
|
||||
if (
|
||||
link.doc &&
|
||||
!fs.existsSync(CWD + '/../' + readMetadata.getDocsPath() + '/')
|
||||
!fs.existsSync(`${CWD}/../${readMetadata.getDocsPath()}/`)
|
||||
) {
|
||||
throw new Error(
|
||||
"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'."
|
||||
`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."
|
||||
|
@ -302,8 +294,8 @@ class HeaderNav extends React.Component {
|
|||
const versionsLink =
|
||||
this.props.baseUrl +
|
||||
(env.translation.enabled
|
||||
? this.props.language + '/versions' + extension
|
||||
: 'versions' + extension);
|
||||
? `${this.props.language}/versions${extension}`
|
||||
: `versions${extension}`);
|
||||
return (
|
||||
<div className="fixedHeaderContainer">
|
||||
<div className="headerWrapper wrapper">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue