refactor: move exported type definitions to declaration file (#6300)

* refactor: move exported type definitions to declaration file

* fix

* fix
This commit is contained in:
Joshua Chen 2022-01-09 22:02:31 +08:00 committed by GitHub
parent 9c0e659a44
commit cf265c051e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 482 additions and 452 deletions

View file

@ -5,13 +5,14 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {PluginContext, UserPluginOptions} from '../types'; import type {PluginContext} from '../types';
import collectRedirects from '../collectRedirects'; import collectRedirects from '../collectRedirects';
import normalizePluginOptions from '../normalizePluginOptions'; import normalizePluginOptions from '../normalizePluginOptions';
import {removeTrailingSlash} from '@docusaurus/utils'; import {removeTrailingSlash} from '@docusaurus/utils';
import type {Options} from '@docusaurus/plugin-client-redirects';
function createTestPluginContext( function createTestPluginContext(
options?: UserPluginOptions, options?: Options,
relativeRoutesPaths: string[] = [], relativeRoutesPaths: string[] = [],
): PluginContext { ): PluginContext {
return { return {

View file

@ -7,11 +7,10 @@
import {uniqBy, difference, groupBy} from 'lodash'; import {uniqBy, difference, groupBy} from 'lodash';
import type { import type {
PluginContext,
RedirectMetadata,
PluginOptions, PluginOptions,
RedirectOption, RedirectOption,
} from './types'; } from '@docusaurus/plugin-client-redirects';
import type {PluginContext, RedirectMetadata} from './types';
import { import {
createFromExtensionsRedirects, createFromExtensionsRedirects,
createToExtensionsRedirects, createToExtensionsRedirects,

View file

@ -6,7 +6,8 @@
*/ */
import type {LoadContext, Plugin, Props} from '@docusaurus/types'; import type {LoadContext, Plugin, Props} from '@docusaurus/types';
import type {UserPluginOptions, PluginContext, RedirectMetadata} from './types'; import type {PluginContext, RedirectMetadata} from './types';
import type {PluginOptions} from '@docusaurus/plugin-client-redirects';
import normalizePluginOptions from './normalizePluginOptions'; import normalizePluginOptions from './normalizePluginOptions';
import collectRedirects from './collectRedirects'; import collectRedirects from './collectRedirects';
@ -18,7 +19,7 @@ import {removePrefix, addLeadingSlash} from '@docusaurus/utils';
export default function pluginClientRedirectsPages( export default function pluginClientRedirectsPages(
context: LoadContext, context: LoadContext,
opts: UserPluginOptions, opts: PluginOptions,
): Plugin<unknown> { ): Plugin<unknown> {
const {trailingSlash} = context.siteConfig; const {trailingSlash} = context.siteConfig;

View file

@ -5,7 +5,11 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {PluginOptions, RedirectOption, UserPluginOptions} from './types'; import type {
PluginOptions,
Options as UserPluginOptions,
RedirectOption,
} from '@docusaurus/plugin-client-redirects';
import {Joi, PathnameSchema} from '@docusaurus/utils-validation'; import {Joi, PathnameSchema} from '@docusaurus/utils-validation';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils'; import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';

View file

@ -5,4 +5,23 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
export type Options = import('./types').UserPluginOptions; export type RedirectOption = {
to: string;
from: string | string[];
};
// For a given existing route path,
// return all the paths from which we should redirect from
export type CreateRedirectsFnOption = (
path: string,
) => string[] | string | null | undefined;
export type PluginOptions = {
id: string;
fromExtensions: string[];
toExtensions: string[];
redirects: RedirectOption[];
createRedirects?: CreateRedirectsFnOption;
};
export type Options = Partial<PluginOptions>;

View file

@ -6,27 +6,7 @@
*/ */
import type {Props} from '@docusaurus/types'; import type {Props} from '@docusaurus/types';
import type {PluginOptions} from '@docusaurus/plugin-client-redirects';
export type PluginOptions = {
id: string;
fromExtensions: string[];
toExtensions: string[];
redirects: RedirectOption[];
createRedirects?: CreateRedirectsFnOption;
};
// For a given existing route path,
// return all the paths from which we should redirect from
export type CreateRedirectsFnOption = (
path: string,
) => string[] | string | null | undefined;
export type RedirectOption = {
to: string;
from: string | string[];
};
export type UserPluginOptions = Partial<PluginOptions>;
// The minimal infos the plugin needs to work // The minimal infos the plugin needs to work
export type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & { export type PluginContext = Pick<Props, 'outDir' | 'baseUrl'> & {

View file

@ -5,11 +5,9 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import { import {validateBlogPostFrontMatter} from '../blogFrontMatter';
type BlogPostFrontMatter,
validateBlogPostFrontMatter,
} from '../blogFrontMatter';
import escapeStringRegexp from 'escape-string-regexp'; import escapeStringRegexp from 'escape-string-regexp';
import type {BlogPostFrontMatter} from '@docusaurus/plugin-content-blog';
// TODO this abstraction reduce verbosity but it makes it harder to debug // TODO this abstraction reduce verbosity but it makes it harder to debug
// It would be preferable to just expose helper methods // It would be preferable to just expose helper methods

View file

@ -8,10 +8,11 @@
import path from 'path'; import path from 'path';
import {generateBlogFeed} from '../feed'; import {generateBlogFeed} from '../feed';
import type {LoadContext, I18n} from '@docusaurus/types'; import type {LoadContext, I18n} from '@docusaurus/types';
import type {PluginOptions, BlogContentPaths} from '../types'; import type {BlogContentPaths} from '../types';
import {DEFAULT_OPTIONS} from '../pluginOptionSchema'; import {DEFAULT_OPTIONS} from '../pluginOptionSchema';
import {generateBlogPosts} from '../blogUtils'; import {generateBlogPosts} from '../blogUtils';
import type {Feed} from 'feed'; import type {Feed} from 'feed';
import type {PluginOptions} from '@docusaurus/plugin-content-blog';
const DefaultI18N: I18n = { const DefaultI18N: I18n = {
currentLocale: 'en', currentLocale: 'en',

View file

@ -10,9 +10,13 @@ import path from 'path';
import pluginContentBlog from '../index'; import pluginContentBlog from '../index';
import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types'; import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types';
import {PluginOptionSchema} from '../pluginOptionSchema'; import {PluginOptionSchema} from '../pluginOptionSchema';
import type {PluginOptions, EditUrlFunction, BlogPost} from '../types'; import type {BlogPost} from '../types';
import type {Joi} from '@docusaurus/utils-validation'; import type {Joi} from '@docusaurus/utils-validation';
import {posixPath} from '@docusaurus/utils'; import {posixPath} from '@docusaurus/utils';
import type {
PluginOptions,
EditUrlFunction,
} from '@docusaurus/plugin-content-blog';
function findByTitle( function findByTitle(
blogPosts: BlogPost[], blogPosts: BlogPost[],

View file

@ -5,10 +5,11 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {BlogPost, BlogContent, PluginOptions} from '../types'; import type {BlogPost, BlogContent} from '../types';
import {getTranslationFiles, translateContent} from '../translations'; import {getTranslationFiles, translateContent} from '../translations';
import {DEFAULT_OPTIONS} from '../pluginOptionSchema'; import {DEFAULT_OPTIONS} from '../pluginOptionSchema';
import {updateTranslationFileMessages} from '@docusaurus/utils'; import {updateTranslationFileMessages} from '@docusaurus/utils';
import type {PluginOptions} from '@docusaurus/plugin-content-blog';
const sampleBlogOptions: PluginOptions = { const sampleBlogOptions: PluginOptions = {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,

View file

@ -5,14 +5,15 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {Author, BlogContentPaths} from './types'; import type {BlogContentPaths} from './types';
import {getDataFileData} from '@docusaurus/utils'; import {getDataFileData} from '@docusaurus/utils';
import {Joi, URISchema} from '@docusaurus/utils-validation'; import {Joi, URISchema} from '@docusaurus/utils-validation';
import type { import type {
Author,
BlogPostFrontMatter, BlogPostFrontMatter,
BlogPostFrontMatterAuthor, BlogPostFrontMatterAuthor,
BlogPostFrontMatterAuthors, BlogPostFrontMatterAuthors,
} from './blogFrontMatter'; } from '@docusaurus/plugin-content-blog';
export type AuthorsMap = Record<string, Author>; export type AuthorsMap = Record<string, Author>;

View file

@ -12,21 +12,7 @@ import {
FrontMatterTagsSchema, FrontMatterTagsSchema,
FrontMatterTOCHeadingLevels, FrontMatterTOCHeadingLevels,
} from '@docusaurus/utils-validation'; } from '@docusaurus/utils-validation';
import type {FrontMatterTag} from '@docusaurus/utils'; import type {BlogPostFrontMatter} from '@docusaurus/plugin-content-blog';
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)[];
const BlogPostFrontMatterAuthorSchema = Joi.object({ const BlogPostFrontMatterAuthorSchema = Joi.object({
key: Joi.string(), key: Joi.string(),
@ -38,37 +24,6 @@ const BlogPostFrontMatterAuthorSchema = Joi.object({
.or('key', 'name') .or('key', 'name')
.rename('image_url', 'imageURL', {alias: true}); .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 = 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).'; '{{#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).';

View file

@ -10,12 +10,10 @@ import path from 'path';
import readingTime from 'reading-time'; import readingTime from 'reading-time';
import {keyBy, mapValues} from 'lodash'; import {keyBy, mapValues} from 'lodash';
import type { import type {
PluginOptions,
BlogPost, BlogPost,
BlogContentPaths, BlogContentPaths,
BlogMarkdownLoaderOptions, BlogMarkdownLoaderOptions,
BlogTags, BlogTags,
ReadingTimeFunction,
} from './types'; } from './types';
import { import {
parseMarkdownFile, parseMarkdownFile,
@ -34,6 +32,10 @@ import type {LoadContext} from '@docusaurus/types';
import {validateBlogPostFrontMatter} from './blogFrontMatter'; import {validateBlogPostFrontMatter} from './blogFrontMatter';
import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors'; import {type AuthorsMap, getAuthorsMap, getBlogPostAuthors} from './authors';
import logger from '@docusaurus/logger'; import logger from '@docusaurus/logger';
import type {
PluginOptions,
ReadingTimeFunction,
} from '@docusaurus/plugin-content-blog';
export function truncate(fileString: string, truncateMarker: RegExp): string { export function truncate(fileString: string, truncateMarker: RegExp): string {
return fileString.split(truncateMarker, 1).shift()!; return fileString.split(truncateMarker, 1).shift()!;

View file

@ -6,11 +6,16 @@
*/ */
import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed'; import {Feed, type Author as FeedAuthor, type Item as FeedItem} from 'feed';
import type {PluginOptions, Author, BlogPost, FeedType} from './types'; import type {BlogPost} from './types';
import {normalizeUrl, mdxToHtml} from '@docusaurus/utils'; import {normalizeUrl, mdxToHtml} from '@docusaurus/utils';
import type {DocusaurusConfig} from '@docusaurus/types'; import type {DocusaurusConfig} from '@docusaurus/types';
import path from 'path'; import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import type {
FeedType,
PluginOptions,
Author,
} from '@docusaurus/plugin-content-blog';
// TODO this is temporary until we handle mdxToHtml better // TODO this is temporary until we handle mdxToHtml better
// It's hard to convert reliably JSX/require calls to an html feed content // It's hard to convert reliably JSX/require calls to an html feed content

View file

@ -23,7 +23,6 @@ import {
import {translateContent, getTranslationFiles} from './translations'; import {translateContent, getTranslationFiles} from './translations';
import type { import type {
PluginOptions,
BlogTags, BlogTags,
BlogContent, BlogContent,
BlogItemsToMetadata, BlogItemsToMetadata,
@ -32,7 +31,6 @@ import type {
BlogContentPaths, BlogContentPaths,
BlogMarkdownLoaderOptions, BlogMarkdownLoaderOptions,
MetaData, MetaData,
Assets,
} from './types'; } from './types';
import {PluginOptionSchema} from './pluginOptionSchema'; import {PluginOptionSchema} from './pluginOptionSchema';
import type { import type {
@ -50,8 +48,12 @@ import {
getSourceToPermalink, getSourceToPermalink,
getBlogTags, getBlogTags,
} from './blogUtils'; } from './blogUtils';
import type {BlogPostFrontMatter} from './blogFrontMatter';
import {createBlogFeedFiles} from './feed'; import {createBlogFeedFiles} from './feed';
import type {
PluginOptions,
BlogPostFrontMatter,
Assets,
} from '@docusaurus/plugin-content-blog';
export default async function pluginContentBlog( export default async function pluginContentBlog(
context: LoadContext, context: LoadContext,

View file

@ -6,7 +6,145 @@
*/ */
declare module '@docusaurus/plugin-content-blog' { declare module '@docusaurus/plugin-content-blog' {
export type Options = Partial<import('./types').UserPluginOptions>; import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
import type {FrontMatterTag} from '@docusaurus/utils';
import type {Overwrite} from 'utility-types';
export interface Assets {
image?: string;
authorsImageUrls: (string | undefined)[]; // Array of same size as the original MetaData.authors array
}
// We allow passing custom fields to authors, e.g., twitter
export interface Author extends Record<string, unknown> {
name?: string;
imageURL?: string;
url?: string;
title?: string;
}
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 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)[];
export type EditUrlFunction = (editUrlParams: {
blogDirPath: string;
blogPath: string;
permalink: string;
locale: string;
}) => string | undefined;
export type FeedType = 'rss' | 'atom' | 'json';
export type FeedOptions = {
type?: FeedType[] | null;
title?: string;
description?: string;
copyright: string;
language?: string;
};
// Feed options, as provided by user config
export type UserFeedOptions = Overwrite<
Partial<FeedOptions>,
{type?: FeedOptions['type'] | 'all'} // Handle the type: "all" shortcut
>;
// Duplicate from ngryman/reading-time to keep stability of API
type ReadingTimeOptions = {
wordsPerMinute?: number;
wordBound?: (char: string) => boolean;
};
export type ReadingTimeFunction = (params: {
content: string;
frontMatter?: BlogPostFrontMatter & Record<string, unknown>;
options?: ReadingTimeOptions;
}) => number;
export type ReadingTimeFunctionOption = (
params: Required<Omit<Parameters<ReadingTimeFunction>[0], 'options'>> & {
defaultReadingTime: ReadingTimeFunction;
},
) => number | undefined;
export type PluginOptions = RemarkAndRehypePluginOptions & {
id?: string;
path: string;
routeBasePath: string;
tagsBasePath: string;
archiveBasePath: string;
include: string[];
exclude: string[];
postsPerPage: number | 'ALL';
blogListComponent: string;
blogPostComponent: string;
blogTagsListComponent: string;
blogTagsPostsComponent: string;
blogTitle: string;
blogDescription: string;
blogSidebarCount: number | 'ALL';
blogSidebarTitle: string;
truncateMarker: RegExp;
showReadingTime: boolean;
feedOptions: {
type?: FeedType[] | null;
title?: string;
description?: string;
copyright: string;
language?: string;
};
editUrl?: string | EditUrlFunction;
editLocalizedFiles?: boolean;
admonitions: Record<string, unknown>;
authorsMapPath: string;
readingTime: ReadingTimeFunctionOption;
sortPosts: 'ascending' | 'descending';
};
// Options, as provided in the user config (before normalization)
export type Options = Overwrite<
Partial<PluginOptions>,
{feedOptions?: UserFeedOptions}
>;
} }
declare module '@theme/BlogSidebar' { declare module '@theme/BlogSidebar' {
@ -27,9 +165,13 @@ declare module '@theme/BlogSidebar' {
declare module '@theme/BlogPostPage' { declare module '@theme/BlogPostPage' {
import type {BlogSidebar} from '@theme/BlogSidebar'; import type {BlogSidebar} from '@theme/BlogSidebar';
import type {TOCItem} from '@docusaurus/types'; import type {TOCItem} from '@docusaurus/types';
import type {
BlogPostFrontMatter,
Author,
Assets,
} from '@docusaurus/plugin-content-blog';
export type FrontMatter = import('./blogFrontMatter').BlogPostFrontMatter; export type FrontMatter = BlogPostFrontMatter;
export type Assets = import('./types').Assets;
export type Metadata = { export type Metadata = {
readonly title: string; readonly title: string;
@ -42,7 +184,7 @@ declare module '@theme/BlogPostPage' {
readonly truncated?: string; readonly truncated?: string;
readonly nextItem?: {readonly title: string; readonly permalink: string}; readonly nextItem?: {readonly title: string; readonly permalink: string};
readonly prevItem?: {readonly title: string; readonly permalink: string}; readonly prevItem?: {readonly title: string; readonly permalink: string};
readonly authors: import('./types').Author[]; readonly authors: Author[];
readonly frontMatter: FrontMatter & Record<string, unknown>; readonly frontMatter: FrontMatter & Record<string, unknown>;
readonly tags: readonly { readonly tags: readonly {
readonly label: string; readonly label: string;

View file

@ -13,7 +13,7 @@ import {
URISchema, URISchema,
} from '@docusaurus/utils-validation'; } from '@docusaurus/utils-validation';
import {GlobExcludeDefault} from '@docusaurus/utils'; import {GlobExcludeDefault} from '@docusaurus/utils';
import type {PluginOptions} from './types'; import type {PluginOptions} from '@docusaurus/plugin-content-blog';
export const DEFAULT_OPTIONS: PluginOptions = { export const DEFAULT_OPTIONS: PluginOptions = {
feedOptions: {type: ['rss', 'atom'], copyright: ''}, feedOptions: {type: ['rss', 'atom'], copyright: ''},

View file

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

View file

@ -5,14 +5,15 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
import type {Tag} from '@docusaurus/utils'; import type {Tag} from '@docusaurus/utils';
import type { import type {
BrokenMarkdownLink, BrokenMarkdownLink,
ContentPaths, ContentPaths,
} from '@docusaurus/utils/lib/markdownLinks'; } from '@docusaurus/utils/lib/markdownLinks';
import type {Overwrite} from 'utility-types'; import type {
import type {BlogPostFrontMatter} from './blogFrontMatter'; BlogPostFrontMatter,
Author,
} from '@docusaurus/plugin-content-blog';
export type BlogContentPaths = ContentPaths; export type BlogContentPaths = ContentPaths;
@ -24,87 +25,6 @@ export interface BlogContent {
blogTagsListPath: string | null; blogTagsListPath: string | null;
} }
export type FeedType = 'rss' | 'atom' | 'json';
export type FeedOptions = {
type?: FeedType[] | null;
title?: string;
description?: string;
copyright: string;
language?: string;
};
// Feed options, as provided by user config
export type UserFeedOptions = Overwrite<
Partial<FeedOptions>,
{type?: FeedOptions['type'] | 'all'} // Handle the type: "all" shortcut
>;
export type EditUrlFunction = (editUrlParams: {
blogDirPath: string;
blogPath: string;
permalink: string;
locale: string;
}) => string | undefined;
// Duplicate from ngryman/reading-time to keep stability of API
type ReadingTimeOptions = {
wordsPerMinute?: number;
wordBound?: (char: string) => boolean;
};
export type ReadingTimeFunction = (params: {
content: string;
frontMatter?: BlogPostFrontMatter & Record<string, unknown>;
options?: ReadingTimeOptions;
}) => number;
export type ReadingTimeFunctionOption = (
params: Required<Omit<Parameters<ReadingTimeFunction>[0], 'options'>> & {
defaultReadingTime: ReadingTimeFunction;
},
) => number | undefined;
export type PluginOptions = RemarkAndRehypePluginOptions & {
id?: string;
path: string;
routeBasePath: string;
tagsBasePath: string;
archiveBasePath: string;
include: string[];
exclude: string[];
postsPerPage: number | 'ALL';
blogListComponent: string;
blogPostComponent: string;
blogTagsListComponent: string;
blogTagsPostsComponent: string;
blogTitle: string;
blogDescription: string;
blogSidebarCount: number | 'ALL';
blogSidebarTitle: string;
truncateMarker: RegExp;
showReadingTime: boolean;
feedOptions: {
type?: FeedType[] | null;
title?: string;
description?: string;
copyright: string;
language?: string;
};
editUrl?: string | EditUrlFunction;
editLocalizedFiles?: boolean;
admonitions: Record<string, unknown>;
authorsMapPath: string;
readingTime: ReadingTimeFunctionOption;
sortPosts: 'ascending' | 'descending';
};
// Options, as provided in the user config (before normalization)
export type UserPluginOptions = Overwrite<
Partial<PluginOptions>,
{feedOptions?: UserFeedOptions}
>;
export interface BlogTags { export interface BlogTags {
[key: string]: BlogTag; [key: string]: BlogTag;
} }
@ -138,14 +58,6 @@ export interface BlogPaginated {
items: string[]; items: string[];
} }
// We allow passing custom fields to authors, e.g., twitter
export interface Author extends Record<string, unknown> {
name?: string;
imageURL?: string;
url?: string;
title?: string;
}
export interface MetaData { export interface MetaData {
permalink: string; permalink: string;
source: string; source: string;
@ -163,11 +75,6 @@ export interface MetaData {
frontMatter: BlogPostFrontMatter & Record<string, unknown>; frontMatter: BlogPostFrontMatter & Record<string, unknown>;
} }
export interface Assets {
image?: string;
authorsImageUrls: (string | undefined)[]; // Array of same size as the original MetaData.authors array
}
export interface Paginator { export interface Paginator {
title: string; title: string;
permalink: string; permalink: string;

View file

@ -7,7 +7,10 @@
import path from 'path'; import path from 'path';
import {cliDocsVersionCommand} from '../cli'; import {cliDocsVersionCommand} from '../cli';
import type {PathOptions, SidebarOptions} from '../types'; import type {
PathOptions,
SidebarOptions,
} from '@docusaurus/plugin-content-docs';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { import {
getVersionedDocsDirPath, getVersionedDocsDirPath,

View file

@ -19,12 +19,14 @@ import {readVersionsMetadata} from '../versions';
import type { import type {
DocFile, DocFile,
DocMetadataBase, DocMetadataBase,
MetadataOptions,
VersionMetadata, VersionMetadata,
PluginOptions,
EditUrlFunction,
DocNavLink, DocNavLink,
} from '../types'; } from '../types';
import type {
MetadataOptions,
PluginOptions,
EditUrlFunction,
} from '@docusaurus/plugin-content-docs';
import type {LoadContext} from '@docusaurus/types'; import type {LoadContext} from '@docusaurus/types';
import {DEFAULT_OPTIONS} from '../options'; import {DEFAULT_OPTIONS} from '../options';
import type {Optional} from 'utility-types'; import type {Optional} from 'utility-types';

View file

@ -13,7 +13,7 @@ import {
DisabledNumberPrefixParser, DisabledNumberPrefixParser,
} from '../numberPrefix'; } from '../numberPrefix';
import {GlobExcludeDefault} from '@docusaurus/utils'; import {GlobExcludeDefault} from '@docusaurus/utils';
import type {PluginOptions} from '../types'; import type {PluginOptions} from '@docusaurus/plugin-content-docs';
// the type of remark/rehype plugins is function // the type of remark/rehype plugins is function
const markdownPluginsFunctionStub = () => {}; const markdownPluginsFunctionStub = () => {};

View file

@ -14,8 +14,9 @@ import {
} from '../versions'; } from '../versions';
import {DEFAULT_OPTIONS} from '../options'; import {DEFAULT_OPTIONS} from '../options';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils'; import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import type {PluginOptions, VersionMetadata} from '../types'; import type {VersionMetadata} from '../types';
import type {I18n} from '@docusaurus/types'; import type {I18n} from '@docusaurus/types';
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
const DefaultI18N: I18n = { const DefaultI18N: I18n = {
currentLocale: 'en', currentLocale: 'en',

View file

@ -12,7 +12,10 @@ import {
} from './versions'; } from './versions';
import fs from 'fs-extra'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import type {PathOptions, SidebarOptions} from './types'; import type {
PathOptions,
SidebarOptions,
} from '@docusaurus/plugin-content-docs';
import {loadSidebarsFile, resolveSidebarPathOption} from './sidebars'; import {loadSidebarsFile, resolveSidebarPathOption} from './sidebars';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils'; import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import logger from '@docusaurus/logger'; import logger from '@docusaurus/logger';

View file

@ -7,21 +7,18 @@
import {matchPath} from '@docusaurus/router'; import {matchPath} from '@docusaurus/router';
import type {GlobalPluginData, GlobalVersion, GlobalDoc} from '../types'; import type {
GlobalPluginData,
GlobalVersion,
GlobalDoc,
GetActivePluginOptions,
ActivePlugin,
ActiveDocContext,
DocVersionSuggestions,
} from '@docusaurus/plugin-content-docs/client';
// This code is not part of the api surface, not in ./theme on purpose // This code is not part of the api surface, not in ./theme on purpose
// Short/convenient type aliases
type Version = GlobalVersion;
type Doc = GlobalDoc;
export type ActivePlugin = {
pluginId: string;
pluginData: GlobalPluginData;
};
export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
// get the data of the plugin that is currently "active" // get the data of the plugin that is currently "active"
// ie the docs of that plugin are currently browsed // ie the docs of that plugin are currently browsed
// it is useful to support multiple docs plugin instances // it is useful to support multiple docs plugin instances
@ -56,13 +53,7 @@ export function getActivePlugin(
return activePlugin; return activePlugin;
} }
export type ActiveDocContext = { export const getLatestVersion = (data: GlobalPluginData): GlobalVersion =>
activeVersion?: Version;
activeDoc?: Doc;
alternateDocVersions: Record<string, Doc>;
};
export const getLatestVersion = (data: GlobalPluginData): Version =>
data.versions.find((version) => version.isLast)!; data.versions.find((version) => version.isLast)!;
// Note: return undefined on doc-unrelated pages, // Note: return undefined on doc-unrelated pages,
@ -70,7 +61,7 @@ export const getLatestVersion = (data: GlobalPluginData): Version =>
export const getActiveVersion = ( export const getActiveVersion = (
data: GlobalPluginData, data: GlobalPluginData,
pathname: string, pathname: string,
): Version | undefined => { ): GlobalVersion | undefined => {
const lastVersion = getLatestVersion(data); const lastVersion = getLatestVersion(data);
// Last version is a route like /docs/*, // Last version is a route like /docs/*,
// we need to try to match it last or it would match /docs/version-1.0/* as well // we need to try to match it last or it would match /docs/version-1.0/* as well
@ -127,13 +118,6 @@ export const getActiveDocContext = (
}; };
}; };
export type DocVersionSuggestions = {
// suggest the latest version
latestVersionSuggestion: GlobalVersion;
// suggest the same doc, in latest version (if exist)
latestDocSuggestion?: GlobalDoc;
};
export const getDocVersionSuggestions = ( export const getDocVersionSuggestions = (
data: GlobalPluginData, data: GlobalPluginData,
pathname: string, pathname: string,

View file

@ -11,18 +11,21 @@ import useGlobalData, {
usePluginData, usePluginData,
} from '@docusaurus/useGlobalData'; } from '@docusaurus/useGlobalData';
import type {GlobalPluginData, GlobalVersion} from '../types';
import { import {
getActivePlugin, getActivePlugin,
getLatestVersion, getLatestVersion,
getActiveVersion, getActiveVersion,
getActiveDocContext, getActiveDocContext,
getDocVersionSuggestions, getDocVersionSuggestions,
type ActivePlugin,
type ActiveDocContext,
type DocVersionSuggestions,
type GetActivePluginOptions,
} from './docsClientUtils'; } from './docsClientUtils';
import type {
GlobalPluginData,
GlobalVersion,
ActivePlugin,
ActiveDocContext,
DocVersionSuggestions,
GetActivePluginOptions,
} from '@docusaurus/plugin-content-docs/client';
// Important to use a constant object to avoid React useEffect executions etc..., // Important to use a constant object to avoid React useEffect executions etc...,
// see https://github.com/facebook/docusaurus/issues/5089 // see https://github.com/facebook/docusaurus/issues/5089

View file

@ -28,8 +28,6 @@ import type {
DocMetadata, DocMetadata,
DocNavLink, DocNavLink,
LastUpdateData, LastUpdateData,
MetadataOptions,
PluginOptions,
VersionMetadata, VersionMetadata,
LoadedVersion, LoadedVersion,
} from './types'; } from './types';
@ -40,6 +38,10 @@ import {stripPathNumberPrefixes} from './numberPrefix';
import {validateDocFrontMatter} from './docFrontMatter'; import {validateDocFrontMatter} from './docFrontMatter';
import type {SidebarsUtils} from './sidebars/utils'; import type {SidebarsUtils} from './sidebars/utils';
import {toDocNavigationLink, toNavigationLink} from './sidebars/utils'; import {toDocNavigationLink, toNavigationLink} from './sidebars/utils';
import type {
MetadataOptions,
PluginOptions,
} from '@docusaurus/plugin-content-docs';
type LastUpdateOptions = Pick< type LastUpdateOptions = Pick<
PluginOptions, PluginOptions,

View file

@ -9,13 +9,12 @@ import {mapValues} from 'lodash';
import {normalizeUrl} from '@docusaurus/utils'; import {normalizeUrl} from '@docusaurus/utils';
import type {Sidebars} from './sidebars/types'; import type {Sidebars} from './sidebars/types';
import {createSidebarsUtils} from './sidebars/utils'; import {createSidebarsUtils} from './sidebars/utils';
import type {DocMetadata, LoadedVersion} from './types';
import type { import type {
DocMetadata,
GlobalDoc,
LoadedVersion,
GlobalVersion, GlobalVersion,
GlobalSidebar, GlobalSidebar,
} from './types'; GlobalDoc,
} from '@docusaurus/plugin-content-docs/client';
export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc { export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
return { return {

View file

@ -30,11 +30,9 @@ import {
import {getDocsDirPaths, readVersionsMetadata} from './versions'; import {getDocsDirPaths, readVersionsMetadata} from './versions';
import type { import type {
PluginOptions,
LoadedContent, LoadedContent,
SourceToPermalink, SourceToPermalink,
DocMetadataBase, DocMetadataBase,
GlobalPluginData,
VersionMetadata, VersionMetadata,
LoadedVersion, LoadedVersion,
DocFile, DocFile,
@ -54,7 +52,11 @@ import {
import logger from '@docusaurus/logger'; import logger from '@docusaurus/logger';
import {getVersionTags} from './tags'; import {getVersionTags} from './tags';
import {createVersionRoutes} from './routes'; import {createVersionRoutes} from './routes';
import type {PropTagsListPage} from '@docusaurus/plugin-content-docs'; import type {
PropTagsListPage,
PluginOptions,
} from '@docusaurus/plugin-content-docs';
import type {GlobalPluginData} from '@docusaurus/plugin-content-docs/client';
import {createSidebarsUtils} from './sidebars/utils'; import {createSidebarsUtils} from './sidebars/utils';
import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex'; import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {NumberPrefixParser} from './types'; import type {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
// Best-effort to avoid parsing some patterns as number prefix // Best-effort to avoid parsing some patterns as number prefix
const IgnoredPrefixPatterns = (function () { const IgnoredPrefixPatterns = (function () {

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {PluginOptions} from './types'; import type {PluginOptions} from '@docusaurus/plugin-content-docs';
import { import {
Joi, Joi,
RemarkPluginsSchema, RemarkPluginsSchema,

View file

@ -6,15 +6,76 @@
*/ */
declare module '@docusaurus/plugin-content-docs' { declare module '@docusaurus/plugin-content-docs' {
export type Options = Partial<import('./types').PluginOptions>; import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
export type VersionBanner = import('./types').VersionBanner;
type GlobalDataVersion = import('./types').GlobalVersion;
type GlobalDataDoc = import('./types').GlobalDoc;
type GlobalDataSidebar = import('./types').GlobalSidebar;
type VersionTag = import('./types').VersionTag;
export type {GlobalDataVersion, GlobalDataDoc, GlobalDataSidebar}; export type NumberPrefixParser = (filename: string) => {
filename: string;
numberPrefix?: number;
};
export type EditUrlFunction = (editUrlParams: {
version: string;
versionDocsDirPath: string;
docPath: string;
permalink: string;
locale: string;
}) => string | undefined;
export type MetadataOptions = {
routeBasePath: string;
editUrl?: string | EditUrlFunction;
editCurrentVersion: boolean;
editLocalizedFiles: boolean;
showLastUpdateTime?: boolean;
showLastUpdateAuthor?: boolean;
numberPrefixParser: NumberPrefixParser;
};
export type PathOptions = {
path: string;
sidebarPath?: string | false | undefined;
};
// TODO support custom version banner? {type: "error", content: "html content"}
export type VersionBanner = 'unreleased' | 'unmaintained';
export type VersionOptions = {
path?: string;
label?: string;
banner?: 'none' | VersionBanner;
badge?: boolean;
className?: string;
};
export type VersionsOptions = {
lastVersion?: string;
versions: Record<string, VersionOptions>;
onlyIncludeVersions?: string[];
};
export type SidebarOptions = {
sidebarCollapsible: boolean;
sidebarCollapsed: boolean;
};
export type PluginOptions = MetadataOptions &
PathOptions &
VersionsOptions &
RemarkAndRehypePluginOptions &
SidebarOptions & {
id: string;
include: string[];
exclude: string[];
docLayoutComponent: string;
docItemComponent: string;
docTagDocListComponent: string;
docTagsListComponent: string;
docCategoryGeneratedIndexComponent: string;
admonitions: Record<string, unknown>;
disableVersioning: boolean;
includeCurrentVersion: boolean;
sidebarItemsGenerator: import('./sidebars/types').SidebarItemsGeneratorOption;
tagsBasePath: string;
};
export type Options = Partial<PluginOptions>;
export type SidebarsConfig = import('./sidebars/types').SidebarsConfig;
export type PropNavigationLink = { export type PropNavigationLink = {
readonly title: string; readonly title: string;
@ -241,18 +302,54 @@ declare module '@theme/Seo' {
export default Seo; export default Seo;
} }
// TODO can't we infer types directly from code? // TODO until TS supports exports field... hope it's in 4.6
declare module '@docusaurus/plugin-content-docs/client' { declare module '@docusaurus/plugin-content-docs/client' {
type GlobalPluginData = import('./types').GlobalPluginData; export type ActivePlugin = {
type GlobalVersion = import('./types').GlobalVersion; pluginId: string;
type ActivePlugin = import('./client/docsClientUtils').ActivePlugin; pluginData: GlobalPluginData;
type ActiveDocContext = import('./client/docsClientUtils').ActiveDocContext; };
type DocVersionSuggestions = export type ActiveDocContext = {
import('./client/docsClientUtils').DocVersionSuggestions; activeVersion?: GlobalVersion;
type GetActivePluginOptions = activeDoc?: GlobalDoc;
import('./client/docsClientUtils').GetActivePluginOptions; alternateDocVersions: Record<string, GlobalDoc>;
};
export type GlobalDoc = {
id: string;
path: string;
sidebar: string | undefined;
};
export type GlobalVersion = {
name: string;
label: string;
isLast: boolean;
path: string;
mainDocId: string; // home doc (if docs homepage configured), or first doc
docs: GlobalDoc[];
sidebars?: Record<string, GlobalSidebar>;
};
export type GlobalSidebarLink = {
label: string;
path: string;
};
export type GlobalSidebar = {
link?: GlobalSidebarLink;
// ... we may add other things here later
};
export type GlobalPluginData = {
path: string;
versions: GlobalVersion[];
};
export type DocVersionSuggestions = {
// suggest the latest version
latestVersionSuggestion: GlobalVersion;
// suggest the same doc, in latest version (if exist)
latestDocSuggestion?: GlobalDoc;
};
export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
export type {GlobalPluginData, GlobalVersion};
export const useAllDocsData: () => Record<string, GlobalPluginData>; export const useAllDocsData: () => Record<string, GlobalPluginData>;
export const useDocsData: (pluginId?: string) => GlobalPluginData; export const useDocsData: (pluginId?: string) => GlobalPluginData;
export const useActivePlugin: ( export const useActivePlugin: (

View file

@ -8,12 +8,13 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import importFresh from 'import-fresh'; import importFresh from 'import-fresh';
import type {SidebarsConfig, Sidebars, NormalizedSidebars} from './types'; import type {SidebarsConfig, Sidebars, NormalizedSidebars} from './types';
import type {NormalizeSidebarsParams, PluginOptions} from '../types'; import type {NormalizeSidebarsParams} from '../types';
import {validateSidebars} from './validation'; import {validateSidebars} from './validation';
import {normalizeSidebars} from './normalization'; import {normalizeSidebars} from './normalization';
import {processSidebars, type SidebarProcessorParams} from './processor'; import {processSidebars, type SidebarProcessorParams} from './processor';
import path from 'path'; import path from 'path';
import {createSlugger} from '@docusaurus/utils'; import {createSlugger} from '@docusaurus/utils';
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
export const DefaultSidebars: SidebarsConfig = { export const DefaultSidebars: SidebarsConfig = {
defaultSidebar: [ defaultSidebar: [

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {NormalizeSidebarsParams, SidebarOptions} from '../types'; import type {NormalizeSidebarsParams} from '../types';
import type { import type {
NormalizedSidebarItem, NormalizedSidebarItem,
NormalizedSidebar, NormalizedSidebar,
@ -21,6 +21,7 @@ import type {
import {isCategoriesShorthand} from './utils'; import {isCategoriesShorthand} from './utils';
import {mapValues} from 'lodash'; import {mapValues} from 'lodash';
import {normalizeUrl} from '@docusaurus/utils'; import {normalizeUrl} from '@docusaurus/utils';
import type {SidebarOptions} from '@docusaurus/plugin-content-docs';
function normalizeCategoryLink( function normalizeCategoryLink(
category: SidebarItemCategoryConfig, category: SidebarItemCategoryConfig,

View file

@ -5,12 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type { import type {DocMetadataBase, VersionMetadata} from '../types';
NumberPrefixParser,
DocMetadataBase,
VersionMetadata,
SidebarOptions,
} from '../types';
import type { import type {
Sidebars, Sidebars,
Sidebar, Sidebar,
@ -31,6 +26,10 @@ import {mapValues, memoize, pick} from 'lodash';
import combinePromises from 'combine-promises'; import combinePromises from 'combine-promises';
import {normalizeItem} from './normalization'; import {normalizeItem} from './normalization';
import type {Slugger} from '@docusaurus/utils'; import type {Slugger} from '@docusaurus/utils';
import type {
NumberPrefixParser,
SidebarOptions,
} from '@docusaurus/plugin-content-docs';
export type SidebarProcessorParams = { export type SidebarProcessorParams = {
sidebarItemsGenerator: SidebarItemsGeneratorOption; sidebarItemsGenerator: SidebarItemsGeneratorOption;

View file

@ -6,12 +6,11 @@
*/ */
import type {Optional, Required} from 'utility-types'; import type {Optional, Required} from 'utility-types';
import type {DocMetadataBase, VersionMetadata} from '../types';
import type { import type {
DocMetadataBase,
VersionMetadata,
NumberPrefixParser, NumberPrefixParser,
SidebarOptions, SidebarOptions,
} from '../types'; } from '@docusaurus/plugin-content-docs';
// Makes all properties visible when hovering over the type // Makes all properties visible when hovering over the type
type Expand<T extends Record<string, unknown>> = {[P in keyof T]: T[P]}; type Expand<T extends Record<string, unknown>> = {[P in keyof T]: T[P]};

View file

@ -15,8 +15,9 @@ import {
DefaultNumberPrefixParser, DefaultNumberPrefixParser,
stripPathNumberPrefixes, stripPathNumberPrefixes,
} from './numberPrefix'; } from './numberPrefix';
import type {DocMetadataBase, NumberPrefixParser} from './types'; import type {DocMetadataBase} from './types';
import {isConventionalDocIndex} from './docs'; import {isConventionalDocIndex} from './docs';
import type {NumberPrefixParser} from '@docusaurus/plugin-content-docs';
export default function getSlug({ export default function getSlug({
baseID, baseID,

View file

@ -7,13 +7,16 @@
/// <reference types="@docusaurus/module-type-aliases" /> /// <reference types="@docusaurus/module-type-aliases" />
import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader'; import type {Sidebars} from './sidebars/types';
import type {Tag, FrontMatterTag, Slugger} from '@docusaurus/utils'; import type {Tag, FrontMatterTag, Slugger} from '@docusaurus/utils';
import type { import type {
BrokenMarkdownLink as IBrokenMarkdownLink, BrokenMarkdownLink as IBrokenMarkdownLink,
ContentPaths, ContentPaths,
} from '@docusaurus/utils/lib/markdownLinks'; } from '@docusaurus/utils/lib/markdownLinks';
import type {SidebarItemsGeneratorOption, Sidebars} from './sidebars/types'; import type {
VersionBanner,
SidebarOptions,
} from '@docusaurus/plugin-content-docs';
export type DocFile = { export type DocFile = {
contentPath: string; // /!\ may be localized contentPath: string; // /!\ may be localized
@ -23,10 +26,8 @@ export type DocFile = {
lastUpdate: LastUpdateData; lastUpdate: LastUpdateData;
}; };
export type VersionName = string;
export type VersionMetadata = ContentPaths & { export type VersionMetadata = ContentPaths & {
versionName: VersionName; // 1.0.0 versionName: string; // 1.0.0
versionLabel: string; // Version 1.0.0 versionLabel: string; // Version 1.0.0
versionPath: string; // /baseUrl/docs/1.0.0 versionPath: string; // /baseUrl/docs/1.0.0
tagsPath: string; tagsPath: string;
@ -40,76 +41,11 @@ export type VersionMetadata = ContentPaths & {
routePriority: number | undefined; // -1 for the latest docs routePriority: number | undefined; // -1 for the latest docs
}; };
export type EditUrlFunction = (editUrlParams: {
version: string;
versionDocsDirPath: string;
docPath: string;
permalink: string;
locale: string;
}) => string | undefined;
export type MetadataOptions = {
routeBasePath: string;
editUrl?: string | EditUrlFunction;
editCurrentVersion: boolean;
editLocalizedFiles: boolean;
showLastUpdateTime?: boolean;
showLastUpdateAuthor?: boolean;
numberPrefixParser: NumberPrefixParser;
};
export type PathOptions = {
path: string;
sidebarPath?: string | false | undefined;
};
// TODO support custom version banner? {type: "error", content: "html content"}
export type VersionBanner = 'unreleased' | 'unmaintained';
export type VersionOptions = {
path?: string;
label?: string;
banner?: 'none' | VersionBanner;
badge?: boolean;
className?: string;
};
export type VersionsOptions = {
lastVersion?: string;
versions: Record<string, VersionOptions>;
onlyIncludeVersions?: string[];
};
export type SidebarOptions = {
sidebarCollapsible: boolean;
sidebarCollapsed: boolean;
};
export type NormalizeSidebarsParams = SidebarOptions & { export type NormalizeSidebarsParams = SidebarOptions & {
version: VersionMetadata; version: VersionMetadata;
categoryLabelSlugger: Slugger; categoryLabelSlugger: Slugger;
}; };
export type PluginOptions = MetadataOptions &
PathOptions &
VersionsOptions &
RemarkAndRehypePluginOptions &
SidebarOptions & {
id: string;
include: string[];
exclude: string[];
docLayoutComponent: string;
docItemComponent: string;
docTagDocListComponent: string;
docTagsListComponent: string;
docCategoryGeneratedIndexComponent: string;
admonitions: Record<string, unknown>;
disableVersioning: boolean;
includeCurrentVersion: boolean;
sidebarItemsGenerator: SidebarItemsGeneratorOption;
tagsBasePath: string;
};
export type LastUpdateData = { export type LastUpdateData = {
lastUpdatedAt?: number; lastUpdatedAt?: number;
formattedLastUpdatedAt?: string; formattedLastUpdatedAt?: string;
@ -142,7 +78,7 @@ export type DocFrontMatter = {
export type DocMetadataBase = LastUpdateData & { export type DocMetadataBase = LastUpdateData & {
id: string; // TODO legacy versioned id => try to remove id: string; // TODO legacy versioned id => try to remove
unversionedId: string; // TODO new unversioned id => try to rename to "id" unversionedId: string; // TODO new unversioned id => try to rename to "id"
version: VersionName; version: string;
title: string; title: string;
description: string; description: string;
source: string; // @site aliased source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md" source: string; // @site aliased source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
@ -203,37 +139,6 @@ export type LoadedContent = {
loadedVersions: LoadedVersion[]; loadedVersions: LoadedVersion[];
}; };
export type GlobalDoc = {
id: string;
path: string;
sidebar: string | undefined;
};
export type GlobalVersion = {
name: VersionName;
label: string;
isLast: boolean;
path: string;
mainDocId: string; // home doc (if docs homepage configured), or first doc
docs: GlobalDoc[];
sidebars?: Record<string, GlobalSidebar>;
};
export type GlobalSidebarLink = {
label: string;
path: string;
};
export type GlobalSidebar = {
link?: GlobalSidebarLink;
// ... we may add other things here later
};
export type GlobalPluginData = {
path: string;
versions: GlobalVersion[];
};
export type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>; export type BrokenMarkdownLink = IBrokenMarkdownLink<VersionMetadata>;
export type DocsMarkdownOption = { export type DocsMarkdownOption = {
@ -242,8 +147,3 @@ export type DocsMarkdownOption = {
sourceToPermalink: SourceToPermalink; sourceToPermalink: SourceToPermalink;
onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void; onBrokenMarkdownLink: (brokenMarkdownLink: BrokenMarkdownLink) => void;
}; };
export type NumberPrefixParser = (filename: string) => {
filename: string;
numberPrefix?: number;
};

View file

@ -7,19 +7,19 @@
import path from 'path'; import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import type { import type {VersionMetadata} from './types';
PluginOptions,
VersionBanner,
VersionMetadata,
VersionOptions,
VersionsOptions,
} from './types';
import { import {
VERSIONS_JSON_FILE, VERSIONS_JSON_FILE,
VERSIONED_DOCS_DIR, VERSIONED_DOCS_DIR,
VERSIONED_SIDEBARS_DIR, VERSIONED_SIDEBARS_DIR,
CURRENT_VERSION_NAME, CURRENT_VERSION_NAME,
} from './constants'; } from './constants';
import type {
PluginOptions,
VersionBanner,
VersionOptions,
VersionsOptions,
} from '@docusaurus/plugin-content-docs';
import type {LoadContext} from '@docusaurus/types'; import type {LoadContext} from '@docusaurus/types';
import { import {

View file

@ -6,7 +6,7 @@
*/ */
import {PluginOptionSchema, DEFAULT_OPTIONS} from '../pluginOptionSchema'; import {PluginOptionSchema, DEFAULT_OPTIONS} from '../pluginOptionSchema';
import type {PluginOptions} from '../types'; import type {PluginOptions} from '@docusaurus/plugin-content-pages';
export default function normalizePluginOptions( export default function normalizePluginOptions(
options: Partial<PluginOptions>, options: Partial<PluginOptions>,

View file

@ -31,12 +31,8 @@ import type {Configuration} from 'webpack';
import admonitions from 'remark-admonitions'; import admonitions from 'remark-admonitions';
import {PluginOptionSchema} from './pluginOptionSchema'; import {PluginOptionSchema} from './pluginOptionSchema';
import type { import type {LoadedContent, Metadata, PagesContentPaths} from './types';
PluginOptions, import type {PluginOptions} from '@docusaurus/plugin-content-pages';
LoadedContent,
Metadata,
PagesContentPaths,
} from './types';
export function getContentPathList(contentPaths: PagesContentPaths): string[] { export function getContentPathList(contentPaths: PagesContentPaths): string[] {
return [contentPaths.contentPathLocalized, contentPaths.contentPath]; return [contentPaths.contentPathLocalized, contentPaths.contentPath];

View file

@ -6,7 +6,19 @@
*/ */
declare module '@docusaurus/plugin-content-pages' { declare module '@docusaurus/plugin-content-pages' {
export type Options = Partial<import('./types').PluginOptions>; import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
export type PluginOptions = RemarkAndRehypePluginOptions & {
id?: string;
path: string;
routeBasePath: string;
include: string[];
exclude: string[];
mdxPageComponent: string;
admonitions: Record<string, unknown>;
};
export type Options = Partial<PluginOptions>;
} }
declare module '@theme/MDXPage' { declare module '@theme/MDXPage' {

View file

@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {PluginOptions} from './types'; import type {PluginOptions} from '@docusaurus/plugin-content-pages';
import { import {
Joi, Joi,
RemarkPluginsSchema, RemarkPluginsSchema,

View file

@ -5,18 +5,6 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
export type PluginOptions = RemarkAndRehypePluginOptions & {
id?: string;
path: string;
routeBasePath: string;
include: string[];
exclude: string[];
mdxPageComponent: string;
admonitions: Record<string, unknown>;
};
export type JSXPageMetadata = { export type JSXPageMetadata = {
type: 'jsx'; type: 'jsx';
permalink: string; permalink: string;

View file

@ -27,6 +27,7 @@
"@docusaurus/plugin-google-gtag": "2.0.0-beta.14", "@docusaurus/plugin-google-gtag": "2.0.0-beta.14",
"@docusaurus/plugin-sitemap": "2.0.0-beta.14", "@docusaurus/plugin-sitemap": "2.0.0-beta.14",
"@docusaurus/theme-classic": "2.0.0-beta.14", "@docusaurus/theme-classic": "2.0.0-beta.14",
"@docusaurus/theme-common": "2.0.0-beta.14",
"@docusaurus/theme-search-algolia": "2.0.0-beta.14" "@docusaurus/theme-search-algolia": "2.0.0-beta.14"
}, },
"peerDependencies": { "peerDependencies": {

View file

@ -5,18 +5,28 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import type {Options as DocsPluginOptions} from '@docusaurus/plugin-content-docs';
import type {Options as BlogPluginOptions} from '@docusaurus/plugin-content-blog';
import type {Options as PagesPluginOptions} from '@docusaurus/plugin-content-pages';
import type {Options as SitemapPluginOptions} from '@docusaurus/plugin-sitemap';
import type {Options as GAPluginOptions} from '@docusaurus/plugin-google-analytics';
import type {Options as GtagPluginOptions} from '@docusaurus/plugin-google-gtag';
import type {Options as ThemeOptions} from '@docusaurus/theme-classic';
import type {ThemeConfig as BaseThemeConfig} from '@docusaurus/types';
import type {UserThemeConfig as ClassicThemeConfig} from '@docusaurus/theme-common';
import type {UserThemeConfig as AlgoliaThemeConfig} from '@docusaurus/theme-search-algolia';
export type Options = { export type Options = {
debug?: boolean; debug?: boolean;
docs?: false | import('@docusaurus/plugin-content-docs').Options; docs?: false | DocsPluginOptions;
blog?: false | import('@docusaurus/plugin-content-blog').Options; blog?: false | BlogPluginOptions;
pages?: false | import('@docusaurus/plugin-content-pages').Options; pages?: false | PagesPluginOptions;
sitemap?: false | import('@docusaurus/plugin-sitemap').Options; sitemap?: false | SitemapPluginOptions;
theme?: import('@docusaurus/theme-classic').Options; theme?: ThemeOptions;
googleAnalytics?: import('@docusaurus/plugin-google-analytics').Options; googleAnalytics?: GAPluginOptions;
gtag?: import('@docusaurus/plugin-google-gtag').Options; gtag?: GtagPluginOptions;
}; };
export type ThemeConfig = import('@docusaurus/types').ThemeConfig & export type ThemeConfig = BaseThemeConfig &
import('@docusaurus/theme-common').UserThemeConfig & { ClassicThemeConfig &
algolia?: unknown; // TODO type plugin AlgoliaThemeConfig;
};

View file

@ -44,7 +44,8 @@ declare module '@theme/BlogListPaginator' {
} }
declare module '@theme/BlogPostItem' { declare module '@theme/BlogPostItem' {
import type {FrontMatter, Assets, Metadata} from '@theme/BlogPostPage'; import type {FrontMatter, Metadata} from '@theme/BlogPostPage';
import type {Assets} from '@docusaurus/plugin-content-blog';
export interface Props { export interface Props {
readonly frontMatter: FrontMatter; readonly frontMatter: FrontMatter;
@ -70,7 +71,8 @@ declare module '@theme/BlogPostAuthor' {
} }
declare module '@theme/BlogPostAuthors' { declare module '@theme/BlogPostAuthors' {
import type {Metadata, Assets} from '@theme/BlogPostPage'; import type {Metadata} from '@theme/BlogPostPage';
import type {Assets} from '@docusaurus/plugin-content-blog';
export interface Props { export interface Props {
readonly authors: Metadata['authors']; readonly authors: Metadata['authors'];

View file

@ -15,9 +15,9 @@ import clsx from 'clsx';
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils'; import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
import type {Props} from '@theme/NavbarItem/DocNavbarItem'; import type {Props} from '@theme/NavbarItem/DocNavbarItem';
import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common'; import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs'; import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
function getDocInVersions(versions: GlobalDataVersion[], docId: string) { function getDocInVersions(versions: GlobalVersion[], docId: string) {
const allDocs = versions.flatMap((version) => version.docs); const allDocs = versions.flatMap((version) => version.docs);
const doc = allDocs.find((versionDoc) => versionDoc.id === docId); const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
if (!doc) { if (!doc) {
@ -46,7 +46,7 @@ export default function DocNavbarItem({
const versions = uniq( const versions = uniq(
[activeVersion, preferredVersion, latestVersion].filter( [activeVersion, preferredVersion, latestVersion].filter(
Boolean, Boolean,
) as GlobalDataVersion[], ) as GlobalVersion[],
); );
const doc = getDocInVersions(versions, docId); const doc = getDocInVersions(versions, docId);
const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile); const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);

View file

@ -17,11 +17,11 @@ import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem'; import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem';
import type { import type {
GlobalDataVersion, GlobalVersion,
GlobalDataSidebar, GlobalSidebar,
} from '@docusaurus/plugin-content-docs'; } from '@docusaurus/plugin-content-docs/client';
function getSidebarLink(versions: GlobalDataVersion[], sidebarId: string) { function getSidebarLink(versions: GlobalVersion[], sidebarId: string) {
const allSidebars = versions const allSidebars = versions
.flatMap((version) => { .flatMap((version) => {
if (version.sidebars) { if (version.sidebars) {
@ -30,8 +30,7 @@ function getSidebarLink(versions: GlobalDataVersion[], sidebarId: string) {
return undefined; return undefined;
}) })
.filter( .filter(
(sidebarItem): sidebarItem is [string, GlobalDataSidebar] => (sidebarItem): sidebarItem is [string, GlobalSidebar] => !!sidebarItem,
!!sidebarItem,
); );
const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId); const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
if (!sidebarEntry) { if (!sidebarEntry) {
@ -65,7 +64,7 @@ export default function DocSidebarNavbarItem({
const versions = uniq( const versions = uniq(
[activeVersion, preferredVersion, latestVersion].filter( [activeVersion, preferredVersion, latestVersion].filter(
Boolean, Boolean,
) as GlobalDataVersion[], ) as GlobalVersion[],
); );
const sidebarLink = getSidebarLink(versions, sidebarId); const sidebarLink = getSidebarLink(versions, sidebarId);
const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile); const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);

View file

@ -16,9 +16,9 @@ import {
import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem'; import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
import {useDocsPreferredVersion} from '@docusaurus/theme-common'; import {useDocsPreferredVersion} from '@docusaurus/theme-common';
import {translate} from '@docusaurus/Translate'; import {translate} from '@docusaurus/Translate';
import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs'; import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
const getVersionMainDoc = (version: GlobalDataVersion) => const getVersionMainDoc = (version: GlobalVersion) =>
version.docs.find((doc) => doc.id === version.mainDocId)!; version.docs.find((doc) => doc.id === version.mainDocId)!;
export default function DocsVersionDropdownNavbarItem({ export default function DocsVersionDropdownNavbarItem({

View file

@ -36,7 +36,8 @@
"clsx": "^1.1.1", "clsx": "^1.1.1",
"eta": "^1.12.3", "eta": "^1.12.3",
"lodash": "^4.17.20", "lodash": "^4.17.20",
"tslib": "^2.3.1" "tslib": "^2.3.1",
"utility-types": "^3.10.0"
}, },
"devDependencies": { "devDependencies": {
"@docusaurus/module-type-aliases": "2.0.0-beta.14", "@docusaurus/module-type-aliases": "2.0.0-beta.14",

View file

@ -5,6 +5,22 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
declare module '@docusaurus/theme-search-algolia' {
import type {DeepPartial} from 'utility-types';
export type ThemeConfig = {
algolia: {
contextualSearch: boolean;
externalUrlRegex?: string;
appId: string;
apiKey: string;
indexName: string;
searchParameters: Record<string, unknown>;
};
};
export type UserThemeConfig = DeepPartial<ThemeConfig>;
}
declare module '@docusaurus/theme-search-algolia/client' { declare module '@docusaurus/theme-search-algolia/client' {
export function useAlgoliaContextualFacetFilters(): [string, string[]]; export function useAlgoliaContextualFacetFilters(): [string, string[]];
} }
@ -14,17 +30,6 @@ declare module '@theme/SearchPage' {
export default SearchPage; export default SearchPage;
} }
declare module '@theme/SearchMetadata' {
export type SearchMetadataProps = {
readonly locale?: string;
readonly version?: string;
readonly tag?: string;
};
const SearchMetadata: (props: SearchMetadataProps) => JSX.Element;
export default SearchMetadata;
}
declare module '@theme/SearchBar' { declare module '@theme/SearchBar' {
const SearchBar: () => JSX.Element; const SearchBar: () => JSX.Element;
export default SearchBar; export default SearchBar;

View file

@ -8,14 +8,10 @@
import React from 'react'; import React from 'react';
import Head from '@docusaurus/Head'; import Head from '@docusaurus/Head';
import type {SearchMetadataProps} from '@theme/SearchMetadata'; import type {Props} from '@theme/SearchMetadata';
// Override default/agnostic SearchMetas to use Algolia-specific metadata // Override default/agnostic SearchMetas to use Algolia-specific metadata
function SearchMetadata({ function SearchMetadata({locale, version, tag}: Props): JSX.Element {
locale,
version,
tag,
}: SearchMetadataProps): JSX.Element {
// Seems safe to consider here the locale is the language, // Seems safe to consider here the locale is the language,
// as the existing docsearch:language filter is afaik a regular string-based filter // as the existing docsearch:language filter is afaik a regular string-based filter
const language = locale; const language = locale;