Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move blog theme component type defs to theme-classic #6175

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {
BlogPostFrontMatter,
validateBlogPostFrontMatter,
} from '../blogFrontMatter';
import {validateBlogPostFrontMatter} from '../blogFrontMatter';
import type {BlogPostFrontMatter} from '@docusaurus/plugin-content-blog';
import escapeStringRegexp from 'escape-string-regexp';

// TODO this abstraction reduce verbosity but it makes it harder to debug
Expand Down
7 changes: 4 additions & 3 deletions packages/docusaurus-plugin-content-blog/src/authors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import fs from 'fs-extra';
import logger from '@docusaurus/logger';
import path from 'path';
import {Author, BlogContentPaths} from './types';
import {BlogContentPaths} from './types';
import {findFolderContainingFile} from '@docusaurus/utils';
import {Joi, URISchema} from '@docusaurus/utils-validation';
import {
import type {
Author,
BlogPostFrontMatter,
BlogPostFrontMatterAuthor,
BlogPostFrontMatterAuthors,
} from './blogFrontMatter';
} from '@docusaurus/plugin-content-blog';
import {getContentPathList} from './blogUtils';
import Yaml from 'js-yaml';

Expand Down
47 changes: 1 addition & 46 deletions packages/docusaurus-plugin-content-blog/src/blogFrontMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,7 @@ import {
FrontMatterTagsSchema,
FrontMatterTOCHeadingLevels,
} from '@docusaurus/utils-validation';
import type {FrontMatterTag} from '@docusaurus/utils';

export type BlogPostFrontMatterAuthor = Record<string, unknown> & {
key?: string;
name?: string;
imageURL?: string;
url?: string;
title?: string;
};

// All the possible variants that the user can use for convenience
export type BlogPostFrontMatterAuthors =
| string
| BlogPostFrontMatterAuthor
| (string | BlogPostFrontMatterAuthor)[];
import type {BlogPostFrontMatter} from '@docusaurus/plugin-content-blog';

const BlogPostFrontMatterAuthorSchema = Joi.object({
key: Joi.string(),
Expand All @@ -38,37 +24,6 @@ const BlogPostFrontMatterAuthorSchema = Joi.object({
.or('key', 'name')
.rename('image_url', 'imageURL', {alias: true});

export type BlogPostFrontMatter = {
id?: string;
title?: string;
description?: string;
tags?: FrontMatterTag[];
slug?: string;
draft?: boolean;
date?: Date | string; // Yaml automagically convert some string patterns as Date, but not all

authors?: BlogPostFrontMatterAuthors;

// We may want to deprecate those older author frontmatter fields later:
author?: string;
author_title?: string;
author_url?: string;
author_image_url?: string;

/** @deprecated */
authorTitle?: string;
/** @deprecated */
authorURL?: string;
/** @deprecated */
authorImageURL?: string;

image?: string;
keywords?: string[];
hide_table_of_contents?: boolean;
toc_min_heading_level?: number;
toc_max_heading_level?: number;
};

const FrontMatterAuthorErrorMessage =
'{{#label}} does not look like a valid blog post author. Please use an author key or an author object (with a key and/or name).';

Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-blog/src/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/

import {Feed, Author as FeedAuthor, Item as FeedItem} from 'feed';
import {PluginOptions, Author, BlogPost, FeedType} from './types';
import type {PluginOptions, BlogPost, FeedType} from './types';
import {normalizeUrl, mdxToHtml} from '@docusaurus/utils';
import {DocusaurusConfig} from '@docusaurus/types';
import type {Author} from '@docusaurus/plugin-content-blog';
import path from 'path';
import fs from 'fs-extra';

Expand Down
6 changes: 4 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
BlogContentPaths,
BlogMarkdownLoaderOptions,
MetaData,
Assets,
} from './types';
import {PluginOptionSchema} from './pluginOptionSchema';
import {
Expand All @@ -49,7 +48,10 @@ import {
getSourceToPermalink,
getBlogTags,
} from './blogUtils';
import {BlogPostFrontMatter} from './blogFrontMatter';
import type {
BlogPostFrontMatter,
Assets,
} from '@docusaurus/plugin-content-blog';
import {createBlogFeedFiles} from './feed';
import {getAuthorsMapFilePath} from './authors';

Expand Down
245 changes: 110 additions & 135 deletions packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,139 +5,114 @@
* LICENSE file in the root directory of this source tree.
*/

declare module '@docusaurus/plugin-content-blog' {
export type Options = Partial<import('./types').UserPluginOptions>;
}

declare module '@theme/BlogSidebar' {
export type BlogSidebarItem = {title: string; permalink: string};
export type BlogSidebar = {
title: string;
items: BlogSidebarItem[];
};

export interface Props {
readonly sidebar: BlogSidebar;
}

const BlogSidebar: (props: Props) => JSX.Element;
export default BlogSidebar;
}

declare module '@theme/BlogPostPage' {
import type {BlogSidebar} from '@theme/BlogSidebar';
import type {TOCItem} from '@docusaurus/types';

export type FrontMatter = import('./blogFrontMatter').BlogPostFrontMatter;
export type Assets = import('./types').Assets;

export type Metadata = {
readonly title: string;
readonly date: string;
readonly formattedDate: string;
import type {FrontMatterTag} from '@docusaurus/utils';
import type {TOCItem} from '@docusaurus/types';

export type Options = Partial<import('./types').UserPluginOptions>;

// We allow passing custom fields to authors, e.g., twitter
export type Author = Record<string, unknown> & {
name?: string;
imageURL?: string;
url?: string;
title?: string;
};

export type BlogPostFrontMatterAuthor = Author & {
key?: string;
};

// All the possible variants that the user can use for convenience
export type BlogPostFrontMatterAuthors =
| string
| BlogPostFrontMatterAuthor
| (string | BlogPostFrontMatterAuthor)[];

export type BlogPostFrontMatter = {
id?: string;
title?: string;
description?: string;
tags?: FrontMatterTag[];
slug?: string;
draft?: boolean;
date?: Date | string; // Yaml automagically convert some string patterns as Date, but not all

authors?: BlogPostFrontMatterAuthors;

// We may want to deprecate those older author frontmatter fields later:
author?: string;
author_title?: string;
author_url?: string;
author_image_url?: string;

/** @deprecated */
authorTitle?: string;
/** @deprecated */
authorURL?: string;
/** @deprecated */
authorImageURL?: string;

image?: string;
keywords?: string[];
hide_table_of_contents?: boolean;
toc_min_heading_level?: number;
toc_max_heading_level?: number;
};

export type Assets = {
image?: string;
authorsImageUrls: (string | undefined)[]; // Array of same size as the original MetaData.authors array
};

export type BlogPostMetadata = {
readonly title: string;
readonly date: string;
readonly formattedDate: string;
readonly permalink: string;
readonly description?: string;
readonly editUrl?: string;
readonly readingTime?: number;
readonly truncated?: string;
readonly nextItem?: {readonly title: string; readonly permalink: string};
readonly prevItem?: {readonly title: string; readonly permalink: string};
readonly authors: Author[];
readonly tags: readonly {
readonly label: string;
readonly permalink: string;
readonly description?: string;
readonly editUrl?: string;
readonly readingTime?: number;
readonly truncated?: string;
readonly nextItem?: {readonly title: string; readonly permalink: string};
readonly prevItem?: {readonly title: string; readonly permalink: string};
readonly authors: import('./types').Author[];
readonly frontMatter: FrontMatter & Record<string, unknown>;
readonly tags: readonly {
readonly label: string;
readonly permalink: string;
}[];
};

export type Content = {
readonly frontMatter: FrontMatter;
readonly assets: Assets;
readonly metadata: Metadata;
readonly toc: readonly TOCItem[];
(): JSX.Element;
};

export interface Props {
readonly sidebar: BlogSidebar;
readonly content: Content;
}

const BlogPostPage: (props: Props) => JSX.Element;
export default BlogPostPage;
}

declare module '@theme/BlogListPage' {
import type {Content} from '@theme/BlogPostPage';
import type {BlogSidebar} from '@theme/BlogSidebar';

export type Metadata = {
readonly blogTitle: string;
readonly blogDescription: string;
readonly nextPage?: string;
readonly page: number;
readonly permalink: string;
readonly postsPerPage: number;
readonly previousPage?: string;
readonly totalCount: number;
readonly totalPages: number;
};

export interface Props {
readonly sidebar: BlogSidebar;
readonly metadata: Metadata;
readonly items: readonly {readonly content: Content}[];
}

const BlogListPage: (props: Props) => JSX.Element;
export default BlogListPage;
}

declare module '@theme/BlogTagsListPage' {
import type {BlogSidebar} from '@theme/BlogSidebar';

export type Tag = {
permalink: string;
name: string;
count: number;
allTagsPath: string;
slug: string;
};

export interface Props {
readonly sidebar: BlogSidebar;
readonly tags: Readonly<Record<string, Tag>>;
}

const BlogTagsListPage: (props: Props) => JSX.Element;
export default BlogTagsListPage;
}

declare module '@theme/BlogTagsPostsPage' {
import type {BlogSidebar} from '@theme/BlogSidebar';
import type {Tag} from '@theme/BlogTagsListPage';
import type {Content} from '@theme/BlogPostPage';

export interface Props {
readonly sidebar: BlogSidebar;
readonly metadata: Tag;
readonly items: readonly {readonly content: Content}[];
}

const BlogTagsPostsPage: (props: Props) => JSX.Element;
export default BlogTagsPostsPage;
}

declare module '@theme/BlogArchivePage' {
import type {Content} from '@theme/BlogPostPage';

export type ArchiveBlogPost = Content;

export interface Props {
readonly archive: {
readonly blogPosts: readonly ArchiveBlogPost[];
};
}

export default function BlogArchivePage(props: Props): JSX.Element;
}
}[];
readonly frontMatter: BlogPostFrontMatter & Record<string, unknown>;
};

export type BlogPaginatedMetadata = {
readonly blogTitle: string;
readonly blogDescription: string;
readonly nextPage?: string;
readonly page: number;
readonly permalink: string;
readonly postsPerPage: number;
readonly previousPage?: string;
readonly totalCount: number;
readonly totalPages: number;
};

export type Content = {
readonly frontMatter: BlogPostFrontMatter;
readonly assets: Assets;
readonly metadata: BlogPostMetadata;
readonly toc: readonly TOCItem[];
(): JSX.Element;
};

export type PropBlogSidebarItem = {title: string; permalink: string};
export type PropBlogSidebar = {
title: string;
items: PropBlogSidebarItem[];
};

export type Tag = {
permalink: string;
name: string;
count: number;
allTagsPath: string;
slug: string;
};
Loading