mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 20:27:20 +02:00
chore(v2): fix code style (revert previous changes)
This commit is contained in:
parent
1480a7eb80
commit
1f00d15c74
143 changed files with 457 additions and 458 deletions
|
@ -15,12 +15,12 @@ function getOutputCss(output) {
|
|||
|
||||
global.testStylelintRule = (config, tests) => {
|
||||
describe(tests.ruleName, () => {
|
||||
const checkTestCaseContent = testCase =>
|
||||
const checkTestCaseContent = (testCase) =>
|
||||
testCase.description || testCase.code || 'no description';
|
||||
|
||||
if (tests.accept && tests.accept.length) {
|
||||
describe('accept cases', () => {
|
||||
tests.accept.forEach(testCase => {
|
||||
tests.accept.forEach((testCase) => {
|
||||
const spec = testCase.only ? it.only : it;
|
||||
|
||||
spec(checkTestCaseContent(testCase), () => {
|
||||
|
@ -30,7 +30,7 @@ global.testStylelintRule = (config, tests) => {
|
|||
syntax: tests.syntax,
|
||||
};
|
||||
|
||||
return stylelint.lint(options).then(output => {
|
||||
return stylelint.lint(options).then((output) => {
|
||||
expect(output.results[0].warnings).toEqual([]);
|
||||
|
||||
if (!tests.fix) {
|
||||
|
@ -40,8 +40,8 @@ global.testStylelintRule = (config, tests) => {
|
|||
// Check the fix.
|
||||
return stylelint
|
||||
.lint({...options, fix: true})
|
||||
.then(fixedOutput => getOutputCss(fixedOutput))
|
||||
.then(fixedCode => expect(fixedCode).toBe(testCase.fixed));
|
||||
.then((fixedOutput) => getOutputCss(fixedOutput))
|
||||
.then((fixedCode) => expect(fixedCode).toBe(testCase.fixed));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -50,7 +50,7 @@ global.testStylelintRule = (config, tests) => {
|
|||
|
||||
if (tests.reject && tests.reject.length) {
|
||||
describe('reject cases', () => {
|
||||
tests.reject.forEach(testCase => {
|
||||
tests.reject.forEach((testCase) => {
|
||||
const skip = testCase.skip ? it.skip : it;
|
||||
const spec = testCase.only ? it.only : skip;
|
||||
|
||||
|
@ -61,7 +61,7 @@ global.testStylelintRule = (config, tests) => {
|
|||
syntax: tests.syntax,
|
||||
};
|
||||
|
||||
return stylelint.lint(options).then(output => {
|
||||
return stylelint.lint(options).then((output) => {
|
||||
const {warnings} = output.results[0];
|
||||
const warning = warnings[0];
|
||||
|
||||
|
@ -93,8 +93,8 @@ global.testStylelintRule = (config, tests) => {
|
|||
// Check the fix.
|
||||
return stylelint
|
||||
.lint({...options, fix: true})
|
||||
.then(fixedOutput => getOutputCss(fixedOutput))
|
||||
.then(fixedCode => expect(fixedCode).toBe(testCase.fixed));
|
||||
.then((fixedOutput) => getOutputCss(fixedOutput))
|
||||
.then((fixedCode) => expect(fixedCode).toBe(testCase.fixed));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ function Help(props) {
|
|||
const {baseUrl, docsUrl} = siteConfig;
|
||||
const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`;
|
||||
const langPart = `${language ? `${language}/` : ''}`;
|
||||
const docUrl = doc => `${baseUrl}${docsPart}${langPart}${doc}`;
|
||||
const docUrl = (doc) => `${baseUrl}${docsPart}${langPart}${doc}`;
|
||||
|
||||
const supportLinks = [
|
||||
{
|
||||
|
|
|
@ -19,9 +19,9 @@ class HomeSplash extends React.Component {
|
|||
const {baseUrl, docsUrl} = siteConfig;
|
||||
const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`;
|
||||
const langPart = `${language ? `${language}/` : ''}`;
|
||||
const docUrl = doc => `${baseUrl}${docsPart}${langPart}${doc}`;
|
||||
const docUrl = (doc) => `${baseUrl}${docsPart}${langPart}${doc}`;
|
||||
|
||||
const SplashContainer = props => (
|
||||
const SplashContainer = (props) => (
|
||||
<div className="homeContainer">
|
||||
<div className="homeSplashFade">
|
||||
<div className="wrapper homeWrapper">{props.children}</div>
|
||||
|
@ -29,20 +29,20 @@ class HomeSplash extends React.Component {
|
|||
</div>
|
||||
);
|
||||
|
||||
const Logo = props => (
|
||||
const Logo = (props) => (
|
||||
<div className="projectLogo">
|
||||
<img src={props.img_src} alt="Project Logo" />
|
||||
</div>
|
||||
);
|
||||
|
||||
const ProjectTitle = props => (
|
||||
const ProjectTitle = (props) => (
|
||||
<h2 className="projectTitle">
|
||||
{props.title}
|
||||
<small>{props.tagline}</small>
|
||||
</h2>
|
||||
);
|
||||
|
||||
const PromoSection = props => (
|
||||
const PromoSection = (props) => (
|
||||
<div className="section promoSection">
|
||||
<div className="promoRow">
|
||||
<div className="pluginRowBlock">{props.children}</div>
|
||||
|
@ -50,7 +50,7 @@ class HomeSplash extends React.Component {
|
|||
</div>
|
||||
);
|
||||
|
||||
const Button = props => (
|
||||
const Button = (props) => (
|
||||
<div className="pluginWrapper buttonWrapper">
|
||||
<a className="button" href={props.href} target={props.target}>
|
||||
{props.children}
|
||||
|
@ -79,7 +79,7 @@ class Index extends React.Component {
|
|||
const {config: siteConfig, language = ''} = this.props;
|
||||
const {baseUrl} = siteConfig;
|
||||
|
||||
const Block = props => (
|
||||
const Block = (props) => (
|
||||
<Container
|
||||
padding={['bottom', 'top']}
|
||||
id={props.id}
|
||||
|
@ -170,14 +170,15 @@ class Index extends React.Component {
|
|||
}
|
||||
|
||||
const showcase = siteConfig.users
|
||||
.filter(user => user.pinned)
|
||||
.map(user => (
|
||||
.filter((user) => user.pinned)
|
||||
.map((user) => (
|
||||
<a href={user.infoLink} key={user.infoLink}>
|
||||
<img src={user.image} alt={user.caption} title={user.caption} />
|
||||
</a>
|
||||
));
|
||||
|
||||
const pageUrl = page => baseUrl + (language ? `${language}/` : '') + page;
|
||||
const pageUrl = (page) =>
|
||||
baseUrl + (language ? `${language}/` : '') + page;
|
||||
|
||||
return (
|
||||
<div className="productShowcaseSection paddingBottom">
|
||||
|
|
|
@ -18,7 +18,7 @@ class Users extends React.Component {
|
|||
return null;
|
||||
}
|
||||
|
||||
const showcase = siteConfig.users.map(user => (
|
||||
const showcase = siteConfig.users.map((user) => (
|
||||
<a href={user.infoLink} key={user.infoLink}>
|
||||
<img src={user.image} alt={user.caption} title={user.caption} />
|
||||
</a>
|
||||
|
|
|
@ -79,7 +79,7 @@ function Versions(props) {
|
|||
<table className="versions">
|
||||
<tbody>
|
||||
{versions.map(
|
||||
version =>
|
||||
(version) =>
|
||||
version !== latestVersion && (
|
||||
<tr key={version}>
|
||||
<th>{version}</th>
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('Build files', () => {
|
|||
glob(`${buildDir}/${siteConfig.projectName}/docs/**/*.html`),
|
||||
glob(`${docsDir}/assets/*`),
|
||||
glob(`${buildDir}/${siteConfig.projectName}/img/*`),
|
||||
]).then(results => {
|
||||
]).then((results) => {
|
||||
[
|
||||
inputMarkdownFiles,
|
||||
outputHTMLFiles,
|
||||
|
@ -62,15 +62,15 @@ describe('Build files', () => {
|
|||
});
|
||||
|
||||
test('Build folder exists', () =>
|
||||
fs.stat(buildDir).then(status => {
|
||||
fs.stat(buildDir).then((status) => {
|
||||
expect(status.isDirectory()).toBeTruthy();
|
||||
}));
|
||||
|
||||
test('Generated HTML for each Markdown resource', () => {
|
||||
const metadata = outputHTMLFiles.map(file =>
|
||||
const metadata = outputHTMLFiles.map((file) =>
|
||||
filepath.create(file).basename(),
|
||||
);
|
||||
inputMarkdownFiles.forEach(file => {
|
||||
inputMarkdownFiles.forEach((file) => {
|
||||
const data = fs.readFileSync(file, 'utf8');
|
||||
const frontmatter = fm(data);
|
||||
expect(metadata).toContain(`${frontmatter.attributes.id}.html`);
|
||||
|
@ -78,17 +78,17 @@ describe('Build files', () => {
|
|||
});
|
||||
|
||||
test('Generated table of contents', () => {
|
||||
outputHTMLFiles.forEach(file => {
|
||||
outputHTMLFiles.forEach((file) => {
|
||||
const fileContents = fs.readFileSync(file, 'utf8');
|
||||
expect(fileContents).not.toContain('<AUTOGENERATED_TABLE_OF_CONTENTS>');
|
||||
});
|
||||
});
|
||||
|
||||
test('Copied assets from /docs/assets', () => {
|
||||
const metadata = outputAssetsFiles.map(file =>
|
||||
const metadata = outputAssetsFiles.map((file) =>
|
||||
filepath.create(file).basename(),
|
||||
);
|
||||
inputAssetsFiles.forEach(file => {
|
||||
inputAssetsFiles.forEach((file) => {
|
||||
const path = filepath.create(file);
|
||||
expect(metadata).toContain(path.basename());
|
||||
});
|
||||
|
|
|
@ -42,7 +42,7 @@ generate()
|
|||
.then(() => {
|
||||
console.log("Site built successfully. Generated files in 'build' folder.");
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ const path = require('path');
|
|||
|
||||
const CWD = process.cwd();
|
||||
|
||||
const toHex = color => {
|
||||
const toHex = (color) => {
|
||||
const hex = color.toString(16);
|
||||
return hex.length === 1 ? `0${hex}` : hex;
|
||||
};
|
||||
|
@ -37,7 +37,7 @@ let feature;
|
|||
|
||||
commander
|
||||
.arguments('[feature]')
|
||||
.action(feat => {
|
||||
.action((feat) => {
|
||||
feature = feat;
|
||||
})
|
||||
.parse(process.argv);
|
||||
|
@ -85,7 +85,7 @@ if (feature === 'translations') {
|
|||
fs.copySync(`${folder}/crowdin.yaml`, `${CWD}/../crowdin.yaml`);
|
||||
}
|
||||
const files = glob.sync(`${folder}/**/*`);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
if (fs.lstatSync(file).isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ if (feature === 'translations') {
|
|||
// copy files for versions
|
||||
const folder = path.join(__dirname, '..', 'examples', 'versions');
|
||||
const files = glob.sync(`${folder}/**/*`);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
if (fs.lstatSync(file).isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ if (feature === 'translations') {
|
|||
// copy other files
|
||||
const files = glob.sync(`${folder}/**/*`);
|
||||
const {primaryColor, secondaryColor} = colorScheme();
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
if (fs.lstatSync(file).isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ if (feature === 'translations') {
|
|||
});
|
||||
|
||||
const svgs = glob.sync(`${CWD}/static/img/**/*.svg`);
|
||||
svgs.forEach(file => {
|
||||
svgs.forEach((file) => {
|
||||
// Replace primary colors of SVGs.
|
||||
const newImage = fs
|
||||
.readFileSync(file, 'utf8')
|
||||
|
|
|
@ -14,7 +14,7 @@ const MetadataBlog = require('./MetadataBlog.js');
|
|||
const MetadataPublicBlog =
|
||||
process.env.NODE_ENV === 'development'
|
||||
? MetadataBlog
|
||||
: MetadataBlog.filter(item => !item.unlisted);
|
||||
: MetadataBlog.filter((item) => !item.unlisted);
|
||||
const Site = require('./Site.js');
|
||||
const utils = require('./utils.js');
|
||||
|
||||
|
@ -48,7 +48,7 @@ class BlogPageLayout extends React.Component {
|
|||
{MetadataPublicBlog.slice(
|
||||
page * perPage,
|
||||
(page + 1) * perPage,
|
||||
).map(post => (
|
||||
).map((post) => (
|
||||
<BlogPost
|
||||
post={post}
|
||||
content={post.content}
|
||||
|
|
|
@ -38,8 +38,9 @@ class BlogPostLayout extends React.Component {
|
|||
{/* Facebook SDK require 'fb-comments' class */}
|
||||
<div
|
||||
className="fb-comments"
|
||||
data-href={`${this.props.config.url +
|
||||
this.props.config.baseUrl}blog/${post.path}`}
|
||||
data-href={`${
|
||||
this.props.config.url + this.props.config.baseUrl
|
||||
}blog/${post.path}`}
|
||||
data-width="100%"
|
||||
data-numposts="5"
|
||||
data-order-by="time"
|
||||
|
@ -52,8 +53,9 @@ class BlogPostLayout extends React.Component {
|
|||
{/* Facebook SDK require 'fb-like' class */}
|
||||
<div
|
||||
className="fb-like"
|
||||
data-href={`${this.props.config.url +
|
||||
this.props.config.baseUrl}blog/${post.path}`}
|
||||
data-href={`${
|
||||
this.props.config.url + this.props.config.baseUrl
|
||||
}blog/${post.path}`}
|
||||
data-layout="standard"
|
||||
data-share="true"
|
||||
data-width="225"
|
||||
|
|
|
@ -13,7 +13,7 @@ const MetadataBlog = require('./MetadataBlog.js');
|
|||
const MetadataPublicBlog =
|
||||
process.env.NODE_ENV === 'development'
|
||||
? MetadataBlog
|
||||
: MetadataBlog.filter(item => !item.unlisted);
|
||||
: MetadataBlog.filter((item) => !item.unlisted);
|
||||
|
||||
class BlogSidebar extends React.Component {
|
||||
render() {
|
||||
|
@ -33,7 +33,7 @@ class BlogSidebar extends React.Component {
|
|||
{
|
||||
type: 'CATEGORY',
|
||||
title: blogSidebarTitle,
|
||||
children: MetadataPublicBlog.slice(0, blogSidebarCount).map(item => ({
|
||||
children: MetadataPublicBlog.slice(0, blogSidebarCount).map((item) => ({
|
||||
type: 'LINK',
|
||||
item,
|
||||
})),
|
||||
|
|
|
@ -27,7 +27,7 @@ const splitTabsToTitleAndContent = (lines, indents) => {
|
|||
let current = {
|
||||
content: [],
|
||||
};
|
||||
lines.forEach(line => {
|
||||
lines.forEach((line) => {
|
||||
if (indents) {
|
||||
line = line.replace(new RegExp(`^((\\t|\\s{4}){${indents}})`, 'g'), '');
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ const cleanTheCodeTag = (content, indents) => {
|
|||
};
|
||||
const contents = content.split(/(<pre>)(.*?)(<\/pre>)/gms);
|
||||
let inCodeBlock = false;
|
||||
const cleanContents = contents.map(c => {
|
||||
const cleanContents = contents.map((c) => {
|
||||
if (c === '<pre>') {
|
||||
inCodeBlock = true;
|
||||
return c;
|
||||
|
@ -159,8 +159,8 @@ class Doc extends React.Component {
|
|||
let indents = 0;
|
||||
return content.replace(
|
||||
/(\t|\s{4})*?(<!--DOCUSAURUS_CODE_TABS-->\n)(.*?)((\n|\t|\s{4})<!--END_DOCUSAURUS_CODE_TABS-->)/gms,
|
||||
m => {
|
||||
const contents = m.split('\n').filter(c => {
|
||||
(m) => {
|
||||
const contents = m.split('\n').filter((c) => {
|
||||
if (!indents) {
|
||||
indents = (
|
||||
c.match(/((\t|\s{4})+)<!--DOCUSAURUS_CODE_TABS-->/) || []
|
||||
|
|
|
@ -11,7 +11,7 @@ const React = require('react');
|
|||
class Head extends React.Component {
|
||||
render() {
|
||||
const links = this.props.config.headerLinks;
|
||||
const hasBlog = links.some(link => link.blog);
|
||||
const hasBlog = links.some((link) => link.blog);
|
||||
|
||||
const highlight = {
|
||||
version: '9.12.0',
|
||||
|
@ -130,7 +130,7 @@ class Head extends React.Component {
|
|||
|
||||
{/* External resources */}
|
||||
{this.props.config.stylesheets &&
|
||||
this.props.config.stylesheets.map(source =>
|
||||
this.props.config.stylesheets.map((source) =>
|
||||
source.href ? (
|
||||
<link rel="stylesheet" key={source.href} {...source} />
|
||||
) : (
|
||||
|
@ -138,7 +138,7 @@ class Head extends React.Component {
|
|||
),
|
||||
)}
|
||||
{this.props.config.scripts &&
|
||||
this.props.config.scripts.map(source =>
|
||||
this.props.config.scripts.map((source) =>
|
||||
source.src ? (
|
||||
<script type="text/javascript" key={source.src} {...source} />
|
||||
) : (
|
||||
|
|
|
@ -20,7 +20,7 @@ class Remarkable extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
return React.Children.map(this.props.children, child => {
|
||||
return React.Children.map(this.props.children, (child) => {
|
||||
if (typeof child === 'string') {
|
||||
return (
|
||||
<span dangerouslySetInnerHTML={{__html: renderMarkdown(child)}} />
|
||||
|
|
|
@ -26,7 +26,7 @@ class Site extends React.Component {
|
|||
const hasLanguageDropdown =
|
||||
env.translation.enabled && env.translation.enabledLanguages().length > 1;
|
||||
const hasOrdinaryHeaderLinks = headerLinks.some(
|
||||
link => !(link.languages || link.search),
|
||||
(link) => !(link.languages || link.search),
|
||||
);
|
||||
return !(hasLanguageDropdown || hasOrdinaryHeaderLinks);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('utils', () => {
|
|||
expect(utils.getPath(null, false)).toBeNull();
|
||||
|
||||
// transform to pretty/clean path
|
||||
const cleanPath = pathStr => utils.getPath(pathStr, true);
|
||||
const cleanPath = (pathStr) => utils.getPath(pathStr, true);
|
||||
expect(cleanPath('/en/users')).toBe('/en/users');
|
||||
expect(cleanPath('/docs/versioning.html')).toBe('/docs/versioning');
|
||||
expect(cleanPath('/en/users.html')).toBe('/en/users');
|
||||
|
@ -168,7 +168,7 @@ describe('utils', () => {
|
|||
});
|
||||
expect(utils.idx(env, ['translation', 'enabled'])).toEqual(true);
|
||||
expect(
|
||||
utils.idx(env, ['translation', variable]).map(lang => lang.tag),
|
||||
utils.idx(env, ['translation', variable]).map((lang) => lang.tag),
|
||||
).toEqual(['en', 'ja']);
|
||||
expect(utils.idx(undefined)).toBeUndefined();
|
||||
expect(utils.idx(null)).toBeNull();
|
||||
|
|
|
@ -39,8 +39,8 @@ class LanguageDropDown extends React.Component {
|
|||
// add all enabled languages to dropdown
|
||||
const enabledLanguages = env.translation
|
||||
.enabledLanguages()
|
||||
.filter(lang => lang.tag !== this.props.language)
|
||||
.map(lang => {
|
||||
.filter((lang) => lang.tag !== this.props.language)
|
||||
.map((lang) => {
|
||||
// build the href so that we try to stay in current url but change the language.
|
||||
let href = siteConfig.baseUrl + lang.tag;
|
||||
if (
|
||||
|
@ -71,8 +71,8 @@ class LanguageDropDown extends React.Component {
|
|||
// Get the current language full name for display in the header nav
|
||||
const currentLanguage = env.translation
|
||||
.enabledLanguages()
|
||||
.filter(lang => lang.tag === this.props.language)
|
||||
.map(lang => lang.name);
|
||||
.filter((lang) => lang.tag === this.props.language)
|
||||
.map((lang) => lang.name);
|
||||
|
||||
// add Crowdin project recruiting link
|
||||
if (siteConfig.translationRecruitingLink) {
|
||||
|
@ -179,10 +179,10 @@ class HeaderNav extends React.Component {
|
|||
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: ${
|
||||
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.`;
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ class HeaderNav extends React.Component {
|
|||
const headerLinks = this.props.config.headerLinks;
|
||||
// add language drop down to end if location not specified
|
||||
let languages = false;
|
||||
headerLinks.forEach(link => {
|
||||
headerLinks.forEach((link) => {
|
||||
if (link.languages) {
|
||||
languages = true;
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ class HeaderNav extends React.Component {
|
|||
headerLinks.push({languages: true});
|
||||
}
|
||||
let search = false;
|
||||
headerLinks.forEach(link => {
|
||||
headerLinks.forEach((link) => {
|
||||
if (
|
||||
link.doc &&
|
||||
!fs.existsSync(`${CWD}/../${readMetadata.getDocsPath()}/`)
|
||||
|
|
|
@ -23,7 +23,7 @@ const Headings = ({headings}) => {
|
|||
if (!headings.length) return null;
|
||||
return (
|
||||
<ul className="toc-headings">
|
||||
{headings.map(heading => (
|
||||
{headings.map((heading) => (
|
||||
<li key={heading.hashLink}>
|
||||
<Link hashLink={heading.hashLink} content={heading.content} />
|
||||
<Headings headings={heading.children} />
|
||||
|
|
|
@ -61,7 +61,7 @@ class SideNav extends React.Component {
|
|||
return null;
|
||||
}
|
||||
|
||||
renderCategory = categoryItem => {
|
||||
renderCategory = (categoryItem) => {
|
||||
let ulClassName = '';
|
||||
let categoryClassName = 'navGroupCategoryTitle';
|
||||
let arrow;
|
||||
|
@ -89,7 +89,7 @@ class SideNav extends React.Component {
|
|||
{arrow}
|
||||
</h3>
|
||||
<ul className={ulClassName}>
|
||||
{categoryItem.children.map(item => {
|
||||
{categoryItem.children.map((item) => {
|
||||
switch (item.type) {
|
||||
case 'LINK':
|
||||
return this.renderItemLink(item);
|
||||
|
@ -104,7 +104,7 @@ class SideNav extends React.Component {
|
|||
);
|
||||
};
|
||||
|
||||
renderSubcategory = subcategoryItem => (
|
||||
renderSubcategory = (subcategoryItem) => (
|
||||
<div className="navGroup subNavGroup" key={subcategoryItem.title}>
|
||||
<h4 className="navGroupSubcategoryTitle">
|
||||
{this.getLocalizedCategoryString(subcategoryItem.title)}
|
||||
|
@ -113,7 +113,7 @@ class SideNav extends React.Component {
|
|||
</div>
|
||||
);
|
||||
|
||||
renderItemLink = linkItem => {
|
||||
renderItemLink = (linkItem) => {
|
||||
const linkMetadata = linkItem.item;
|
||||
const itemClasses = classNames('navListItem', {
|
||||
navListItemActive: linkMetadata.id === this.props.current.id,
|
||||
|
|
|
@ -109,7 +109,7 @@ class MarkdownRenderer {
|
|||
|
||||
// Allow client sites to register their own plugins
|
||||
if (siteConfig.markdownPlugins) {
|
||||
siteConfig.markdownPlugins.forEach(plugin => {
|
||||
siteConfig.markdownPlugins.forEach((plugin) => {
|
||||
md.use(plugin);
|
||||
});
|
||||
}
|
||||
|
@ -128,4 +128,4 @@ class MarkdownRenderer {
|
|||
|
||||
const renderMarkdown = new MarkdownRenderer();
|
||||
|
||||
module.exports = source => renderMarkdown.toHtml(source);
|
||||
module.exports = (source) => renderMarkdown.toHtml(source);
|
||||
|
|
|
@ -20,7 +20,7 @@ const tocRegex = new RegExp('<AUTOGENERATED_TABLE_OF_CONTENTS>', 'i');
|
|||
*
|
||||
*/
|
||||
function getTOC(content, headingTags = 'h2', subHeadingTags = 'h3') {
|
||||
const tagToLevel = tag => Number(tag.slice(1));
|
||||
const tagToLevel = (tag) => Number(tag.slice(1));
|
||||
const headingLevels = [].concat(headingTags).map(tagToLevel);
|
||||
const subHeadingLevels = subHeadingTags
|
||||
? [].concat(subHeadingTags).map(tagToLevel)
|
||||
|
@ -35,7 +35,7 @@ function getTOC(content, headingTags = 'h2', subHeadingTags = 'h3') {
|
|||
const slugger = new GithubSlugger();
|
||||
let current;
|
||||
|
||||
headings.forEach(heading => {
|
||||
headings.forEach((heading) => {
|
||||
const rawContent = heading.content;
|
||||
const rendered = md.renderInline(rawContent);
|
||||
|
||||
|
@ -68,8 +68,8 @@ function insertTOC(rawContent) {
|
|||
const filterRe = /^`[^`]*`/;
|
||||
const headers = getTOC(rawContent, 'h3', null);
|
||||
const tableOfContents = headers
|
||||
.filter(header => filterRe.test(header.rawContent))
|
||||
.map(header => ` - [${header.rawContent}](#${header.hashLink})`)
|
||||
.filter((header) => filterRe.test(header.rawContent))
|
||||
.map((header) => ` - [${header.rawContent}](#${header.hashLink})`)
|
||||
.join('\n');
|
||||
return rawContent.replace(tocRegex, tableOfContents);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ const excludePath = `${PROJECT_NAME}-${DEPLOYMENT_BRANCH}`;
|
|||
fs.copy(
|
||||
fromPath,
|
||||
toPath,
|
||||
src => {
|
||||
(src) => {
|
||||
if (src.indexOf('.DS_Store') !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ fs.copy(
|
|||
|
||||
return true;
|
||||
},
|
||||
error => {
|
||||
(error) => {
|
||||
if (error) {
|
||||
shell.echo(`Error: Copying build assets failed with error '${error}'`);
|
||||
shell.exit(1);
|
||||
|
|
|
@ -21,7 +21,7 @@ const CWD = process.cwd();
|
|||
// generate a doc header from metadata
|
||||
function makeHeader(metadata) {
|
||||
let header = '---\n';
|
||||
Object.keys(metadata).forEach(key => {
|
||||
Object.keys(metadata).forEach((key) => {
|
||||
header += `${key}: ${metadata[key]}\n`;
|
||||
});
|
||||
header += '---\n';
|
||||
|
@ -91,7 +91,7 @@ if (fs.existsSync(`${CWD}/versioned_docs/version-${currentVersion}`)) {
|
|||
);
|
||||
|
||||
const files = glob.sync(`${CWD}/versioned_docs/version-${newVersion}/*`);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
|
|
|
@ -145,7 +145,7 @@ describe('getFile', () => {
|
|||
'docs/doc1.md': 'Just another document',
|
||||
};
|
||||
fs.existsSync = jest.fn().mockReturnValue(true);
|
||||
fs.readFileSync = jest.fn().mockImplementation(file => {
|
||||
fs.readFileSync = jest.fn().mockImplementation((file) => {
|
||||
const fakePath = file.replace(
|
||||
process.cwd().replace(/website-1.x\/?$/, ''),
|
||||
'',
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = function loadConfig(configPath, deleteCache = true) {
|
|||
customDocsPath: 'docs',
|
||||
docsUrl: 'docs',
|
||||
};
|
||||
Object.keys(defaultConfig).forEach(field => {
|
||||
Object.keys(defaultConfig).forEach((field) => {
|
||||
if (!(field in config)) {
|
||||
config[field] = defaultConfig[field];
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ function mdToHtmlify(oldContent, mdToHtml, metadata, siteConfig) {
|
|||
let content = oldContent;
|
||||
/* Replace internal markdown linking (except in fenced blocks) */
|
||||
let fencedBlock = false;
|
||||
const lines = content.split('\n').map(line => {
|
||||
const lines = content.split('\n').map((line) => {
|
||||
if (line.trim().startsWith('```')) {
|
||||
fencedBlock = !fencedBlock;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class Translation {
|
|||
this.load();
|
||||
}
|
||||
|
||||
enabledLanguages = () => this.languages.filter(lang => lang.enabled);
|
||||
enabledLanguages = () => this.languages.filter((lang) => lang.enabled);
|
||||
|
||||
load() {
|
||||
if (fs.existsSync(languagesFile)) {
|
||||
|
|
|
@ -31,7 +31,7 @@ module.exports = function(type) {
|
|||
const MetadataPublicBlog =
|
||||
process.env.NODE_ENV === 'development'
|
||||
? MetadataBlog
|
||||
: MetadataBlog.filter(item => !item.unlisted);
|
||||
: MetadataBlog.filter((item) => !item.unlisted);
|
||||
|
||||
const feed = new Feed({
|
||||
title: `${siteConfig.title} Blog`,
|
||||
|
@ -43,7 +43,7 @@ module.exports = function(type) {
|
|||
updated: new Date(MetadataPublicBlog[0].date),
|
||||
});
|
||||
|
||||
MetadataPublicBlog.forEach(post => {
|
||||
MetadataPublicBlog.forEach((post) => {
|
||||
const url = `${blogRootURL}/${post.path}`;
|
||||
const description = utils.blogPostHasTruncateMarker(post.content)
|
||||
? renderMarkdown(utils.extractBlogPostBeforeTruncate(post.content))
|
||||
|
|
|
@ -72,7 +72,7 @@ async function execute() {
|
|||
|
||||
// create html files for all docs by going through all doc ids
|
||||
const mdToHtml = metadataUtils.mdToHtml(Metadata, siteConfig);
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
Object.keys(Metadata).forEach((id) => {
|
||||
const metadata = Metadata[id];
|
||||
const file = docs.getFile(metadata);
|
||||
if (!file) {
|
||||
|
@ -118,7 +118,7 @@ async function execute() {
|
|||
files
|
||||
.sort()
|
||||
.reverse()
|
||||
.forEach(file => {
|
||||
.forEach((file) => {
|
||||
// Why normalize? In case we are on Windows.
|
||||
// Remember the nuance of glob: https://www.npmjs.com/package/glob#windows
|
||||
const normalizedFile = path.normalize(file);
|
||||
|
@ -137,7 +137,7 @@ async function execute() {
|
|||
|
||||
// create html files for all blog pages (collections of article previews)
|
||||
const blogPages = blog.getPagesMarkup(MetadataBlog.length, siteConfig);
|
||||
Object.keys(blogPages).forEach(pagePath => {
|
||||
Object.keys(blogPages).forEach((pagePath) => {
|
||||
const targetFile = join(buildDir, 'blog', pagePath);
|
||||
writeFileAndCreateFolder(targetFile, blogPages[pagePath]);
|
||||
});
|
||||
|
@ -168,7 +168,7 @@ async function execute() {
|
|||
// copy all static files from docusaurus
|
||||
const libStaticDir = join(__dirname, '..', 'static');
|
||||
files = glob.sync(join(libStaticDir, '**'));
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
// Why normalize? In case we are on Windows.
|
||||
// Remember the nuance of glob: https://www.npmjs.com/package/glob#windows
|
||||
const targetFile = path.normalize(file).replace(libStaticDir, buildDir);
|
||||
|
@ -188,15 +188,15 @@ async function execute() {
|
|||
);
|
||||
}
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
Object.keys(siteConfig.colors).forEach((key) => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp(`\\$${key}`, 'g'), color);
|
||||
});
|
||||
|
||||
if (siteConfig.fonts) {
|
||||
Object.keys(siteConfig.fonts).forEach(key => {
|
||||
Object.keys(siteConfig.fonts).forEach((key) => {
|
||||
const fontString = siteConfig.fonts[key]
|
||||
.map(font => `"${font}"`)
|
||||
.map((font) => `"${font}"`)
|
||||
.join(', ');
|
||||
cssContent = cssContent.replace(
|
||||
new RegExp(`\\$${key}`, 'g'),
|
||||
|
@ -216,7 +216,7 @@ async function execute() {
|
|||
// Copy all static files from user.
|
||||
const userStaticDir = join(CWD, 'static');
|
||||
files = glob.sync(join(userStaticDir, '**'), {dot: true});
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
// Why normalize? In case we are on Windows.
|
||||
// Remember the nuance of glob: https://www.npmjs.com/package/glob#windows
|
||||
const normalizedFile = path.normalize(file);
|
||||
|
@ -229,15 +229,15 @@ async function execute() {
|
|||
let cssContent = fs.readFileSync(normalizedFile, 'utf8');
|
||||
cssContent = `${fs.readFileSync(mainCss, 'utf8')}\n${cssContent}`;
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
Object.keys(siteConfig.colors).forEach((key) => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp(`\\$${key}`, 'g'), color);
|
||||
});
|
||||
|
||||
if (siteConfig.fonts) {
|
||||
Object.keys(siteConfig.fonts).forEach(key => {
|
||||
Object.keys(siteConfig.fonts).forEach((key) => {
|
||||
const fontString = siteConfig.fonts[key]
|
||||
.map(font => `"${font}"`)
|
||||
.map((font) => `"${font}"`)
|
||||
.join(', ');
|
||||
cssContent = cssContent.replace(
|
||||
new RegExp(`\\$${key}`, 'g'),
|
||||
|
@ -264,7 +264,7 @@ async function execute() {
|
|||
}),
|
||||
imageminGifsicle(),
|
||||
],
|
||||
}).catch(error => {
|
||||
}).catch((error) => {
|
||||
// if image compression fail, just copy it as it is
|
||||
console.error(error);
|
||||
fs.copySync(normalizedFile, targetFile);
|
||||
|
@ -287,10 +287,10 @@ async function execute() {
|
|||
// compile/copy pages from user
|
||||
const enabledLanguages = env.translation
|
||||
.enabledLanguages()
|
||||
.map(lang => lang.tag);
|
||||
.map((lang) => lang.tag);
|
||||
const userPagesDir = join(CWD, 'pages');
|
||||
files = glob.sync(join(userPagesDir, '**'));
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
// Why normalize? In case we are on Windows.
|
||||
// Remember the nuance of glob: https://www.npmjs.com/package/glob#windows
|
||||
const normalizedFile = path.normalize(file);
|
||||
|
|
|
@ -49,10 +49,7 @@ function extractMetadata(content) {
|
|||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
const keyvalue = lines[i].split(':');
|
||||
const key = keyvalue[0].trim();
|
||||
let value = keyvalue
|
||||
.slice(1)
|
||||
.join(':')
|
||||
.trim();
|
||||
let value = keyvalue.slice(1).join(':').trim();
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (err) {
|
||||
|
@ -68,7 +65,7 @@ function extractMetadata(content) {
|
|||
function mdToHtml(Metadata, siteConfig) {
|
||||
const {baseUrl, docsUrl} = siteConfig;
|
||||
const result = {};
|
||||
Object.keys(Metadata).forEach(id => {
|
||||
Object.keys(Metadata).forEach((id) => {
|
||||
const metadata = Metadata[id];
|
||||
if (metadata.language !== 'en' || metadata.original_id) {
|
||||
return;
|
||||
|
|
|
@ -13,34 +13,34 @@ function readCategories(sidebar, allMetadata, languages) {
|
|||
|
||||
// Go through each language that might be defined.
|
||||
languages
|
||||
.filter(lang => lang.enabled)
|
||||
.map(lang => lang.tag)
|
||||
.forEach(language => {
|
||||
.filter((lang) => lang.enabled)
|
||||
.map((lang) => lang.tag)
|
||||
.forEach((language) => {
|
||||
// Get all related metadata for the current sidebar and specific to the language.
|
||||
const metadatas = Object.values(allMetadata)
|
||||
.filter(
|
||||
metadata =>
|
||||
(metadata) =>
|
||||
metadata.sidebar === sidebar && metadata.language === language,
|
||||
)
|
||||
.sort((a, b) => a.order - b.order);
|
||||
|
||||
// Define the correct order of categories.
|
||||
const sortedCategories = _.uniq(
|
||||
metadatas.map(metadata => metadata.category),
|
||||
metadatas.map((metadata) => metadata.category),
|
||||
);
|
||||
|
||||
const metadatasGroupedByCategory = _.chain(metadatas)
|
||||
.groupBy(metadata => metadata.category)
|
||||
.mapValues(categoryItems => {
|
||||
.groupBy((metadata) => metadata.category)
|
||||
.mapValues((categoryItems) => {
|
||||
// Process subcategories.
|
||||
const metadatasGroupedBySubcategory = _.groupBy(
|
||||
categoryItems,
|
||||
item => item.subcategory,
|
||||
(item) => item.subcategory,
|
||||
);
|
||||
const result = [];
|
||||
const seenSubcategories = new Set();
|
||||
// categoryItems can be links or subcategories. Handle separately.
|
||||
categoryItems.forEach(item => {
|
||||
categoryItems.forEach((item) => {
|
||||
// Has no subcategory.
|
||||
if (item.subcategory == null) {
|
||||
result.push({
|
||||
|
@ -59,7 +59,7 @@ function readCategories(sidebar, allMetadata, languages) {
|
|||
seenSubcategories.add(subcategory);
|
||||
const subcategoryLinks = metadatasGroupedBySubcategory[
|
||||
subcategory
|
||||
].map(subcategoryItem => ({
|
||||
].map((subcategoryItem) => ({
|
||||
type: 'LINK',
|
||||
item: subcategoryItem,
|
||||
}));
|
||||
|
@ -74,7 +74,7 @@ function readCategories(sidebar, allMetadata, languages) {
|
|||
})
|
||||
.value();
|
||||
|
||||
const categories = sortedCategories.map(category => ({
|
||||
const categories = sortedCategories.map((category) => ({
|
||||
type: 'CATEGORY',
|
||||
title: category,
|
||||
children: metadatasGroupedByCategory[category],
|
||||
|
|
|
@ -66,17 +66,17 @@ function readSidebar(sidebars = {}) {
|
|||
|
||||
const items = {};
|
||||
|
||||
Object.keys(sidebars).forEach(sidebar => {
|
||||
Object.keys(sidebars).forEach((sidebar) => {
|
||||
const categories = sidebars[sidebar];
|
||||
const sidebarItems = [];
|
||||
|
||||
Object.keys(categories).forEach(category => {
|
||||
Object.keys(categories).forEach((category) => {
|
||||
const categoryItems = categories[category];
|
||||
categoryItems.forEach(categoryItem => {
|
||||
categoryItems.forEach((categoryItem) => {
|
||||
if (typeof categoryItem === 'object') {
|
||||
switch (categoryItem.type) {
|
||||
case 'subcategory':
|
||||
categoryItem.ids.forEach(subcategoryItem => {
|
||||
categoryItem.ids.forEach((subcategoryItem) => {
|
||||
sidebarItems.push({
|
||||
id: subcategoryItem,
|
||||
category,
|
||||
|
@ -133,7 +133,7 @@ function processMetadata(file, refDir) {
|
|||
const language = utils.getLanguage(file, refDir) || 'en';
|
||||
|
||||
const metadata = {};
|
||||
Object.keys(result.metadata).forEach(fieldName => {
|
||||
Object.keys(result.metadata).forEach((fieldName) => {
|
||||
if (SupportedHeaderFields.has(fieldName)) {
|
||||
metadata[fieldName] = result.metadata[fieldName];
|
||||
} else {
|
||||
|
@ -219,7 +219,7 @@ function generateMetadataDocs() {
|
|||
|
||||
const enabledLanguages = env.translation
|
||||
.enabledLanguages()
|
||||
.map(language => language.tag);
|
||||
.map((language) => language.tag);
|
||||
|
||||
const metadatas = {};
|
||||
const defaultMetadatas = {};
|
||||
|
@ -228,7 +228,7 @@ function generateMetadataDocs() {
|
|||
// metadata for english files
|
||||
const docsDir = path.join(CWD, '../', getDocsPath());
|
||||
let files = glob.sync(`${docsDir}/**`);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
const extension = path.extname(file);
|
||||
|
||||
if (extension === '.md' || extension === '.markdown') {
|
||||
|
@ -243,8 +243,8 @@ function generateMetadataDocs() {
|
|||
// create a default list of documents for each enabled language based on docs in English
|
||||
// these will get replaced if/when the localized file is downloaded from crowdin
|
||||
enabledLanguages
|
||||
.filter(currentLanguage => currentLanguage !== 'en')
|
||||
.forEach(currentLanguage => {
|
||||
.filter((currentLanguage) => currentLanguage !== 'en')
|
||||
.forEach((currentLanguage) => {
|
||||
const baseMetadata = Object.assign({}, metadata);
|
||||
baseMetadata.id = baseMetadata.id
|
||||
.toString()
|
||||
|
@ -277,7 +277,7 @@ function generateMetadataDocs() {
|
|||
// metadata for non-english docs
|
||||
const translatedDir = path.join(CWD, 'translated_docs');
|
||||
files = glob.sync(`${CWD}/translated_docs/**`);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
if (!utils.getLanguage(file, translatedDir)) {
|
||||
return;
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ function generateMetadataDocs() {
|
|||
|
||||
// metadata for versioned docs
|
||||
const versionData = versionFallback.docData();
|
||||
versionData.forEach(metadata => {
|
||||
versionData.forEach((metadata) => {
|
||||
const id = metadata.localized_id;
|
||||
if (order[id]) {
|
||||
metadata.sidebar = order[id].sidebar;
|
||||
|
@ -329,7 +329,7 @@ function generateMetadataDocs() {
|
|||
|
||||
// Get the titles of the previous and next ids so that we can use them in
|
||||
// navigation buttons in DocsLayout.js
|
||||
Object.keys(metadatas).forEach(metadata => {
|
||||
Object.keys(metadatas).forEach((metadata) => {
|
||||
if (metadatas[metadata].previous) {
|
||||
if (metadatas[metadatas[metadata].previous]) {
|
||||
metadatas[metadata].previous_title =
|
||||
|
@ -350,11 +350,13 @@ function generateMetadataDocs() {
|
|||
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '/../core/metadata.js'),
|
||||
`${'/**\n' +
|
||||
`${
|
||||
'/**\n' +
|
||||
' * @' +
|
||||
'generated\n' + // separate this out for Nuclide treating @generated as readonly
|
||||
' */\n' +
|
||||
'module.exports = '}${JSON.stringify(metadatas, null, 2)};\n`,
|
||||
'module.exports = '
|
||||
}${JSON.stringify(metadatas, null, 2)};\n`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -366,7 +368,7 @@ function generateMetadataBlog(config = siteConfig) {
|
|||
files
|
||||
.sort()
|
||||
.reverse()
|
||||
.forEach(file => {
|
||||
.forEach((file) => {
|
||||
const extension = path.extname(file);
|
||||
if (extension !== '.md' && extension !== '.markdown') {
|
||||
return;
|
||||
|
@ -389,11 +391,13 @@ function generateMetadataBlog(config = siteConfig) {
|
|||
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '/../core/MetadataBlog.js'),
|
||||
`${'/**\n' +
|
||||
`${
|
||||
'/**\n' +
|
||||
' * @' +
|
||||
'generated\n' + // separate this out for Nuclide treating @generated as readonly
|
||||
' */\n' +
|
||||
'module.exports = '}${JSON.stringify(sortedMetadatas, null, 2)};\n`,
|
||||
'module.exports = '
|
||||
}${JSON.stringify(sortedMetadatas, null, 2)};\n`,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ function noExtension() {
|
|||
}
|
||||
|
||||
function page(siteConfig) {
|
||||
const gr = regex => regex.toString().replace(/(^\/|\/$)/gm, '');
|
||||
const gr = (regex) => regex.toString().replace(/(^\/|\/$)/gm, '');
|
||||
|
||||
if (siteConfig.docsUrl === '') {
|
||||
return new RegExp(
|
||||
|
|
|
@ -34,7 +34,7 @@ function execute(port, host) {
|
|||
|
||||
function removeModulePathFromCache(moduleName) {
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
Object.keys(module.constructor._pathCache).forEach(cacheKey => {
|
||||
Object.keys(module.constructor._pathCache).forEach((cacheKey) => {
|
||||
if (cacheKey.indexOf(moduleName) > 0) {
|
||||
delete module.constructor._pathCache[cacheKey];
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ function execute(port, host) {
|
|||
function removeModuleAndChildrenFromCache(moduleName) {
|
||||
let mod = require.resolve(moduleName);
|
||||
if (mod && (mod = require.cache[mod])) {
|
||||
mod.children.forEach(child => {
|
||||
mod.children.forEach((child) => {
|
||||
delete require.cache[child.id];
|
||||
removeModulePathFromCache(mod.id);
|
||||
});
|
||||
|
@ -121,7 +121,7 @@ function execute(port, host) {
|
|||
app.get(routing.docs(siteConfig), (req, res, next) => {
|
||||
const url = decodeURI(req.path.toString().replace(siteConfig.baseUrl, ''));
|
||||
const metakey = Object.keys(Metadata).find(
|
||||
id => Metadata[id].permalink === url,
|
||||
(id) => Metadata[id].permalink === url,
|
||||
);
|
||||
|
||||
let metadata = Metadata[metakey];
|
||||
|
@ -137,7 +137,7 @@ function execute(port, host) {
|
|||
|
||||
// if any of the followings is changed, reload the metadata
|
||||
const reloadTriggers = ['sidebar_label', 'hide_title', 'title'];
|
||||
if (reloadTriggers.some(key => metadata[key] !== rawMetadata[key])) {
|
||||
if (reloadTriggers.some((key) => metadata[key] !== rawMetadata[key])) {
|
||||
reloadMetadata();
|
||||
extractTranslations();
|
||||
reloadTranslations();
|
||||
|
@ -163,10 +163,7 @@ function execute(port, host) {
|
|||
|
||||
app.get(routing.feed(siteConfig), (req, res, next) => {
|
||||
res.set('Content-Type', 'application/rss+xml');
|
||||
const file = req.path
|
||||
.toString()
|
||||
.split('blog/')[1]
|
||||
.toLowerCase();
|
||||
const file = req.path.toString().split('blog/')[1].toLowerCase();
|
||||
if (file === 'atom.xml') {
|
||||
res.send(feed('atom'));
|
||||
} else if (file === 'feed.xml') {
|
||||
|
@ -250,7 +247,7 @@ function execute(port, host) {
|
|||
const parts = match[1].split('/');
|
||||
const enabledLangTags = env.translation
|
||||
.enabledLanguages()
|
||||
.map(lang => lang.tag);
|
||||
.map((lang) => lang.tag);
|
||||
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (enabledLangTags.indexOf(parts[i]) !== -1) {
|
||||
|
@ -321,7 +318,7 @@ function execute(port, host) {
|
|||
|
||||
const files = glob.sync(join(CWD, 'static', '**', '*.css'));
|
||||
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
if (isSeparateCss(file, siteConfig.separateCss)) {
|
||||
return;
|
||||
}
|
||||
|
@ -342,15 +339,15 @@ function execute(port, host) {
|
|||
);
|
||||
}
|
||||
|
||||
Object.keys(siteConfig.colors).forEach(key => {
|
||||
Object.keys(siteConfig.colors).forEach((key) => {
|
||||
const color = siteConfig.colors[key];
|
||||
cssContent = cssContent.replace(new RegExp(`\\$${key}`, 'g'), color);
|
||||
});
|
||||
|
||||
if (siteConfig.fonts) {
|
||||
Object.keys(siteConfig.fonts).forEach(key => {
|
||||
Object.keys(siteConfig.fonts).forEach((key) => {
|
||||
const fontString = siteConfig.fonts[key]
|
||||
.map(font => `"${font}"`)
|
||||
.map((font) => `"${font}"`)
|
||||
.join(', ');
|
||||
cssContent = cssContent.replace(
|
||||
new RegExp(`\\$${key}`, 'g'),
|
||||
|
|
|
@ -43,23 +43,23 @@ module.exports = function(callback) {
|
|||
// If we have a languages.js file, get all the enabled languages in there
|
||||
if (fs.existsSync(`${CWD}/languages.js`)) {
|
||||
const languages = require(`${CWD}/languages.js`);
|
||||
enabledLanguages = languages.filter(lang => lang.enabled);
|
||||
enabledLanguages = languages.filter((lang) => lang.enabled);
|
||||
}
|
||||
|
||||
// Create a url mapping to all the enabled languages files
|
||||
const urls = files.map(file => {
|
||||
const urls = files.map((file) => {
|
||||
let url = file.split('/pages/en')[1];
|
||||
url = siteConfig.cleanUrl
|
||||
? url.replace(/\.js$/, '')
|
||||
: url.replace(/\.js$/, '.html');
|
||||
const links = enabledLanguages.map(lang => {
|
||||
const links = enabledLanguages.map((lang) => {
|
||||
const langUrl = lang.tag + url;
|
||||
return {lang: lang.tag, url: langUrl};
|
||||
});
|
||||
return {url, changefreq: 'weekly', priority: 0.5, links};
|
||||
});
|
||||
|
||||
MetadataBlog.forEach(blog => {
|
||||
MetadataBlog.forEach((blog) => {
|
||||
urls.push({
|
||||
url: `/blog/${utils.getPath(blog.path, siteConfig.cleanUrl)}`,
|
||||
changefreq: 'weekly',
|
||||
|
@ -68,12 +68,12 @@ module.exports = function(callback) {
|
|||
});
|
||||
|
||||
Object.keys(Metadata)
|
||||
.filter(key => Metadata[key].language === 'en')
|
||||
.forEach(key => {
|
||||
.filter((key) => Metadata[key].language === 'en')
|
||||
.forEach((key) => {
|
||||
const doc = Metadata[key];
|
||||
const docUrl = utils.getPath(doc.permalink, siteConfig.cleanUrl);
|
||||
const docsPart = `${siteConfig.docsUrl ? `${siteConfig.docsUrl}/` : ''}`;
|
||||
const links = enabledLanguages.map(lang => {
|
||||
const links = enabledLanguages.map((lang) => {
|
||||
const langUrl = docUrl.replace(
|
||||
new RegExp(`^${docsPart}en/`),
|
||||
`${docsPart}${lang.tag}/`,
|
||||
|
|
|
@ -14,7 +14,7 @@ const server = require('./server.js');
|
|||
const CWD = process.cwd();
|
||||
|
||||
function startLiveReloadServer() {
|
||||
const promise = portFinder.getPortPromise({port: 35729}).then(port => {
|
||||
const promise = portFinder.getPortPromise({port: 35729}).then((port) => {
|
||||
liveReloadServer.start(port);
|
||||
});
|
||||
return promise;
|
||||
|
@ -26,7 +26,7 @@ function startServer() {
|
|||
const host = program.host || 'localhost';
|
||||
const promise = portFinder
|
||||
.getPortPromise({port: initialServerPort})
|
||||
.then(port => {
|
||||
.then((port) => {
|
||||
server(port, host);
|
||||
const {baseUrl} = require(`${CWD}/siteConfig.js`);
|
||||
const serverAddress = `http://${host}:${port}${baseUrl}`;
|
||||
|
@ -39,7 +39,7 @@ function startServer() {
|
|||
function startDocusaurus() {
|
||||
if (program.watch) {
|
||||
return startLiveReloadServer()
|
||||
.catch(ex => console.warn(`Failed to start live reload server: ${ex}`))
|
||||
.catch((ex) => console.warn(`Failed to start live reload server: ${ex}`))
|
||||
.then(() => startServer());
|
||||
}
|
||||
return startServer();
|
||||
|
|
|
@ -25,14 +25,14 @@ if (fs.existsSync(`${CWD}/languages.js`)) {
|
|||
];
|
||||
}
|
||||
|
||||
const enabledLanguages = languages.filter(lang => lang.enabled);
|
||||
const enabledLanguages = languages.filter((lang) => lang.enabled);
|
||||
|
||||
const translation = {languages: enabledLanguages};
|
||||
|
||||
const files = glob.sync(`${CWD}/i18n/**`);
|
||||
const langRegex = /\/i18n\/(.*)\.json$/;
|
||||
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === '.json') {
|
||||
const match = langRegex.exec(file);
|
||||
|
|
|
@ -28,7 +28,7 @@ function getLanguage(file, refDir) {
|
|||
if (match && env.translation.enabled) {
|
||||
const enabledLanguages = env.translation
|
||||
.enabledLanguages()
|
||||
.map(language => language.tag);
|
||||
.map((language) => language.tag);
|
||||
if (enabledLanguages.indexOf(match[1]) !== -1) {
|
||||
return match[1];
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ function minifyCss(cssContent) {
|
|||
zindex: false,
|
||||
from: undefined,
|
||||
})
|
||||
.then(result => result.css);
|
||||
.then((result) => result.css);
|
||||
}
|
||||
|
||||
function autoPrefixCss(cssContent) {
|
||||
|
@ -63,12 +63,12 @@ function autoPrefixCss(cssContent) {
|
|||
.process(cssContent, {
|
||||
from: undefined,
|
||||
})
|
||||
.then(result => result.css);
|
||||
.then((result) => result.css);
|
||||
}
|
||||
|
||||
function replaceAssetsLink(oldContent, location) {
|
||||
let fencedBlock = false;
|
||||
const lines = oldContent.split('\n').map(line => {
|
||||
const lines = oldContent.split('\n').map((line) => {
|
||||
if (line.trim().startsWith('```')) {
|
||||
fencedBlock = !fencedBlock;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ const available = {};
|
|||
// given version/id of a document
|
||||
const versionFiles = {};
|
||||
const files = glob.sync(`${versionFolder}**`);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
const ext = path.extname(file);
|
||||
if (ext !== '.md' && ext !== '.markdown') {
|
||||
return;
|
||||
|
@ -210,8 +210,8 @@ function processVersionMetadata(file, version, useVersion, language) {
|
|||
// return all metadata of versioned documents
|
||||
function docData() {
|
||||
const allIds = new Set();
|
||||
Object.keys(versionFiles).forEach(version => {
|
||||
Object.keys(versionFiles[version]).forEach(id => {
|
||||
Object.keys(versionFiles).forEach((version) => {
|
||||
Object.keys(versionFiles[version]).forEach((id) => {
|
||||
allIds.add(id);
|
||||
});
|
||||
});
|
||||
|
@ -219,10 +219,10 @@ function docData() {
|
|||
const metadatas = [];
|
||||
|
||||
languages
|
||||
.filter(language => language.enabled)
|
||||
.forEach(language => {
|
||||
versions.forEach(version => {
|
||||
allIds.forEach(id => {
|
||||
.filter((language) => language.enabled)
|
||||
.forEach((language) => {
|
||||
versions.forEach((version) => {
|
||||
allIds.forEach((id) => {
|
||||
let useVersion;
|
||||
try {
|
||||
useVersion = docVersion(id, version);
|
||||
|
|
|
@ -48,7 +48,7 @@ program
|
|||
.option('--host <host>', 'use specified host (default: localhost)')
|
||||
.parse(process.argv);
|
||||
|
||||
startDocusaurus().catch(ex => {
|
||||
startDocusaurus().catch((ex) => {
|
||||
console.error(chalk.red(`Failed to start Docusaurus server: ${ex}`));
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
|
@ -46,7 +46,7 @@ let version;
|
|||
|
||||
program
|
||||
.arguments('<version>')
|
||||
.action(ver => {
|
||||
.action((ver) => {
|
||||
version = ver;
|
||||
})
|
||||
.parse(process.argv);
|
||||
|
@ -85,7 +85,7 @@ if (versions.includes(version)) {
|
|||
|
||||
function makeHeader(metadata) {
|
||||
let header = '---\n';
|
||||
Object.keys(metadata).forEach(key => {
|
||||
Object.keys(metadata).forEach((key) => {
|
||||
header += `${key}: ${metadata[key]}\n`;
|
||||
});
|
||||
header += '---\n';
|
||||
|
@ -104,7 +104,7 @@ mkdirp.sync(versionFolder);
|
|||
|
||||
// copy necessary files to new version, changing some of its metadata to reflect the versioning
|
||||
const files = glob.sync(`${CWD}/../${readMetadata.getDocsPath()}/**`);
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
const ext = path.extname(file);
|
||||
if (ext !== '.md' && ext !== '.markdown') {
|
||||
return;
|
||||
|
@ -153,21 +153,21 @@ if (versionFallback.diffLatestSidebar()) {
|
|||
const sidebar = JSON.parse(fs.readFileSync(`${CWD}/sidebars.json`, 'utf8'));
|
||||
const versioned = {};
|
||||
|
||||
Object.keys(sidebar).forEach(sb => {
|
||||
Object.keys(sidebar).forEach((sb) => {
|
||||
const versionSidebar = `version-${version}-${sb}`;
|
||||
versioned[versionSidebar] = {};
|
||||
|
||||
const categories = sidebar[sb];
|
||||
Object.keys(categories).forEach(category => {
|
||||
Object.keys(categories).forEach((category) => {
|
||||
versioned[versionSidebar][category] = [];
|
||||
|
||||
const categoryItems = categories[category];
|
||||
categoryItems.forEach(categoryItem => {
|
||||
categoryItems.forEach((categoryItem) => {
|
||||
let versionedCategoryItem = categoryItem;
|
||||
if (typeof categoryItem === 'object') {
|
||||
if (categoryItem.ids && categoryItem.ids.length > 0) {
|
||||
versionedCategoryItem.ids = categoryItem.ids.map(
|
||||
id => `version-${version}-${id}`,
|
||||
(id) => `version-${version}-${id}`,
|
||||
);
|
||||
}
|
||||
} else if (typeof categoryItem === 'string') {
|
||||
|
|
|
@ -102,27 +102,27 @@ function execute() {
|
|||
}
|
||||
}
|
||||
};
|
||||
glob.sync(`${docsDir}/**`).forEach(file => translateDoc(file, docsDir));
|
||||
glob.sync(`${docsDir}/**`).forEach((file) => translateDoc(file, docsDir));
|
||||
glob
|
||||
.sync(`${versionedDocsDir}/**`)
|
||||
.forEach(file => translateDoc(file, versionedDocsDir));
|
||||
.forEach((file) => translateDoc(file, versionedDocsDir));
|
||||
|
||||
// look through header links for text to translate
|
||||
siteConfig.headerLinks.forEach(link => {
|
||||
siteConfig.headerLinks.forEach((link) => {
|
||||
if (link.label) {
|
||||
translations['localized-strings'].links[link.label] = link.label;
|
||||
}
|
||||
});
|
||||
|
||||
// find sidebar category titles to translate
|
||||
Object.keys(sidebars).forEach(sb => {
|
||||
Object.keys(sidebars).forEach((sb) => {
|
||||
const categories = sidebars[sb];
|
||||
Object.keys(categories).forEach(category => {
|
||||
Object.keys(categories).forEach((category) => {
|
||||
translations['localized-strings'].categories[category] = category;
|
||||
});
|
||||
});
|
||||
|
||||
glob.sync(`${CWD}/versioned_sidebars/*`).forEach(file => {
|
||||
glob.sync(`${CWD}/versioned_sidebars/*`).forEach((file) => {
|
||||
if (!file.endsWith('-sidebars.json')) {
|
||||
if (file.endsWith('-sidebar.json')) {
|
||||
console.warn(
|
||||
|
@ -139,16 +139,16 @@ function execute() {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
Object.keys(sidebarContent).forEach(sb => {
|
||||
Object.keys(sidebarContent).forEach((sb) => {
|
||||
const categories = sidebarContent[sb];
|
||||
Object.keys(categories).forEach(category => {
|
||||
Object.keys(categories).forEach((category) => {
|
||||
translations['localized-strings'].categories[category] = category;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// go through pages to look for text inside translate tags
|
||||
glob.sync(`${CWD}/pages/en/**`).forEach(file => {
|
||||
glob.sync(`${CWD}/pages/en/**`).forEach((file) => {
|
||||
const extension = nodePath.extname(file);
|
||||
if (extension === '.js') {
|
||||
const ast = babylon.parse(fs.readFileSync(file, 'utf8'), {
|
||||
|
|
|
@ -26,7 +26,7 @@ if (!semver.satisfies(process.version, requiredVersion)) {
|
|||
|
||||
function wrapCommand(fn) {
|
||||
return (...args) =>
|
||||
fn(...args).catch(err => {
|
||||
fn(...args).catch((err) => {
|
||||
console.error(chalk.red(err.stack));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
@ -43,7 +43,7 @@ program
|
|||
wrapCommand(init)(path.resolve(rootDir), siteName, template);
|
||||
});
|
||||
|
||||
program.arguments('<command>').action(cmd => {
|
||||
program.arguments('<command>').action((cmd) => {
|
||||
program.outputHelp();
|
||||
console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`);
|
||||
console.log();
|
||||
|
|
|
@ -23,7 +23,7 @@ function hasYarn(): boolean {
|
|||
}
|
||||
|
||||
function isValidGitRepoUrl(gitRepoUrl: string): boolean {
|
||||
return ['https://', 'git@'].some(item => gitRepoUrl.startsWith(item));
|
||||
return ['https://', 'git@'].some((item) => gitRepoUrl.startsWith(item));
|
||||
}
|
||||
|
||||
async function updatePkg(pkgPath: string, obj: any): Promise<void> {
|
||||
|
@ -43,7 +43,7 @@ export async function init(
|
|||
const templatesDir = path.resolve(__dirname, '../templates');
|
||||
const templates = fs
|
||||
.readdirSync(templatesDir)
|
||||
.filter(d => !d.startsWith('.') && !d.startsWith('README'));
|
||||
.filter((d) => !d.startsWith('.') && !d.startsWith('README'));
|
||||
|
||||
const gitChoice = 'Git repository';
|
||||
const templateChoices = [...templates, gitChoice];
|
||||
|
|
|
@ -14,15 +14,15 @@ const parseOptions = {
|
|||
plugins: ['jsx'],
|
||||
sourceType: 'module',
|
||||
};
|
||||
const isImport = child => child.type === 'import';
|
||||
const hasImports = index => index > -1;
|
||||
const isExport = child => child.type === 'export';
|
||||
const isImport = (child) => child.type === 'import';
|
||||
const hasImports = (index) => index > -1;
|
||||
const isExport = (child) => child.type === 'export';
|
||||
|
||||
const isTarget = (child, name) => {
|
||||
let found = false;
|
||||
const ast = parse(child.value, parseOptions);
|
||||
traverse(ast, {
|
||||
VariableDeclarator: path => {
|
||||
VariableDeclarator: (path) => {
|
||||
if (path.node.id.name === name) {
|
||||
found = true;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ const getOrCreateExistingTargetIndex = (children, name) => {
|
|||
const plugin = (options = {}) => {
|
||||
const name = options.name || 'rightToc';
|
||||
|
||||
const transformer = node => {
|
||||
const transformer = (node) => {
|
||||
const headings = search(node);
|
||||
const {children} = node;
|
||||
const targetIndex = getOrCreateExistingTargetIndex(children, name);
|
||||
|
|
|
@ -12,7 +12,7 @@ const toString = require('mdast-util-to-string');
|
|||
const slugs = require('github-slugger')();
|
||||
|
||||
function slug() {
|
||||
const transformer = ast => {
|
||||
const transformer = (ast) => {
|
||||
slugs.reset();
|
||||
|
||||
function visitor(headingNode) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import {LoadContext} from '@docusaurus/types';
|
|||
import {PluginOptions} from '../types';
|
||||
|
||||
describe('blogFeed', () => {
|
||||
['atom', 'rss'].forEach(feedType => {
|
||||
['atom', 'rss'].forEach((feedType) => {
|
||||
describe(`${feedType}`, () => {
|
||||
test('can show feed without posts', async () => {
|
||||
const siteConfig = {
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('loadBlog', () => {
|
|||
.replace(/-/g, '/')}/no date`;
|
||||
|
||||
expect({
|
||||
...blogPosts.find(v => v.metadata.title === 'date-matter').metadata,
|
||||
...blogPosts.find((v) => v.metadata.title === 'date-matter').metadata,
|
||||
...{prevItem: undefined},
|
||||
}).toEqual({
|
||||
editUrl:
|
||||
|
@ -70,7 +70,7 @@ describe('loadBlog', () => {
|
|||
});
|
||||
|
||||
expect(
|
||||
blogPosts.find(v => v.metadata.title === 'Happy 1st Birthday Slash!')
|
||||
blogPosts.find((v) => v.metadata.title === 'Happy 1st Birthday Slash!')
|
||||
.metadata,
|
||||
).toEqual({
|
||||
editUrl:
|
||||
|
@ -94,7 +94,7 @@ describe('loadBlog', () => {
|
|||
});
|
||||
|
||||
expect({
|
||||
...blogPosts.find(v => v.metadata.title === 'no date').metadata,
|
||||
...blogPosts.find((v) => v.metadata.title === 'no date').metadata,
|
||||
...{prevItem: undefined},
|
||||
}).toEqual({
|
||||
editUrl:
|
||||
|
@ -119,6 +119,6 @@ describe('loadBlog', () => {
|
|||
process.env.NODE_ENV = 'production';
|
||||
const blogPosts = await getBlogPosts();
|
||||
|
||||
expect(blogPosts.find(v => v.metadata.title === 'draft')).toBeUndefined();
|
||||
expect(blogPosts.find((v) => v.metadata.title === 'draft')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -36,7 +36,7 @@ const blogPosts: BlogPost[] = [
|
|||
},
|
||||
];
|
||||
|
||||
const transform = filepath => {
|
||||
const transform = (filepath) => {
|
||||
const content = fs.readFileSync(filepath, 'utf-8');
|
||||
const transformedContent = linkify(content, sitePath, blogPath, blogPosts);
|
||||
return [content, transformedContent];
|
||||
|
|
|
@ -69,7 +69,7 @@ export async function generateBlogFeed(
|
|||
copyright: feedOptions.copyright,
|
||||
});
|
||||
|
||||
blogPosts.forEach(post => {
|
||||
blogPosts.forEach((post) => {
|
||||
const {
|
||||
id,
|
||||
metadata: {title, permalink, date, description},
|
||||
|
@ -184,7 +184,7 @@ export function linkify(
|
|||
blogPosts: BlogPost[],
|
||||
) {
|
||||
let fencedBlock = false;
|
||||
const lines = fileContent.split('\n').map(line => {
|
||||
const lines = fileContent.split('\n').map((line) => {
|
||||
if (line.trim().startsWith('```')) {
|
||||
fencedBlock = !fencedBlock;
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ export function linkify(
|
|||
)}`;
|
||||
let blogPostPermalink = null;
|
||||
|
||||
blogPosts.forEach(blogPost => {
|
||||
blogPosts.forEach((blogPost) => {
|
||||
if (blogPost.metadata.source === aliasedPostSource) {
|
||||
blogPostPermalink = blogPost.metadata.permalink;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ export default function pluginContentBlog(
|
|||
|
||||
getPathsToWatch() {
|
||||
const {include = []} = options;
|
||||
const globPattern = include.map(pattern => `${contentPath}/${pattern}`);
|
||||
const globPattern = include.map((pattern) => `${contentPath}/${pattern}`);
|
||||
return [...globPattern];
|
||||
},
|
||||
|
||||
|
@ -151,13 +151,13 @@ export default function pluginContentBlog(
|
|||
},
|
||||
items: blogPosts
|
||||
.slice(page * postsPerPage, (page + 1) * postsPerPage)
|
||||
.map(item => item.id),
|
||||
.map((item) => item.id),
|
||||
});
|
||||
}
|
||||
|
||||
const blogTags: BlogTags = {};
|
||||
const tagsPath = normalizeUrl([basePageUrl, 'tags']);
|
||||
blogPosts.forEach(blogPost => {
|
||||
blogPosts.forEach((blogPost) => {
|
||||
const {tags} = blogPost.metadata;
|
||||
if (!tags || tags.length === 0) {
|
||||
// TODO: Extract tags out into a separate plugin.
|
||||
|
@ -167,7 +167,7 @@ export default function pluginContentBlog(
|
|||
}
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
blogPost.metadata.tags = tags.map(tag => {
|
||||
blogPost.metadata.tags = tags.map((tag) => {
|
||||
if (typeof tag === 'string') {
|
||||
const normalizedTag = kebabCase(tag);
|
||||
const permalink = normalizeUrl([tagsPath, normalizedTag]);
|
||||
|
@ -235,7 +235,7 @@ export default function pluginContentBlog(
|
|||
|
||||
// Create routes for blog entries.
|
||||
await Promise.all(
|
||||
blogPosts.map(async blogPost => {
|
||||
blogPosts.map(async (blogPost) => {
|
||||
const {id, metadata} = blogPost;
|
||||
await createData(
|
||||
// Note that this created data path must be in sync with
|
||||
|
@ -259,7 +259,7 @@ export default function pluginContentBlog(
|
|||
|
||||
// Create routes for blog's paginated list entries.
|
||||
await Promise.all(
|
||||
blogListPaginated.map(async listPage => {
|
||||
blogListPaginated.map(async (listPage) => {
|
||||
const {metadata, items} = listPage;
|
||||
const {permalink} = metadata;
|
||||
const pageMetadataPath = await createData(
|
||||
|
@ -272,7 +272,7 @@ export default function pluginContentBlog(
|
|||
component: blogListComponent,
|
||||
exact: true,
|
||||
modules: {
|
||||
items: items.map(postID => {
|
||||
items: items.map((postID) => {
|
||||
const metadata = blogItemsToMetadata[postID];
|
||||
// To tell routes.js this is an import and not a nested object to recurse.
|
||||
return {
|
||||
|
@ -299,7 +299,7 @@ export default function pluginContentBlog(
|
|||
const tagsModule: TagsModule = {};
|
||||
|
||||
await Promise.all(
|
||||
Object.keys(blogTags).map(async tag => {
|
||||
Object.keys(blogTags).map(async (tag) => {
|
||||
const {name, items, permalink} = blogTags[tag];
|
||||
|
||||
tagsModule[tag] = {
|
||||
|
@ -320,7 +320,7 @@ export default function pluginContentBlog(
|
|||
component: blogTagsPostsComponent,
|
||||
exact: true,
|
||||
modules: {
|
||||
items: items.map(postID => {
|
||||
items: items.map((postID) => {
|
||||
const metadata = blogItemsToMetadata[postID];
|
||||
return {
|
||||
content: {
|
||||
|
@ -422,14 +422,14 @@ export default function pluginContentBlog(
|
|||
const feedTypes = getFeedTypes(options.feedOptions?.type);
|
||||
|
||||
await Promise.all(
|
||||
feedTypes.map(feedType => {
|
||||
feedTypes.map((feedType) => {
|
||||
const feedPath = path.join(
|
||||
outDir,
|
||||
options.routeBasePath,
|
||||
`${feedType}.xml`,
|
||||
);
|
||||
const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1();
|
||||
return fs.writeFile(feedPath, feedContent, err => {
|
||||
return fs.writeFile(feedPath, feedContent, (err) => {
|
||||
if (err) {
|
||||
throw new Error(`Generating ${feedType} feed failed: ${err}`);
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ export default function pluginContentBlog(
|
|||
};
|
||||
const headTags: HtmlTags = [];
|
||||
|
||||
feedTypes.map(feedType => {
|
||||
feedTypes.map((feedType) => {
|
||||
const feedConfig = feedsConfig[feedType] || {};
|
||||
|
||||
if (!feedsConfig) {
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
/// <reference types="node" />
|
||||
|
||||
// @mdx-js/mdx currently doesn't have any @types
|
||||
declare module '@mdx-js/mdx' {
|
||||
export default function mdx(content: string, options: any): JSX.Element;
|
||||
}
|
|
@ -47,7 +47,7 @@ test('site with wrong sidebar file', async () => {
|
|||
});
|
||||
return plugin
|
||||
.loadContent()
|
||||
.catch(e =>
|
||||
.catch((e) =>
|
||||
expect(e).toMatchInlineSnapshot(
|
||||
`[Error: Improper sidebars file, document with id 'goku' not found.]`,
|
||||
),
|
||||
|
@ -110,7 +110,7 @@ describe('simple website', () => {
|
|||
|
||||
test('getPathToWatch', () => {
|
||||
const pathToWatch = plugin.getPathsToWatch();
|
||||
const matchPattern = pathToWatch.map(filepath =>
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
);
|
||||
expect(matchPattern).not.toEqual([]);
|
||||
|
@ -235,7 +235,7 @@ describe('versioned website', () => {
|
|||
|
||||
test('getPathToWatch', () => {
|
||||
const pathToWatch = plugin.getPathsToWatch();
|
||||
const matchPattern = pathToWatch.map(filepath =>
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
);
|
||||
expect(matchPattern).not.toEqual([]);
|
||||
|
|
|
@ -183,7 +183,7 @@ describe('simple site', () => {
|
|||
context,
|
||||
options,
|
||||
env,
|
||||
}).catch(e =>
|
||||
}).catch((e) =>
|
||||
expect(e).toMatchInlineSnapshot(
|
||||
`[Error: Document id cannot include "/".]`,
|
||||
),
|
||||
|
|
|
@ -81,7 +81,7 @@ export default function pluginContentDocs(
|
|||
docsDir: versionedDir,
|
||||
sidebarsDir: versionedSidebarsDir,
|
||||
} = versioning;
|
||||
const versionsNames = versions.map(version => `version-${version}`);
|
||||
const versionsNames = versions.map((version) => `version-${version}`);
|
||||
|
||||
return {
|
||||
name: 'docusaurus-plugin-content-docs',
|
||||
|
@ -91,7 +91,7 @@ export default function pluginContentDocs(
|
|||
.command('docs:version')
|
||||
.arguments('<version>')
|
||||
.description('Tag a new version for docs')
|
||||
.action(version => {
|
||||
.action((version) => {
|
||||
docsVersion(version, siteDir, {
|
||||
path: options.path,
|
||||
sidebarPath: options.sidebarPath,
|
||||
|
@ -101,17 +101,18 @@ export default function pluginContentDocs(
|
|||
|
||||
getPathsToWatch() {
|
||||
const {include} = options;
|
||||
let globPattern = include.map(pattern => `${docsDir}/${pattern}`);
|
||||
let globPattern = include.map((pattern) => `${docsDir}/${pattern}`);
|
||||
if (versioning.enabled) {
|
||||
const docsGlob = include
|
||||
.map(pattern =>
|
||||
.map((pattern) =>
|
||||
versionsNames.map(
|
||||
versionName => `${versionedDir}/${versionName}/${pattern}`,
|
||||
(versionName) => `${versionedDir}/${versionName}/${pattern}`,
|
||||
),
|
||||
)
|
||||
.reduce((a, b) => a.concat(b), []);
|
||||
const sidebarsGlob = versionsNames.map(
|
||||
versionName => `${versionedSidebarsDir}/${versionName}-sidebars.json`,
|
||||
(versionName) =>
|
||||
`${versionedSidebarsDir}/${versionName}-sidebars.json`,
|
||||
);
|
||||
globPattern = [...globPattern, ...sidebarsGlob, ...docsGlob];
|
||||
}
|
||||
|
@ -136,7 +137,7 @@ export default function pluginContentDocs(
|
|||
});
|
||||
docsPromises.push(
|
||||
Promise.all(
|
||||
docsFiles.map(async source => {
|
||||
docsFiles.map(async (source) => {
|
||||
const metadata: MetadataRaw = await processMetadata({
|
||||
source,
|
||||
refDir: docsDir,
|
||||
|
@ -152,8 +153,8 @@ export default function pluginContentDocs(
|
|||
// Metadata for versioned docs.
|
||||
if (versioning.enabled) {
|
||||
const versionedGlob = include
|
||||
.map(pattern =>
|
||||
versionsNames.map(versionName => `${versionName}/${pattern}`),
|
||||
.map((pattern) =>
|
||||
versionsNames.map((versionName) => `${versionName}/${pattern}`),
|
||||
)
|
||||
.reduce((a, b) => a.concat(b), []);
|
||||
const versionedFiles = await globby(versionedGlob, {
|
||||
|
@ -161,7 +162,7 @@ export default function pluginContentDocs(
|
|||
});
|
||||
docsPromises.push(
|
||||
Promise.all(
|
||||
versionedFiles.map(async source => {
|
||||
versionedFiles.map(async (source) => {
|
||||
const metadata = await processMetadata({
|
||||
source,
|
||||
refDir: versionedDir,
|
||||
|
@ -179,7 +180,8 @@ export default function pluginContentDocs(
|
|||
const sidebarPaths = [
|
||||
sidebarPath,
|
||||
...versionsNames.map(
|
||||
versionName => `${versionedSidebarsDir}/${versionName}-sidebars.json`,
|
||||
(versionName) =>
|
||||
`${versionedSidebarsDir}/${versionName}-sidebars.json`,
|
||||
),
|
||||
];
|
||||
const loadedSidebars: Sidebar = loadSidebars(sidebarPaths);
|
||||
|
@ -191,7 +193,7 @@ export default function pluginContentDocs(
|
|||
const docsMetadata: DocsMetadata = {};
|
||||
const permalinkToSidebar: PermalinkToSidebar = {};
|
||||
const versionToSidebars: VersionToSidebars = {};
|
||||
Object.keys(docsMetadataRaw).forEach(currentID => {
|
||||
Object.keys(docsMetadataRaw).forEach((currentID) => {
|
||||
const {next: nextID, previous: previousID, sidebar} =
|
||||
order[currentID] || {};
|
||||
const previous = previousID
|
||||
|
@ -291,7 +293,7 @@ export default function pluginContentDocs(
|
|||
metadataItems: Metadata[],
|
||||
): Promise<RouteConfig[]> => {
|
||||
const routes = await Promise.all(
|
||||
metadataItems.map(async metadataItem => {
|
||||
metadataItems.map(async (metadataItem) => {
|
||||
await createData(
|
||||
// Note that this created data path must be in sync with
|
||||
// metadataPath provided to mdx-loader.
|
||||
|
@ -345,7 +347,7 @@ export default function pluginContentDocs(
|
|||
'version',
|
||||
);
|
||||
await Promise.all(
|
||||
Object.keys(docsMetadataByVersion).map(async version => {
|
||||
Object.keys(docsMetadataByVersion).map(async (version) => {
|
||||
const routes: RouteConfig[] = await genRoutes(
|
||||
docsMetadataByVersion[version],
|
||||
);
|
||||
|
@ -364,8 +366,9 @@ export default function pluginContentDocs(
|
|||
content.docsSidebars,
|
||||
Array.from(neededSidebars),
|
||||
),
|
||||
permalinkToSidebar: pickBy(content.permalinkToSidebar, sidebar =>
|
||||
neededSidebars.has(sidebar),
|
||||
permalinkToSidebar: pickBy(
|
||||
content.permalinkToSidebar,
|
||||
(sidebar) => neededSidebars.has(sidebar),
|
||||
),
|
||||
version,
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@ const sourceToPermalink: SourceToPermalink = {
|
|||
'/docs/1.0.0/subdir/doc1',
|
||||
};
|
||||
|
||||
const transform = filepath => {
|
||||
const transform = (filepath) => {
|
||||
const content = fs.readFileSync(filepath, 'utf-8');
|
||||
const transformedContent = linkify(
|
||||
content,
|
||||
|
|
|
@ -36,7 +36,7 @@ export default function(
|
|||
// Replace internal markdown linking (except in fenced blocks).
|
||||
if (sourceDir) {
|
||||
let fencedBlock = false;
|
||||
const lines = content.split('\n').map(line => {
|
||||
const lines = content.split('\n').map((line) => {
|
||||
if (line.trim().startsWith('```')) {
|
||||
fencedBlock = !fencedBlock;
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ import {Sidebar, SidebarItem, Order} from './types';
|
|||
export default function createOrder(allSidebars: Sidebar = {}): Order {
|
||||
const order: Order = {};
|
||||
|
||||
Object.keys(allSidebars).forEach(sidebarId => {
|
||||
Object.keys(allSidebars).forEach((sidebarId) => {
|
||||
const sidebar = allSidebars[sidebarId];
|
||||
|
||||
const ids: string[] = [];
|
||||
const indexItems = ({items}: {items: SidebarItem[]}) => {
|
||||
items.forEach(item => {
|
||||
items.forEach((item) => {
|
||||
switch (item.type) {
|
||||
case 'category':
|
||||
indexItems({
|
||||
|
|
|
@ -43,7 +43,7 @@ function normalizeCategoryShorthand(
|
|||
*/
|
||||
function assertItem(item: Object, keys: string[]): void {
|
||||
const unknownKeys = Object.keys(item).filter(
|
||||
key => !keys.includes(key) && key !== 'type',
|
||||
(key) => !keys.includes(key) && key !== 'type',
|
||||
);
|
||||
|
||||
if (unknownKeys.length) {
|
||||
|
@ -150,7 +150,7 @@ export default function loadSidebars(sidebarPaths?: string[]): Sidebar {
|
|||
return {} as Sidebar;
|
||||
}
|
||||
|
||||
sidebarPaths.map(sidebarPath => {
|
||||
sidebarPaths.map((sidebarPath) => {
|
||||
if (sidebarPath && fs.existsSync(sidebarPath)) {
|
||||
const sidebar = importFresh(sidebarPath) as SidebarRaw;
|
||||
Object.assign(allSidebars, sidebar);
|
||||
|
|
|
@ -31,7 +31,7 @@ export default function pluginContentPages(
|
|||
|
||||
getPathsToWatch() {
|
||||
const {include = []} = options;
|
||||
const globPattern = include.map(pattern => `${contentPath}/${pattern}`);
|
||||
const globPattern = include.map((pattern) => `${contentPath}/${pattern}`);
|
||||
return [...globPattern];
|
||||
},
|
||||
|
||||
|
@ -49,7 +49,7 @@ export default function pluginContentPages(
|
|||
cwd: pagesDir,
|
||||
});
|
||||
|
||||
return pagesFiles.map(relativeSource => {
|
||||
return pagesFiles.map((relativeSource) => {
|
||||
const source = path.join(pagesDir, relativeSource);
|
||||
const aliasedSource = aliasedSitePath(source, siteDir);
|
||||
const pathName = encodePath(fileToPath(relativeSource));
|
||||
|
@ -69,7 +69,7 @@ export default function pluginContentPages(
|
|||
const {addRoute} = actions;
|
||||
|
||||
await Promise.all(
|
||||
content.map(async metadataItem => {
|
||||
content.map(async (metadataItem) => {
|
||||
const {permalink, source} = metadataItem;
|
||||
addRoute({
|
||||
path: permalink,
|
||||
|
|
|
@ -18,7 +18,7 @@ function Image(props) {
|
|||
width={img.src.width || 100}
|
||||
placeholder={{lqip: img.preSrc}}
|
||||
src={img.src.src}
|
||||
srcSet={img.src.images.map(image => ({
|
||||
srcSet={img.src.images.map((image) => ({
|
||||
...image,
|
||||
src: image.path,
|
||||
}))}
|
||||
|
|
|
@ -20,7 +20,7 @@ export default function createSitemap(
|
|||
}
|
||||
|
||||
const urls = routesPaths.map(
|
||||
routesPath =>
|
||||
(routesPath) =>
|
||||
({
|
||||
url: routesPath,
|
||||
changefreq: options.changefreq,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
const admonitions = require('remark-admonitions');
|
||||
|
||||
const addAdmonitions = pluginOptions => {
|
||||
const addAdmonitions = (pluginOptions) => {
|
||||
if (pluginOptions == null) {
|
||||
return {
|
||||
remarkPlugins: [admonitions],
|
||||
|
|
|
@ -61,7 +61,7 @@ module.exports = function(context, options) {
|
|||
|
||||
configureWebpack() {
|
||||
const prismLanguages = additionalLanguages
|
||||
.map(lang => `prism-${lang}`)
|
||||
.map((lang) => `prism-${lang}`)
|
||||
.join('|');
|
||||
|
||||
return {
|
||||
|
|
|
@ -17,7 +17,7 @@ import siteConfig from '@generated/docusaurus.config';
|
|||
|
||||
window.Prism = Prism;
|
||||
|
||||
additionalLanguages.forEach(lang => {
|
||||
additionalLanguages.forEach((lang) => {
|
||||
require(`prismjs/components/prism-${lang}`); // eslint-disable-line
|
||||
});
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ function BlogTagsListPage(props) {
|
|||
const {tags} = props;
|
||||
|
||||
const tagCategories = {};
|
||||
Object.keys(tags).forEach(tag => {
|
||||
Object.keys(tags).forEach((tag) => {
|
||||
const category = getCategoryOfTag(tag);
|
||||
tagCategories[category] = tagCategories[category] || [];
|
||||
tagCategories[category].push(tag);
|
||||
|
@ -34,7 +34,7 @@ function BlogTagsListPage(props) {
|
|||
.map(([category, tagsForCategory]) => (
|
||||
<div key={category}>
|
||||
<h3>{category}</h3>
|
||||
{tagsForCategory.map(tag => (
|
||||
{tagsForCategory.map((tag) => (
|
||||
<Link
|
||||
className="padding-right--md"
|
||||
href={tags[tag].permalink}
|
||||
|
@ -45,7 +45,7 @@ function BlogTagsListPage(props) {
|
|||
<hr />
|
||||
</div>
|
||||
))
|
||||
.filter(item => item != null);
|
||||
.filter((item) => item != null);
|
||||
|
||||
return (
|
||||
<Layout title="Tags" description="Blog Tags">
|
||||
|
|
|
@ -54,7 +54,7 @@ const getHighlightDirectiveRegex = (
|
|||
// to be more reliable, the opening and closing comment must match
|
||||
const commentPattern = languages
|
||||
.map(
|
||||
lang =>
|
||||
(lang) =>
|
||||
`(?:${comments[lang].start}\\s*(${directives})\\s*${comments[lang].end})`,
|
||||
)
|
||||
.join('|');
|
||||
|
@ -62,7 +62,7 @@ const getHighlightDirectiveRegex = (
|
|||
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
||||
};
|
||||
// select comment styles based on language
|
||||
const highlightDirectiveRegex = lang => {
|
||||
const highlightDirectiveRegex = (lang) => {
|
||||
switch (lang) {
|
||||
case 'js':
|
||||
case 'javascript':
|
||||
|
@ -120,7 +120,9 @@ export default ({children, className: languageClassName, metastring}) => {
|
|||
|
||||
if (metastring && highlightLinesRangeRegex.test(metastring)) {
|
||||
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
|
||||
highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0);
|
||||
highlightLines = rangeParser
|
||||
.parse(highlightLinesRange)
|
||||
.filter((n) => n > 0);
|
||||
}
|
||||
|
||||
if (metastring && codeBlockTitleRegex.test(metastring)) {
|
||||
|
|
|
@ -39,7 +39,7 @@ function Headings({headings, isChild}) {
|
|||
}
|
||||
return (
|
||||
<ul className={isChild ? '' : 'contents contents__left-border'}>
|
||||
{headings.map(heading => (
|
||||
{headings.map((heading) => (
|
||||
<li key={heading.id}>
|
||||
<a
|
||||
href={`#${heading.id}`}
|
||||
|
|
|
@ -22,7 +22,7 @@ function DocPage(props) {
|
|||
const {route: baseRoute, docsMetadata, location} = props;
|
||||
// case-sensitive route such as it is defined in the sidebar
|
||||
const currentRoute =
|
||||
baseRoute.routes.find(route => {
|
||||
baseRoute.routes.find((route) => {
|
||||
return matchPath(location.pathname, route);
|
||||
}) || {};
|
||||
const {permalinkToSidebar, docsSidebars, version} = docsMetadata;
|
||||
|
|
|
@ -30,9 +30,9 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
|
|||
setCollapsed(item.collapsed);
|
||||
}
|
||||
|
||||
const handleItemClick = useCallback(e => {
|
||||
const handleItemClick = useCallback((e) => {
|
||||
e.preventDefault();
|
||||
setCollapsed(state => !state);
|
||||
setCollapsed((state) => !state);
|
||||
});
|
||||
|
||||
switch (type) {
|
||||
|
@ -54,7 +54,7 @@ function DocSidebarItem({item, onItemClick, collapsible}) {
|
|||
{label}
|
||||
</a>
|
||||
<ul className="menu__list">
|
||||
{items.map(childItem => (
|
||||
{items.map((childItem) => (
|
||||
<DocSidebarItem
|
||||
key={childItem.label}
|
||||
item={childItem}
|
||||
|
@ -99,8 +99,8 @@ function mutateSidebarCollapsingState(item, path) {
|
|||
case 'category': {
|
||||
const anyChildItemsActive =
|
||||
items
|
||||
.map(childItem => mutateSidebarCollapsingState(childItem, path))
|
||||
.filter(val => val).length > 0;
|
||||
.map((childItem) => mutateSidebarCollapsingState(childItem, path))
|
||||
.filter((val) => val).length > 0;
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
item.collapsed = !anyChildItemsActive;
|
||||
return anyChildItemsActive;
|
||||
|
@ -144,7 +144,7 @@ function DocSidebar(props) {
|
|||
}
|
||||
|
||||
if (sidebarCollapsible) {
|
||||
sidebarData.forEach(sidebarItem =>
|
||||
sidebarData.forEach((sidebarItem) =>
|
||||
mutateSidebarCollapsingState(sidebarItem, path),
|
||||
);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ function DocSidebar(props) {
|
|||
)}
|
||||
</button>
|
||||
<ul className="menu__list">
|
||||
{sidebarData.map(item => (
|
||||
{sidebarData.map((item) => (
|
||||
<DocSidebarItem
|
||||
key={item.label}
|
||||
item={item}
|
||||
|
|
|
@ -14,7 +14,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|||
import './styles.css';
|
||||
import styles from './styles.module.css';
|
||||
|
||||
const Heading = Tag =>
|
||||
const Heading = (Tag) =>
|
||||
function TargetComponent({id, ...props}) {
|
||||
const {
|
||||
siteConfig: {
|
||||
|
|
|
@ -13,21 +13,21 @@ import Heading from '@theme/Heading';
|
|||
import styles from './styles.module.css';
|
||||
|
||||
export default {
|
||||
code: props => {
|
||||
code: (props) => {
|
||||
const {children} = props;
|
||||
if (typeof children === 'string') {
|
||||
return <CodeBlock {...props} />;
|
||||
}
|
||||
return children;
|
||||
},
|
||||
a: props => {
|
||||
a: (props) => {
|
||||
if (/\.[^./]+$/.test(props.href)) {
|
||||
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
||||
return <a {...props} />;
|
||||
}
|
||||
return <Link {...props} />;
|
||||
},
|
||||
pre: props => <div className={styles.mdxCodeBlock} {...props} />,
|
||||
pre: (props) => <div className={styles.mdxCodeBlock} {...props} />,
|
||||
h1: Heading('h1'),
|
||||
h2: Heading('h2'),
|
||||
h3: Heading('h3'),
|
||||
|
|
|
@ -125,7 +125,7 @@ function Navbar() {
|
|||
}, [setSidebarShown]);
|
||||
|
||||
const onToggleChange = useCallback(
|
||||
e => (e.target.checked ? setDarkTheme() : setLightTheme()),
|
||||
(e) => (e.target.checked ? setDarkTheme() : setLightTheme()),
|
||||
[setLightTheme, setDarkTheme],
|
||||
);
|
||||
|
||||
|
@ -182,14 +182,14 @@ function Navbar() {
|
|||
)}
|
||||
</Link>
|
||||
{links
|
||||
.filter(linkItem => linkItem.position === 'left')
|
||||
.filter((linkItem) => linkItem.position === 'left')
|
||||
.map((linkItem, i) => (
|
||||
<NavItem {...linkItem} key={i} />
|
||||
))}
|
||||
</div>
|
||||
<div className="navbar__items navbar__items--right">
|
||||
{links
|
||||
.filter(linkItem => linkItem.position === 'right')
|
||||
.filter((linkItem) => linkItem.position === 'right')
|
||||
.map((linkItem, i) => (
|
||||
<NavItem {...linkItem} key={i} />
|
||||
))}
|
||||
|
|
|
@ -32,7 +32,7 @@ function Tabs(props) {
|
|||
}
|
||||
}
|
||||
|
||||
const changeSelectedValue = newValue => {
|
||||
const changeSelectedValue = (newValue) => {
|
||||
setSelectedValue(newValue);
|
||||
if (groupId != null) {
|
||||
setTabGroupChoices(groupId, newValue);
|
||||
|
@ -91,8 +91,8 @@ function Tabs(props) {
|
|||
'tab-item--active': selectedValue === value,
|
||||
})}
|
||||
key={value}
|
||||
ref={tabControl => tabRefs.push(tabControl)}
|
||||
onKeyDown={event => handleKeydown(tabRefs, event.target, event)}
|
||||
ref={(tabControl) => tabRefs.push(tabControl)}
|
||||
onKeyDown={(event) => handleKeydown(tabRefs, event.target, event)}
|
||||
onFocus={() => changeSelectedValue(value)}
|
||||
onClick={() => changeSelectedValue(value)}>
|
||||
{label}
|
||||
|
@ -102,7 +102,7 @@ function Tabs(props) {
|
|||
<div role="tabpanel" className="margin-vert--md">
|
||||
{
|
||||
Children.toArray(children).filter(
|
||||
child => child.props.value === selectedValue,
|
||||
(child) => child.props.value === selectedValue,
|
||||
)[0]
|
||||
}
|
||||
</div>
|
||||
|
|
|
@ -9,12 +9,12 @@ import {useState, useCallback, useEffect} from 'react';
|
|||
import {useLocation} from '@docusaurus/router';
|
||||
import useLocationHash from '@theme/hooks/useLocationHash';
|
||||
|
||||
const useHideableNavbar = hideOnScroll => {
|
||||
const useHideableNavbar = (hideOnScroll) => {
|
||||
const [isNavbarVisible, setIsNavbarVisible] = useState(true);
|
||||
const [isFocusedAnchor, setIsFocusedAnchor] = useState(false);
|
||||
const [lastScrollTop, setLastScrollTop] = useState(0);
|
||||
const [navbarHeight, setNavbarHeight] = useState(0);
|
||||
const navbarRef = useCallback(node => {
|
||||
const navbarRef = useCallback((node) => {
|
||||
if (node !== null) {
|
||||
setNavbarHeight(node.getBoundingClientRect().height);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ const useTabGroupChoice = () => {
|
|||
return {
|
||||
tabGroupChoices,
|
||||
setTabGroupChoices: (groupId, newChoice) => {
|
||||
setChoices(oldChoices => ({...oldChoices, [groupId]: newChoice}));
|
||||
setChoices((oldChoices) => ({...oldChoices, [groupId]: newChoice}));
|
||||
setChoiceSyncWithLocalStorage(groupId, newChoice);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@ const useTheme = () => {
|
|||
: themes.light,
|
||||
);
|
||||
const setThemeSyncWithLocalStorage = useCallback(
|
||||
newTheme => {
|
||||
(newTheme) => {
|
||||
try {
|
||||
localStorage.setItem('theme', newTheme);
|
||||
} catch (err) {
|
||||
|
|
|
@ -55,7 +55,7 @@ const getHighlightDirectiveRegex = (
|
|||
// to be more reliable, the opening and closing comment must match
|
||||
const commentPattern = languages
|
||||
.map(
|
||||
lang =>
|
||||
(lang) =>
|
||||
`(?:${comments[lang].start}\\s*(${directives})\\s*${comments[lang].end})`,
|
||||
)
|
||||
.join('|');
|
||||
|
@ -63,7 +63,7 @@ const getHighlightDirectiveRegex = (
|
|||
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
||||
};
|
||||
// select comment styles based on language
|
||||
const highlightDirectiveRegex = lang => {
|
||||
const highlightDirectiveRegex = (lang) => {
|
||||
switch (lang) {
|
||||
case 'js':
|
||||
case 'javascript':
|
||||
|
@ -127,7 +127,9 @@ export default ({
|
|||
|
||||
if (metastring && highlightLinesRangeRegex.test(metastring)) {
|
||||
const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
|
||||
highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0);
|
||||
highlightLines = rangeParser
|
||||
.parse(highlightLinesRange)
|
||||
.filter((n) => n > 0);
|
||||
}
|
||||
|
||||
if (metastring && codeBlockTitleRegex.test(metastring)) {
|
||||
|
|
|
@ -15,7 +15,7 @@ function Playground({children, theme, transformCode, ...props}) {
|
|||
return (
|
||||
<LiveProvider
|
||||
code={children}
|
||||
transformCode={transformCode || (code => `${code};`)}
|
||||
transformCode={transformCode || ((code) => `${code};`)}
|
||||
theme={theme}
|
||||
{...props}>
|
||||
<div
|
||||
|
|
|
@ -13,7 +13,7 @@ import {useHistory} from '@docusaurus/router';
|
|||
|
||||
import './styles.css';
|
||||
|
||||
const Search = props => {
|
||||
const Search = (props) => {
|
||||
const [algoliaLoaded, setAlgoliaLoaded] = useState(false);
|
||||
const searchBarRef = useRef(null);
|
||||
const {siteConfig = {}} = useDocusaurusContext();
|
||||
|
@ -81,7 +81,7 @@ const Search = props => {
|
|||
props.handleSearchBarToggle(!props.isSearchBarExpanded);
|
||||
}, [props.isSearchBarExpanded]);
|
||||
|
||||
const handleSearchInput = useCallback(e => {
|
||||
const handleSearchInput = useCallback((e) => {
|
||||
const needFocus = e.type !== 'mouseover';
|
||||
|
||||
loadAlgolia(needFocus);
|
||||
|
|
|
@ -27,7 +27,7 @@ describe('load utils', () => {
|
|||
'@site/versioned_docs/foo/bar.md',
|
||||
'user/docs/test.md': '@site/../docs/test.md',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(aliasedSitePath(file, 'user/website')).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
@ -42,7 +42,7 @@ describe('load utils', () => {
|
|||
'foo\\bar/lol': 'foo/bar/lol',
|
||||
'website\\docs/**/*.{md,mdx}': 'website/docs/**/*.{md,mdx}',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(posixPath(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
@ -59,7 +59,7 @@ describe('load utils', () => {
|
|||
'/blog/201712/14-introducing-docusaurus':
|
||||
'Blog20171214IntroducingDocusaurusA93',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(genComponentName(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
@ -75,7 +75,7 @@ describe('load utils', () => {
|
|||
'/yangshun/tay': 'yangshun-tay-48d',
|
||||
'/yangshun-tay': 'yangshun-tay-f3b',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(docuHash(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
@ -91,7 +91,7 @@ describe('load utils', () => {
|
|||
'foo.js': '/foo',
|
||||
'foo/bar.js': '/foo/bar',
|
||||
};
|
||||
Object.keys(asserts).forEach(file => {
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(fileToPath(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
|
@ -142,7 +142,7 @@ describe('load utils', () => {
|
|||
'/users/en/': 'users-en-f7a',
|
||||
'/blog': 'blog-c06',
|
||||
};
|
||||
Object.keys(firstAssert).forEach(str => {
|
||||
Object.keys(firstAssert).forEach((str) => {
|
||||
expect(genChunkName(str)).toBe(firstAssert[str]);
|
||||
});
|
||||
|
||||
|
@ -156,7 +156,7 @@ describe('load utils', () => {
|
|||
'/blog/1': 'blog-85-f-089',
|
||||
'/blog/2': 'blog-353-489',
|
||||
};
|
||||
Object.keys(secondAssert).forEach(str => {
|
||||
Object.keys(secondAssert).forEach((str) => {
|
||||
expect(genChunkName(str, undefined, 'blog')).toBe(secondAssert[str]);
|
||||
});
|
||||
|
||||
|
@ -167,7 +167,7 @@ describe('load utils', () => {
|
|||
c: '4a8a08f0',
|
||||
d: '8277e091',
|
||||
};
|
||||
Object.keys(thirdAssert).forEach(str => {
|
||||
Object.keys(thirdAssert).forEach((str) => {
|
||||
expect(genChunkName(str, undefined, undefined, true)).toBe(
|
||||
thirdAssert[str],
|
||||
);
|
||||
|
@ -210,10 +210,9 @@ describe('load utils', () => {
|
|||
versions: [],
|
||||
});
|
||||
expect(idx(obj, ['translation', 'enabled'])).toEqual(true);
|
||||
expect(idx(obj, ['translation', variable]).map(lang => lang.tag)).toEqual([
|
||||
'en',
|
||||
'ja',
|
||||
]);
|
||||
expect(
|
||||
idx(obj, ['translation', variable]).map((lang) => lang.tag),
|
||||
).toEqual(['en', 'ja']);
|
||||
expect(idx(test, ['arr', 0])).toEqual(1);
|
||||
expect(idx(undefined)).toBeUndefined();
|
||||
expect(idx(null)).toBeNull();
|
||||
|
@ -283,7 +282,7 @@ describe('load utils', () => {
|
|||
output: 'http://foobar.com/test/',
|
||||
},
|
||||
];
|
||||
asserts.forEach(testCase => {
|
||||
asserts.forEach((testCase) => {
|
||||
expect(normalizeUrl(testCase.input)).toBe(testCase.output);
|
||||
});
|
||||
|
||||
|
|
|
@ -35,15 +35,11 @@ export async function generate(
|
|||
// This is to avoid unnecessary overwriting and we can reuse old file.
|
||||
if (!lastHash && fs.existsSync(filepath)) {
|
||||
const lastContent = await fs.readFile(filepath, 'utf8');
|
||||
lastHash = createHash('md5')
|
||||
.update(lastContent)
|
||||
.digest('hex');
|
||||
lastHash = createHash('md5').update(lastContent).digest('hex');
|
||||
fileHash.set(filepath, lastHash);
|
||||
}
|
||||
|
||||
const currentHash = createHash('md5')
|
||||
.update(content)
|
||||
.digest('hex');
|
||||
const currentHash = createHash('md5').update(content).digest('hex');
|
||||
|
||||
if (lastHash !== currentHash) {
|
||||
await fs.ensureDir(path.dirname(filepath));
|
||||
|
@ -79,7 +75,7 @@ export function fileToPath(file: string): string {
|
|||
export function encodePath(userpath: string): string {
|
||||
return userpath
|
||||
.split('/')
|
||||
.map(item => encodeURIComponent(item))
|
||||
.map((item) => encodeURIComponent(item))
|
||||
.join('/');
|
||||
}
|
||||
|
||||
|
@ -91,10 +87,7 @@ export function docuHash(str: string): string {
|
|||
if (str === '/') {
|
||||
return 'index';
|
||||
}
|
||||
const shortHash = createHash('md5')
|
||||
.update(str)
|
||||
.digest('hex')
|
||||
.substr(0, 3);
|
||||
const shortHash = createHash('md5').update(str).digest('hex').substr(0, 3);
|
||||
return `${kebabCase(str)}-${shortHash}`;
|
||||
}
|
||||
|
||||
|
@ -200,10 +193,7 @@ export function parse(
|
|||
} {
|
||||
const options: {} = {
|
||||
excerpt: (file: matter.GrayMatterFile<string>): void => {
|
||||
file.excerpt = file.content
|
||||
.trim()
|
||||
.split('\n', 1)
|
||||
.shift();
|
||||
file.excerpt = file.content.trim().split('\n', 1).shift();
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ if (!semver.satisfies(process.version, requiredVersion)) {
|
|||
|
||||
function wrapCommand(fn) {
|
||||
return (...args) =>
|
||||
fn(...args).catch(err => {
|
||||
fn(...args).catch((err) => {
|
||||
console.error(chalk.red(err.stack));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
@ -94,7 +94,7 @@ cli
|
|||
});
|
||||
});
|
||||
|
||||
cli.arguments('<command>').action(cmd => {
|
||||
cli.arguments('<command>').action((cmd) => {
|
||||
cli.outputHelp();
|
||||
console.log(` ${chalk.red(`\n Unknown command ${chalk.yellow(cmd)}.`)}`);
|
||||
console.log();
|
||||
|
|
|
@ -72,7 +72,7 @@ class PendingNavigation extends React.Component {
|
|||
}
|
||||
}
|
||||
})
|
||||
.catch(e => console.warn(e));
|
||||
.catch((e) => console.warn(e));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ describe('flat', () => {
|
|||
null: null,
|
||||
undefined,
|
||||
};
|
||||
Object.keys(primitives).forEach(key => {
|
||||
Object.keys(primitives).forEach((key) => {
|
||||
const value = primitives[key];
|
||||
expect(
|
||||
flat({
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import clientModules from '@generated/client-modules';
|
||||
|
||||
function dispatchLifecycleAction(lifecycleAction, ...args) {
|
||||
clientModules.forEach(clientModule => {
|
||||
clientModules.forEach((clientModule) => {
|
||||
const mod = clientModule.__esModule ? clientModule.default : clientModule;
|
||||
if (mod && mod[lifecycleAction]) {
|
||||
mod[lifecycleAction](...args);
|
||||
|
|
|
@ -27,13 +27,13 @@ const isSlowConnection = () => {
|
|||
return false;
|
||||
};
|
||||
|
||||
const canPrefetch = routePath =>
|
||||
const canPrefetch = (routePath) =>
|
||||
!isSlowConnection() && !loaded[routePath] && !fetched[routePath];
|
||||
|
||||
const canPreload = routePath => !isSlowConnection() && !loaded[routePath];
|
||||
const canPreload = (routePath) => !isSlowConnection() && !loaded[routePath];
|
||||
|
||||
const docusaurus = {
|
||||
prefetch: routePath => {
|
||||
prefetch: (routePath) => {
|
||||
if (!canPrefetch(routePath)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ const docusaurus = {
|
|||
}, []);
|
||||
|
||||
// Prefetch all webpack chunk assets file needed.
|
||||
chunkNamesNeeded.forEach(chunkName => {
|
||||
chunkNamesNeeded.forEach((chunkName) => {
|
||||
// "__webpack_require__.gca" is a custom function provided by ChunkAssetPlugin.
|
||||
// Pass it the chunkName or chunkId you want to load and it will return the URL for that chunk.
|
||||
// eslint-disable-next-line no-undef
|
||||
|
@ -69,7 +69,7 @@ const docusaurus = {
|
|||
return true;
|
||||
},
|
||||
|
||||
preload: routePath => {
|
||||
preload: (routePath) => {
|
||||
if (!canPreload(routePath)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ function ComponentCreator(path) {
|
|||
- optsWebpack: [require.resolveWeak('./Pages.js'), require.resolveWeak('./doc1.md')]
|
||||
*/
|
||||
const flatChunkNames = flat(chunkNames);
|
||||
Object.keys(flatChunkNames).forEach(key => {
|
||||
Object.keys(flatChunkNames).forEach((key) => {
|
||||
const chunkRegistry = registry[flatChunkNames[key]];
|
||||
if (chunkRegistry) {
|
||||
/* eslint-disable prefer-destructuring */
|
||||
|
@ -57,7 +57,7 @@ function ComponentCreator(path) {
|
|||
render: (loaded, props) => {
|
||||
// Clone the original object since we don't want to alter the original.
|
||||
const loadedModules = JSON.parse(JSON.stringify(chunkNames));
|
||||
Object.keys(loaded).forEach(key => {
|
||||
Object.keys(loaded).forEach((key) => {
|
||||
let val = loadedModules;
|
||||
const keyPath = key.split('.');
|
||||
for (let i = 0; i < keyPath.length - 1; i += 1) {
|
||||
|
@ -65,10 +65,10 @@ function ComponentCreator(path) {
|
|||
}
|
||||
val[keyPath[keyPath.length - 1]] = loaded[key].default;
|
||||
const nonDefaultKeys = Object.keys(loaded[key]).filter(
|
||||
k => k !== 'default',
|
||||
(k) => k !== 'default',
|
||||
);
|
||||
if (nonDefaultKeys && nonDefaultKeys.length) {
|
||||
nonDefaultKeys.forEach(nonDefaultKey => {
|
||||
nonDefaultKeys.forEach((nonDefaultKey) => {
|
||||
val[keyPath[keyPath.length - 1]][nonDefaultKey] =
|
||||
loaded[key][nonDefaultKey];
|
||||
});
|
||||
|
|
|
@ -20,8 +20,8 @@ function Link(props) {
|
|||
|
||||
let io;
|
||||
const handleIntersection = (el, cb) => {
|
||||
io = new window.IntersectionObserver(entries => {
|
||||
entries.forEach(entry => {
|
||||
io = new window.IntersectionObserver((entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (el === entry.target) {
|
||||
// If element is in viewport, stop listening/observing and run callback.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
|
||||
|
@ -38,7 +38,7 @@ function Link(props) {
|
|||
io.observe(el);
|
||||
};
|
||||
|
||||
const handleRef = ref => {
|
||||
const handleRef = (ref) => {
|
||||
if (IOSupported && ref && isInternal) {
|
||||
// If IO supported and element reference found, setup Observer functionality.
|
||||
handleIntersection(ref, () => {
|
||||
|
|
|
@ -10,7 +10,7 @@ function flat(target) {
|
|||
const output = {};
|
||||
|
||||
function step(object, prev) {
|
||||
Object.keys(object).forEach(key => {
|
||||
Object.keys(object).forEach((key) => {
|
||||
const value = object[key];
|
||||
const type = typeof value;
|
||||
const isObject = type === 'object' && !!value;
|
||||
|
|
|
@ -68,7 +68,7 @@ const supportedPrefetchStrategy = support('prefetch')
|
|||
const preFetched = {};
|
||||
|
||||
function prefetch(url) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
if (preFetched[url]) {
|
||||
resolve();
|
||||
return;
|
||||
|
|
|
@ -19,7 +19,7 @@ export default function preload(routes, pathname) {
|
|||
const matches = matchRoutes(routes, pathname);
|
||||
|
||||
return Promise.all(
|
||||
matches.map(match => {
|
||||
matches.map((match) => {
|
||||
const {component} = match.route;
|
||||
|
||||
if (component && component.preload) {
|
||||
|
|
|
@ -30,7 +30,7 @@ export default async function render(locals) {
|
|||
const modules = new Set();
|
||||
const context = {};
|
||||
const appHtml = ReactDOMServer.renderToString(
|
||||
<Loadable.Capture report={moduleName => modules.add(moduleName)}>
|
||||
<Loadable.Capture report={(moduleName) => modules.add(moduleName)}>
|
||||
<StaticRouter location={location} context={context}>
|
||||
<App />
|
||||
</StaticRouter>
|
||||
|
@ -55,8 +55,8 @@ export default async function render(locals) {
|
|||
// manifest information.
|
||||
const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
|
||||
const bundles = getBundles(manifest, modulesToBeLoaded);
|
||||
const stylesheets = (bundles.css || []).map(b => b.file);
|
||||
const scripts = (bundles.js || []).map(b => b.file);
|
||||
const stylesheets = (bundles.css || []).map((b) => b.file);
|
||||
const scripts = (bundles.js || []).map((b) => b.file);
|
||||
const {baseUrl} = locals;
|
||||
|
||||
const renderedHtml = ejs.render(
|
||||
|
|
|
@ -29,13 +29,13 @@ function compile(config: Configuration[]): Promise<any> {
|
|||
reject(err);
|
||||
}
|
||||
if (stats.hasErrors()) {
|
||||
stats.toJson('errors-only').errors.forEach(e => {
|
||||
stats.toJson('errors-only').errors.forEach((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
reject(new Error('Failed to compile with errors.'));
|
||||
}
|
||||
if (stats.hasWarnings()) {
|
||||
stats.toJson('errors-warnings').warnings.forEach(warning => {
|
||||
stats.toJson('errors-warnings').warnings.forEach((warning) => {
|
||||
console.warn(warning);
|
||||
});
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ export async function build(
|
|||
}
|
||||
|
||||
// Plugin Lifecycle - configureWebpack.
|
||||
plugins.forEach(plugin => {
|
||||
plugins.forEach((plugin) => {
|
||||
const {configureWebpack} = plugin;
|
||||
if (!configureWebpack) {
|
||||
return;
|
||||
|
@ -130,14 +130,14 @@ export async function build(
|
|||
typeof serverConfig.output.filename === 'string'
|
||||
) {
|
||||
const serverBundle = path.join(outDir, serverConfig.output.filename);
|
||||
fs.pathExists(serverBundle).then(exist => {
|
||||
fs.pathExists(serverBundle).then((exist) => {
|
||||
exist && fs.unlink(serverBundle);
|
||||
});
|
||||
}
|
||||
|
||||
// Plugin Lifecycle - postBuild.
|
||||
await Promise.all(
|
||||
plugins.map(async plugin => {
|
||||
plugins.map(async (plugin) => {
|
||||
if (!plugin.postBuild) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ export async function deploy(
|
|||
|
||||
// Build static html files, then push to deploymentBranch branch of specified repo.
|
||||
build(siteDir, cliOptions, false)
|
||||
.then(outDir => {
|
||||
.then((outDir) => {
|
||||
shell.cd(tempDir);
|
||||
|
||||
if (
|
||||
|
@ -146,7 +146,7 @@ export async function deploy(
|
|||
`${projectName}-${deploymentBranch}`,
|
||||
);
|
||||
|
||||
fs.copy(fromPath, toPath, error => {
|
||||
fs.copy(fromPath, toPath, (error) => {
|
||||
if (error) {
|
||||
throw new Error(
|
||||
`Error: Copying build assets failed with error '${error}'`,
|
||||
|
@ -177,7 +177,7 @@ export async function deploy(
|
|||
}
|
||||
});
|
||||
})
|
||||
.catch(buildError => {
|
||||
.catch((buildError) => {
|
||||
console.error(buildError);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ export function externalCommand(cli: CommanderStatic, siteDir: string): void {
|
|||
const plugins = initPlugins({pluginConfigs, context});
|
||||
|
||||
// Plugin Lifecycle - extendCli.
|
||||
plugins.forEach(plugin => {
|
||||
plugins.forEach((plugin) => {
|
||||
const {extendCli} = plugin;
|
||||
|
||||
if (!extendCli) {
|
||||
|
|
|
@ -50,13 +50,13 @@ export async function start(
|
|||
|
||||
// Reload files processing.
|
||||
const reload = () => {
|
||||
load(siteDir).catch(err => {
|
||||
load(siteDir).catch((err) => {
|
||||
console.error(chalk.red(err.stack));
|
||||
});
|
||||
};
|
||||
const {siteConfig, plugins = []} = props;
|
||||
|
||||
const normalizeToSiteDir = filepath => {
|
||||
const normalizeToSiteDir = (filepath) => {
|
||||
if (filepath && path.isAbsolute(filepath)) {
|
||||
return posixPath(path.relative(siteDir, filepath));
|
||||
}
|
||||
|
@ -66,7 +66,9 @@ export async function start(
|
|||
const pluginPaths: string[] = ([] as string[])
|
||||
.concat(
|
||||
...plugins
|
||||
.map<any>(plugin => plugin.getPathsToWatch && plugin.getPathsToWatch())
|
||||
.map<any>(
|
||||
(plugin) => plugin.getPathsToWatch && plugin.getPathsToWatch(),
|
||||
)
|
||||
.filter(Boolean),
|
||||
)
|
||||
.map(normalizeToSiteDir);
|
||||
|
@ -74,7 +76,7 @@ export async function start(
|
|||
cwd: siteDir,
|
||||
ignoreInitial: true,
|
||||
});
|
||||
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach(event =>
|
||||
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) =>
|
||||
fsWatcher.on(event, reload),
|
||||
);
|
||||
|
||||
|
@ -107,7 +109,7 @@ export async function start(
|
|||
});
|
||||
|
||||
// Plugin Lifecycle - configureWebpack.
|
||||
plugins.forEach(plugin => {
|
||||
plugins.forEach((plugin) => {
|
||||
const {configureWebpack} = plugin;
|
||||
if (!configureWebpack) {
|
||||
return;
|
||||
|
@ -160,13 +162,13 @@ export async function start(
|
|||
};
|
||||
const compiler = webpack(config);
|
||||
const devServer = new WebpackDevServer(compiler, devServerConfig);
|
||||
devServer.listen(port, host, err => {
|
||||
devServer.listen(port, host, (err) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
cliOptions.open && openBrowser(openUrl);
|
||||
});
|
||||
['SIGINT', 'SIGTERM'].forEach(sig => {
|
||||
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
||||
process.on(sig as NodeJS.Signals, () => {
|
||||
devServer.close();
|
||||
process.exit();
|
||||
|
|
|
@ -10,7 +10,9 @@ import {Plugin} from '@docusaurus/types';
|
|||
export function loadClientModules(plugins: Plugin<any>[]): string[] {
|
||||
return ([] as string[]).concat(
|
||||
...plugins
|
||||
.map<any>(plugin => plugin.getClientModules && plugin.getClientModules())
|
||||
.map<any>(
|
||||
(plugin) => plugin.getClientModules && plugin.getClientModules(),
|
||||
)
|
||||
.filter(Boolean),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ const DEFAULT_CONFIG: {
|
|||
};
|
||||
|
||||
function formatFields(fields: string[]): string {
|
||||
return fields.map(field => `'${field}'`).join(', ');
|
||||
return fields.map((field) => `'${field}'`).join(', ');
|
||||
}
|
||||
|
||||
export function loadConfig(siteDir: string): DocusaurusConfig {
|
||||
|
@ -57,7 +57,7 @@ export function loadConfig(siteDir: string): DocusaurusConfig {
|
|||
|
||||
const loadedConfig = importFresh(configPath) as Partial<DocusaurusConfig>;
|
||||
const missingFields = REQUIRED_FIELDS.filter(
|
||||
field => !has(loadedConfig, field),
|
||||
(field) => !has(loadedConfig, field),
|
||||
);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
|
@ -77,7 +77,7 @@ export function loadConfig(siteDir: string): DocusaurusConfig {
|
|||
// Don't allow unrecognized fields.
|
||||
const allowedFields = [...REQUIRED_FIELDS, ...OPTIONAL_FIELDS];
|
||||
const unrecognizedFields = Object.keys(config).filter(
|
||||
field => !allowedFields.includes(field),
|
||||
(field) => !allowedFields.includes(field),
|
||||
);
|
||||
|
||||
if (unrecognizedFields && unrecognizedFields.length > 0) {
|
||||
|
|
|
@ -35,8 +35,8 @@ export function htmlTagObjectToString(tagDefinition: any): string {
|
|||
const isVoidTag = voidHtmlTags.indexOf(tagDefinition.tagName) !== -1;
|
||||
const tagAttributes = tagDefinition.attributes || {};
|
||||
const attributes = Object.keys(tagAttributes)
|
||||
.filter(attributeName => tagAttributes[attributeName] !== false)
|
||||
.map(attributeName => {
|
||||
.filter((attributeName) => tagAttributes[attributeName] !== false)
|
||||
.map((attributeName) => {
|
||||
if (tagAttributes[attributeName] === true) {
|
||||
return attributeName;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue