refactor(v2): stronger typing for blog plugin (#2072)

* refactor(v2): stronger typing for blog plugin

* Explicit
This commit is contained in:
Endi 2019-11-30 22:26:28 +07:00 committed by GitHub
parent 6155115280
commit 2297ae9f57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View file

@ -13,18 +13,19 @@ import {normalizeUrl, docuHash} from '@docusaurus/utils';
import {
PluginOptions,
BlogTags,
Tag,
BlogContent,
BlogItemsToModules,
TagsModule,
BlogPaginated,
} from './types';
import {
LoadContext,
PluginContentLoadedActions,
ConfigureWebpackUtils,
Props,
Plugin,
} from '@docusaurus/types';
import {Configuration} from 'webpack';
import {Configuration, Loader} from 'webpack';
import {generateBlogFeed, generateBlogPosts} from './blogUtils';
const DEFAULT_OPTIONS: PluginOptions = {
@ -44,7 +45,7 @@ const DEFAULT_OPTIONS: PluginOptions = {
export default function pluginContentBlog(
context: LoadContext,
opts: Partial<PluginOptions>,
) {
): Plugin<BlogContent | null> {
const options: PluginOptions = {...DEFAULT_OPTIONS, ...opts};
const contentPath = path.resolve(context.siteDir, options.path);
const dataDir = path.join(
@ -98,7 +99,7 @@ export default function pluginContentBlog(
} = context;
const basePageUrl = normalizeUrl([baseUrl, routeBasePath]);
const blogListPaginated = [];
const blogListPaginated: BlogPaginated[] = [];
function blogPaginationPermalink(page: number) {
return page > 0
@ -155,7 +156,7 @@ export default function pluginContentBlog(
return {
label: tag,
permalink,
} as Tag;
};
} else {
return tag;
}
@ -275,6 +276,10 @@ export default function pluginContentBlog(
);
// Tags.
if (blogTagsListPath === null) {
return;
}
const tagsModule: TagsModule = {};
await Promise.all(
@ -372,7 +377,7 @@ export default function pluginContentBlog(
truncateMarker,
},
},
].filter(Boolean),
].filter(Boolean) as Loader[],
},
],
},