fix(*): make TypeScript realize that each plugin package has a default export (#7294)

This commit is contained in:
Joshua Chen 2022-05-03 18:23:34 +08:00 committed by GitHub
parent b49ae67521
commit a2c993bf9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 208 additions and 187 deletions

View file

@ -9,13 +9,7 @@ import fs from 'fs-extra';
import path from 'path';
import readingTime from 'reading-time';
import _ from 'lodash';
import type {
BlogPost,
BlogContentPaths,
BlogMarkdownLoaderOptions,
BlogTags,
BlogPaginated,
} from './types';
import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types';
import {
parseMarkdownString,
normalizeUrl,
@ -37,6 +31,9 @@ import logger from '@docusaurus/logger';
import type {
PluginOptions,
ReadingTimeFunction,
BlogPost,
BlogTags,
BlogPaginated,
} from '@docusaurus/plugin-content-blog';
export function truncate(fileString: string, truncateMarker: RegExp): string {

View file

@ -6,7 +6,6 @@
*/
import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
import type {BlogPost} from './types';
import {normalizeUrl, readOutputHTMLFile} from '@docusaurus/utils';
import {load as cheerioLoad} from 'cheerio';
import type {DocusaurusConfig} from '@docusaurus/types';
@ -16,6 +15,7 @@ import type {
FeedType,
PluginOptions,
Author,
BlogPost,
} from '@docusaurus/plugin-content-blog';
import {blogPostContainerID} from '@docusaurus/utils-common';

View file

@ -25,14 +25,7 @@ import {
} from '@docusaurus/utils';
import {translateContent, getTranslationFiles} from './translations';
import type {
BlogTag,
BlogTags,
BlogContent,
BlogPaginated,
BlogContentPaths,
BlogMarkdownLoaderOptions,
} from './types';
import type {BlogContentPaths, BlogMarkdownLoaderOptions} from './types';
import type {LoadContext, Plugin, HtmlTags} from '@docusaurus/types';
import {
generateBlogPosts,
@ -46,6 +39,10 @@ import type {
BlogPostFrontMatter,
BlogPostMetadata,
Assets,
BlogTag,
BlogTags,
BlogContent,
BlogPaginated,
} from '@docusaurus/plugin-content-blog';
export default async function pluginContentBlog(

View file

@ -8,6 +8,7 @@
declare module '@docusaurus/plugin-content-blog' {
import type {MDXOptions} from '@docusaurus/mdx-loader';
import type {FrontMatterTag, Tag} from '@docusaurus/utils';
import type {Plugin, LoadContext} from '@docusaurus/types';
import type {Overwrite} from 'utility-types';
export type Assets = {
@ -410,6 +411,62 @@ declare module '@docusaurus/plugin-content-blog' {
title: string;
items: {title: string; permalink: string}[];
};
export type BlogContent = {
blogSidebarTitle: string;
blogPosts: BlogPost[];
blogListPaginated: BlogPaginated[];
blogTags: BlogTags;
blogTagsListPath: string;
};
export type BlogTags = {
[permalink: string]: BlogTag;
};
export type BlogTag = Tag & {
/** Blog post permalinks. */
items: string[];
pages: BlogPaginated[];
};
export type BlogPost = {
id: string;
metadata: BlogPostMetadata;
content: string;
};
export type BlogPaginatedMetadata = {
/** Title of the entire blog. */
readonly blogTitle: string;
/** Blog description. */
readonly blogDescription: string;
/** Permalink to the next list page. */
readonly nextPage?: string;
/** Permalink of the current page. */
readonly permalink: string;
/** Permalink to the previous list page. */
readonly previousPage?: string;
/** Index of the current page, 1-based. */
readonly page: number;
/** Posts displayed on each list page. */
readonly postsPerPage: number;
/** Total number of posts in the entire blog. */
readonly totalCount: number;
/** Total number of list pages. */
readonly totalPages: number;
};
export type BlogPaginated = {
metadata: BlogPaginatedMetadata;
/** Blog post permalinks. */
items: string[];
};
export default function pluginContentBlog(
context: LoadContext,
options: PluginOptions,
): Promise<Plugin<BlogContent>>;
}
declare module '@theme/BlogPostPage' {
@ -446,34 +503,16 @@ declare module '@theme/BlogPostPage' {
declare module '@theme/BlogListPage' {
import type {Content} from '@theme/BlogPostPage';
import type {BlogSidebar} from '@docusaurus/plugin-content-blog';
export type Metadata = {
/** Title of the entire blog. */
readonly blogTitle: string;
/** Blog description. */
readonly blogDescription: string;
/** Permalink to the next list page. */
readonly nextPage?: string;
/** Permalink of the current page. */
readonly permalink: string;
/** Permalink to the previous list page. */
readonly previousPage?: string;
/** Index of the current page, 1-based. */
readonly page: number;
/** Posts displayed on each list page. */
readonly postsPerPage: number;
/** Total number of posts in the entire blog. */
readonly totalCount: number;
/** Total number of list pages. */
readonly totalPages: number;
};
import type {
BlogSidebar,
BlogPaginatedMetadata,
} from '@docusaurus/plugin-content-blog';
export interface Props {
/** Blog sidebar. */
readonly sidebar: BlogSidebar;
/** Metadata of the current listing page. */
readonly metadata: Metadata;
readonly metadata: BlogPaginatedMetadata;
/**
* Array of blog posts included on this page. Every post's metadata is also
* available.
@ -499,9 +538,11 @@ declare module '@theme/BlogTagsListPage' {
}
declare module '@theme/BlogTagsPostsPage' {
import type {BlogSidebar} from '@docusaurus/plugin-content-blog';
import type {
BlogSidebar,
BlogPaginatedMetadata,
} from '@docusaurus/plugin-content-blog';
import type {Content} from '@theme/BlogPostPage';
import type {Metadata} from '@theme/BlogListPage';
import type {TagModule} from '@docusaurus/utils';
export interface Props {
@ -510,7 +551,7 @@ declare module '@theme/BlogTagsPostsPage' {
/** Metadata of this tag. */
readonly tag: TagModule;
/** Looks exactly the same as the posts list page */
readonly listMetadata: Metadata;
readonly listMetadata: BlogPaginatedMetadata;
/**
* Array of blog posts included on this page. Every post's metadata is also
* available.

View file

@ -5,9 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
import type {BlogContent, BlogPaginated} from './types';
import type {TranslationFileContent, TranslationFile} from '@docusaurus/types';
import type {PluginOptions} from '@docusaurus/plugin-content-blog';
import type {
PluginOptions,
BlogContent,
BlogPaginated,
} from '@docusaurus/plugin-content-blog';
function translateListPage(
blogListPaginated: BlogPaginated[],

View file

@ -5,42 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/
import type {BrokenMarkdownLink, ContentPaths, Tag} from '@docusaurus/utils';
import type {BlogPostMetadata} from '@docusaurus/plugin-content-blog';
import type {Metadata as BlogPaginatedMetadata} from '@theme/BlogListPage';
import type {BrokenMarkdownLink, ContentPaths} from '@docusaurus/utils';
export type BlogContentPaths = ContentPaths;
export type BlogContent = {
blogSidebarTitle: string;
blogPosts: BlogPost[];
blogListPaginated: BlogPaginated[];
blogTags: BlogTags;
blogTagsListPath: string;
};
export type BlogTags = {
[permalink: string]: BlogTag;
};
export type BlogTag = Tag & {
/** Blog post permalinks. */
items: string[];
pages: BlogPaginated[];
};
export type BlogPost = {
id: string;
metadata: BlogPostMetadata;
content: string;
};
export type BlogPaginated = {
metadata: BlogPaginatedMetadata;
/** Blog post permalinks. */
items: string[];
};
export type BlogBrokenMarkdownLink = BrokenMarkdownLink<BlogContentPaths>;
export type BlogMarkdownLoaderOptions = {
siteDir: string;