mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 12:37:01 +02:00
refactor(v2): use correct plugin types (#4418)
This commit is contained in:
parent
1078341b22
commit
abae86f283
11 changed files with 69 additions and 80 deletions
|
@ -42,7 +42,6 @@ import {PermalinkToSidebar} from '@docusaurus/plugin-content-docs-types';
|
|||
import {RuleSetRule} from 'webpack';
|
||||
import {cliDocsVersionCommand} from './cli';
|
||||
import {VERSIONS_JSON_FILE} from './constants';
|
||||
import {OptionsSchema} from './options';
|
||||
import {flatten, keyBy, compact} from 'lodash';
|
||||
import {toGlobalDataVersion} from './globalData';
|
||||
import {toVersionMetadataProp} from './props';
|
||||
|
@ -54,7 +53,7 @@ import {
|
|||
export default function pluginContentDocs(
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
): Plugin<LoadedContent, typeof OptionsSchema> {
|
||||
): Plugin<LoadedContent> {
|
||||
const {siteDir, generatedFilesDir, baseUrl, siteConfig} = context;
|
||||
|
||||
const versionsMetadata = readVersionsMetadata({context, options});
|
||||
|
|
|
@ -13,7 +13,6 @@ import {
|
|||
URISchema,
|
||||
} from '@docusaurus/utils-validation';
|
||||
import {OptionValidationContext, ValidationResult} from '@docusaurus/types';
|
||||
import {ValidationError} from 'joi';
|
||||
import chalk from 'chalk';
|
||||
import admonitions from 'remark-admonitions';
|
||||
|
||||
|
@ -89,14 +88,10 @@ export const OptionsSchema = Joi.object({
|
|||
versions: VersionsOptionsSchema,
|
||||
});
|
||||
|
||||
// TODO bad validation function types
|
||||
export function validateOptions({
|
||||
validate,
|
||||
options,
|
||||
}: OptionValidationContext<PluginOptions, ValidationError>): ValidationResult<
|
||||
PluginOptions,
|
||||
ValidationError
|
||||
> {
|
||||
}: OptionValidationContext<PluginOptions>): ValidationResult<PluginOptions> {
|
||||
// TODO remove homePageId before end of 2020
|
||||
// "slug: /" is better because the home doc can be different across versions
|
||||
if (options.homePageId) {
|
||||
|
@ -118,8 +113,7 @@ export function validateOptions({
|
|||
options.includeCurrentVersion = !options.excludeNextVersionDocs;
|
||||
}
|
||||
|
||||
// @ts-expect-error: TODO bad OptionValidationContext, need refactor
|
||||
const normalizedOptions: PluginOptions = validate(OptionsSchema, options);
|
||||
const normalizedOptions = validate(OptionsSchema, options);
|
||||
|
||||
if (normalizedOptions.admonitions) {
|
||||
normalizedOptions.remarkPlugins = normalizedOptions.remarkPlugins.concat([
|
||||
|
@ -127,6 +121,5 @@ export function validateOptions({
|
|||
]);
|
||||
}
|
||||
|
||||
// @ts-expect-error: TODO bad OptionValidationContext, need refactor
|
||||
return normalizedOptions;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue