mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +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
|
@ -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();
|
||||
|
|
|
@ -14,7 +14,7 @@ const toSlug = require('./toSlug');
|
|||
function anchors(md) {
|
||||
const originalRender = md.renderer.rules.heading_open;
|
||||
|
||||
md.renderer.rules.heading_open = function(tokens, idx, options, env) {
|
||||
md.renderer.rules.heading_open = function (tokens, idx, options, env) {
|
||||
if (!env.slugger) {
|
||||
env.slugger = new GithubSlugger();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue