mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 13:37:05 +02:00
refactor: fix a lot of errors in type-aware linting (#7477)
This commit is contained in:
parent
222bf3c091
commit
bf1513a3e3
120 changed files with 407 additions and 364 deletions
|
@ -89,6 +89,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
|
|||
},
|
||||
readingTime: ({content, defaultReadingTime}) =>
|
||||
defaultReadingTime({content}),
|
||||
truncateMarker: /<!--\s*truncate\s*-->/,
|
||||
} as PluginOptions,
|
||||
);
|
||||
|
||||
|
@ -128,6 +129,7 @@ describe.each(['atom', 'rss', 'json'])('%s', (feedType) => {
|
|||
},
|
||||
readingTime: ({content, defaultReadingTime}) =>
|
||||
defaultReadingTime({content}),
|
||||
truncateMarker: /<!--\s*truncate\s*-->/,
|
||||
} as PluginOptions,
|
||||
);
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ const getPlugin = async (
|
|||
editUrl: BaseEditUrl,
|
||||
...pluginOptions,
|
||||
},
|
||||
}) as PluginOptions,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ function getSampleTranslationFilesTranslated() {
|
|||
}
|
||||
|
||||
describe('getContentTranslationFiles', () => {
|
||||
it('returns translation files matching snapshot', async () => {
|
||||
it('returns translation files matching snapshot', () => {
|
||||
expect(getSampleTranslationFiles()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -44,7 +44,11 @@ const AuthorsMapSchema = Joi.object<AuthorsMap>()
|
|||
});
|
||||
|
||||
export function validateAuthorsMap(content: unknown): AuthorsMap {
|
||||
return Joi.attempt(content, AuthorsMapSchema);
|
||||
const {error, value} = AuthorsMapSchema.validate(content);
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export async function getAuthorsMap(params: {
|
||||
|
|
|
@ -264,7 +264,7 @@ async function processBlogSourceFile(
|
|||
const title = frontMatter.title ?? contentTitle ?? parsedBlogFileName.text;
|
||||
const description = frontMatter.description ?? excerpt ?? '';
|
||||
|
||||
const slug = frontMatter.slug || parsedBlogFileName.slug;
|
||||
const slug = frontMatter.slug ?? parsedBlogFileName.slug;
|
||||
|
||||
const permalink = normalizeUrl([baseUrl, routeBasePath, slug]);
|
||||
|
||||
|
@ -323,7 +323,7 @@ async function processBlogSourceFile(
|
|||
defaultReadingTime,
|
||||
})
|
||||
: undefined,
|
||||
truncated: truncateMarker?.test(content) || false,
|
||||
truncated: truncateMarker.test(content),
|
||||
authors,
|
||||
frontMatter,
|
||||
},
|
||||
|
|
|
@ -176,10 +176,6 @@ export default async function pluginContentBlog(
|
|||
},
|
||||
|
||||
async contentLoaded({content: blogContents, actions}) {
|
||||
if (!blogContents) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
blogListComponent,
|
||||
blogPostComponent,
|
||||
|
@ -500,11 +496,7 @@ export default async function pluginContentBlog(
|
|||
},
|
||||
|
||||
injectHtmlTags({content}) {
|
||||
if (!content.blogPosts.length) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!options.feedOptions?.type) {
|
||||
if (!content.blogPosts.length || !options.feedOptions.type) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -34,5 +34,5 @@ export default function markdownLoader(
|
|||
finalContent = truncate(finalContent, markdownLoaderOptions.truncateMarker);
|
||||
}
|
||||
|
||||
return callback?.(null, finalContent);
|
||||
return callback(null, finalContent);
|
||||
}
|
||||
|
|
|
@ -136,9 +136,6 @@ export function validateOptions({
|
|||
validate,
|
||||
options,
|
||||
}: OptionValidationContext<Options, PluginOptions>): PluginOptions {
|
||||
const validatedOptions = validate(
|
||||
PluginOptionSchema,
|
||||
options,
|
||||
) as PluginOptions;
|
||||
const validatedOptions = validate(PluginOptionSchema, options);
|
||||
return validatedOptions;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue