feat: async plugin creator functions (#6166)

This commit is contained in:
Sébastien Lorber 2021-12-22 19:10:49 +01:00 committed by GitHub
parent f8a670966e
commit b393700a61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 90 additions and 79 deletions

View file

@ -51,11 +51,12 @@ import {
} from './blogUtils';
import {BlogPostFrontMatter} from './blogFrontMatter';
import {createBlogFeedFiles} from './feed';
import {getAuthorsMapFilePath} from './authors';
export default function pluginContentBlog(
export default async function pluginContentBlog(
context: LoadContext,
options: PluginOptions,
): Plugin<BlogContent> {
): Promise<Plugin<BlogContent>> {
if (options.admonitions) {
options.remarkPlugins = options.remarkPlugins.concat([
[admonitions, options.admonitions],
@ -89,24 +90,23 @@ export default function pluginContentBlog(
const aliasedSource = (source: string) =>
`~blog/${posixPath(path.relative(pluginDataDirRoot, source))}`;
const authorsMapFilePath = await getAuthorsMapFilePath({
authorsMapPath: options.authorsMapPath,
contentPaths,
});
return {
name: 'docusaurus-plugin-content-blog',
getPathsToWatch() {
const {include, authorsMapPath} = options;
const {include} = options;
const contentMarkdownGlobs = getContentPathList(contentPaths).flatMap(
(contentPath) => include.map((pattern) => `${contentPath}/${pattern}`),
);
// TODO: we should read this path in plugin! but plugins do not support async init for now :'(
// const authorsMapFilePath = await getAuthorsMapFilePath({authorsMapPath,contentPaths,});
// simplified impl, better than nothing for now:
const authorsMapFilePath = path.join(
contentPaths.contentPath,
authorsMapPath,
);
return [authorsMapFilePath, ...contentMarkdownGlobs];
return [authorsMapFilePath, ...contentMarkdownGlobs].filter(
Boolean,
) as string[];
},
async getTranslationFiles() {