mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 23:27:28 +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
|
@ -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 "/".]`,
|
||||
),
|
||||
|
|
|
@ -26,7 +26,7 @@ export function getVersionsJSONFile(siteDir: string) {
|
|||
return path.join(siteDir, VERSIONS_JSON_FILE);
|
||||
}
|
||||
|
||||
export default function(siteDir: string): Env {
|
||||
export default function (siteDir: string): Env {
|
||||
const versioning: VersioningEnv = {
|
||||
enabled: false,
|
||||
versions: [],
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -9,7 +9,7 @@ import {getOptions} from 'loader-utils';
|
|||
import {loader} from 'webpack';
|
||||
import linkify from './linkify';
|
||||
|
||||
export = function(fileString: string) {
|
||||
export = function (fileString: string) {
|
||||
const callback = this.async();
|
||||
const {docsDir, siteDir, versionedDir, sourceToPermalink} = getOptions(this);
|
||||
return (
|
||||
|
|
|
@ -10,7 +10,7 @@ import {resolve} from 'url';
|
|||
import {getSubFolder} from '@docusaurus/utils';
|
||||
import {SourceToPermalink} from '../types';
|
||||
|
||||
export default function(
|
||||
export default function (
|
||||
fileString: string,
|
||||
filePath: string,
|
||||
docsDir: string,
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue