mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-05 20:32:42 +02:00
refactor(v2): stronger typing for blog plugin (#2072)
* refactor(v2): stronger typing for blog plugin * Explicit
This commit is contained in:
parent
6155115280
commit
2297ae9f57
2 changed files with 23 additions and 8 deletions
|
@ -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[],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -9,7 +9,7 @@ export interface BlogContent {
|
|||
blogPosts: BlogPost[];
|
||||
blogListPaginated: BlogPaginated[];
|
||||
blogTags: BlogTags;
|
||||
blogTagsListPath: string;
|
||||
blogTagsListPath: string | null;
|
||||
}
|
||||
|
||||
export interface DateLink {
|
||||
|
@ -53,8 +53,18 @@ export interface BlogPost {
|
|||
metadata: MetaData;
|
||||
}
|
||||
|
||||
export interface BlogPaginatedMetadata {
|
||||
permalink: string;
|
||||
page: number;
|
||||
postsPerPage: number;
|
||||
totalPages: number;
|
||||
totalCount: number;
|
||||
previousPage: string | null;
|
||||
nextPage: string | null;
|
||||
}
|
||||
|
||||
export interface BlogPaginated {
|
||||
metadata: MetaData;
|
||||
metadata: BlogPaginatedMetadata;
|
||||
items: string[];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue