refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type (#7080)

* refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type

* fix
This commit is contained in:
Joshua Chen 2022-03-31 19:16:07 +08:00 committed by GitHub
parent ce2b631455
commit 24c205a835
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 145 additions and 138 deletions

View file

@ -314,7 +314,10 @@ describe('validateBlogPostFrontMatter tags', () => {
{tags: ['hello', {label: 'tagLabel', permalink: '/tagPermalink'}]},
],
invalidFrontMatters: [
[{tags: ''}, '"tags" does not look like a valid FrontMatter Yaml array.'],
[
{tags: ''},
'"tags" does not look like a valid front matter Yaml array.',
],
[{tags: ['']}, 'not allowed to be empty'],
],
// See https://github.com/facebook/docusaurus/issues/4642

View file

@ -102,7 +102,7 @@ export default async function pluginContentBlog(
) as string[];
},
async getTranslationFiles() {
getTranslationFiles() {
return getTranslationFiles(options);
},

View file

@ -10,7 +10,7 @@ declare module '@docusaurus/plugin-content-blog' {
import type {FrontMatterTag, Tag} from '@docusaurus/utils';
import type {Overwrite} from 'utility-types';
export interface Assets {
export type Assets = {
/**
* If `metadata.image` is a collocated image path, this entry will be the
* bundler-generated image path. Otherwise, it's empty, and the image URL
@ -25,13 +25,9 @@ declare module '@docusaurus/plugin-content-blog' {
* should be accessed through `authors.imageURL`.
*/
authorsImageUrls: (string | undefined)[];
}
};
/**
* Unknown keys are allowed, so that we can pass custom fields to authors,
* e.g., `twitter`.
*/
export interface Author extends Record<string, unknown> {
export type Author = {
/**
* If `name` doesn't exist, an `imageURL` is expected.
*/
@ -55,7 +51,12 @@ declare module '@docusaurus/plugin-content-blog' {
* to generate a fallback `mailto:` URL.
*/
email?: string;
}
/**
* Unknown keys are allowed, so that we can pass custom fields to authors,
* e.g., `twitter`.
*/
[key: string]: unknown;
};
/**
* Everything is partial/unnormalized, because front matter is always
@ -443,8 +444,6 @@ declare module '@theme/BlogPostPage' {
>;
export type Content = {
// TODO remove this. `metadata.frontMatter` is preferred because it can be
// accessed in enhanced plugins
/** Same as `metadata.frontMatter` */
readonly frontMatter: FrontMatter;
/**

View file

@ -11,39 +11,41 @@ import type {Metadata as BlogPaginatedMetadata} from '@theme/BlogListPage';
export type BlogContentPaths = ContentPaths;
export interface BlogContent {
export type BlogContent = {
blogSidebarTitle: string;
blogPosts: BlogPost[];
blogListPaginated: BlogPaginated[];
blogTags: BlogTags;
blogTagsListPath: string | null;
}
};
export interface BlogTags {
export type BlogTags = {
// TODO, the key is the tag slug/permalink
// This is due to legacy frontmatter: tags:
// [{label: "xyz", permalink: "/1"}, {label: "xyz", permalink: "/2"}]
// Soon we should forbid declaring permalink through frontmatter
[tagKey: string]: BlogTag;
}
};
export interface BlogTag {
export type BlogTag = {
name: string;
items: string[]; // blog post permalinks
/** Blog post permalinks. */
items: string[];
permalink: string;
pages: BlogPaginated[];
}
};
export interface BlogPost {
export type BlogPost = {
id: string;
metadata: BlogPostMetadata;
content: string;
}
};
export interface BlogPaginated {
export type BlogPaginated = {
metadata: BlogPaginatedMetadata;
items: string[]; // blog post permalinks
}
/** Blog post permalinks. */
items: string[];
};
export type BlogBrokenMarkdownLink = BrokenMarkdownLink<BlogContentPaths>;
export type BlogMarkdownLoaderOptions = {