misc(v2): clean up comments in code (#2294)

This commit is contained in:
Yangshun Tay 2020-02-18 21:29:23 +08:00 committed by GitHub
parent d7f3dff6e6
commit 996b115199
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 234 additions and 155 deletions

View file

@ -71,7 +71,7 @@ export default function pluginContentDocs(
'docusaurus-plugin-content-docs',
);
// Versioning
// Versioning.
const env = loadEnv(siteDir);
const {versioning} = env;
const {
@ -128,7 +128,7 @@ export default function pluginContentDocs(
const docsMetadataRaw: DocsMetadataRaw = {};
const docsPromises = [];
// Metadata for default/ master docs files.
// Metadata for default/master docs files.
const docsFiles = await globby(include, {
cwd: docsDir,
});
@ -147,7 +147,7 @@ export default function pluginContentDocs(
),
);
// Metadata for versioned docs
// Metadata for versioned docs.
if (versioning.enabled) {
const versionedGlob = _.flatten(
include.map(pattern =>
@ -173,7 +173,7 @@ export default function pluginContentDocs(
);
}
// Load the sidebars & create docs ordering
// Load the sidebars and create docs ordering.
const sidebarPaths = [
sidebarPath,
...versionsNames.map(
@ -185,7 +185,7 @@ export default function pluginContentDocs(
await Promise.all(docsPromises);
// Construct inter-metadata relationship in docsMetadata
// Construct inter-metadata relationship in docsMetadata.
const docsMetadata: DocsMetadata = {};
const permalinkToSidebar: PermalinkToSidebar = {};
const versionToSidebars: VersionToSidebars = {};
@ -211,7 +211,7 @@ export default function pluginContentDocs(
next,
};
// sourceToPermalink and permalinkToSidebar mapping
// sourceToPermalink and permalinkToSidebar mapping.
const {source, permalink, version} = docsMetadataRaw[currentID];
sourceToPermalink[source] = permalink;
if (sidebar) {
@ -255,8 +255,9 @@ export default function pluginContentDocs(
}
};
// Transform the sidebar so that all sidebar item will be in the form of 'link' or 'category' only
// This is what will be passed as props to the UI component
// Transform the sidebar so that all sidebar item will be in the
// form of 'link' or 'category' only.
// This is what will be passed as props to the UI component.
const docsSidebars: DocsSidebar = Object.entries(loadedSidebars).reduce(
(acc: DocsSidebar, [sidebarId, sidebarItems]) => {
acc[sidebarId] = sidebarItems.map(normalizeItem);
@ -290,10 +291,12 @@ export default function pluginContentDocs(
const routes = await Promise.all(
metadataItems.map(async metadataItem => {
await createData(
// Note that this created data path must be in sync with metadataPath provided to mdx-loader
// Note that this created data path must be in sync with
// metadataPath provided to mdx-loader.
`${docuHash(metadataItem.source)}.json`,
JSON.stringify(metadataItem, null, 2),
);
return {
path: metadataItem.permalink,
component: docItemComponent,
@ -304,6 +307,7 @@ export default function pluginContentDocs(
};
}),
);
return routes.sort((a, b) =>
a.path > b.path ? 1 : b.path > a.path ? -1 : 0,
);
@ -331,8 +335,8 @@ export default function pluginContentDocs(
});
};
// If versioning is enabled, we cleverly chunk the generated routes to be by version
// and pick only needed base metadata
// If versioning is enabled, we cleverly chunk the generated routes
// to be by version and pick only needed base metadata.
if (versioning.enabled) {
const docsMetadataByVersion = _.groupBy(
Object.values(content.docsMetadata),
@ -365,8 +369,9 @@ export default function pluginContentDocs(
version,
};
// We want latest version route config to be placed last in the generated routeconfig.
// Otherwise, `/docs/next/foo` will match `/docs/:route` instead of `/docs/next/:route`
// We want latest version route config to be placed last in the
// generated routeconfig. Otherwise, `/docs/next/foo` will match
// `/docs/:route` instead of `/docs/next/:route`.
return addBaseRoute(
docsBaseRoute,
docsBaseMetadata,
@ -410,7 +415,8 @@ export default function pluginContentDocs(
remarkPlugins,
rehypePlugins,
metadataPath: (mdxPath: string) => {
// Note that metadataPath must be the same/ in-sync as the path from createData for each MDX
// Note that metadataPath must be the same/in-sync as
// the path from createData for each MDX.
const aliasedSource = aliasedSitePath(mdxPath, siteDir);
return path.join(
dataDir,