mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 04:42:40 +02:00
move schema creation outside of loadcontent
This commit is contained in:
parent
d9885dbdbb
commit
9eab6aecfe
2 changed files with 14 additions and 14 deletions
|
@ -13,7 +13,7 @@ import {
|
|||
Globby,
|
||||
} from '@docusaurus/utils';
|
||||
import Yaml from 'js-yaml';
|
||||
import {validateShowcaseItem} from './validation';
|
||||
import {createShowcaseItemSchema, validateShowcaseItem} from './validation';
|
||||
import {getTagsList} from './tags';
|
||||
import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||
import type {
|
||||
|
@ -28,10 +28,10 @@ export function getContentPathList(
|
|||
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
||||
}
|
||||
|
||||
export default function pluginContentShowcase(
|
||||
export default async function pluginContentShowcase(
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
): Plugin<ShowcaseItems | null> {
|
||||
): Promise<Plugin<ShowcaseItems | null>> {
|
||||
const {siteDir, localizationDir} = context;
|
||||
// todo check for better naming of path: sitePath
|
||||
const {include, exclude, tags, routeBasePath, path: sitePath} = options;
|
||||
|
@ -45,6 +45,13 @@ export default function pluginContentShowcase(
|
|||
}),
|
||||
};
|
||||
|
||||
const tagList = await getTagsList({
|
||||
configTags: tags,
|
||||
configPath: contentPaths.contentPath,
|
||||
});
|
||||
|
||||
const showcaseItemSchema = createShowcaseItemSchema(tagList);
|
||||
|
||||
return {
|
||||
name: 'docusaurus-plugin-content-showcase',
|
||||
|
||||
|
@ -68,11 +75,6 @@ export default function pluginContentShowcase(
|
|||
ignore: [...exclude],
|
||||
});
|
||||
|
||||
const tagList = await getTagsList({
|
||||
configTags: tags,
|
||||
configPath: contentPaths.contentPath,
|
||||
});
|
||||
|
||||
async function processShowcaseSourceFile(relativeSource: string) {
|
||||
// Lookup in localized folder in priority
|
||||
const contentPath = await getFolderContainingFile(
|
||||
|
@ -85,7 +87,7 @@ export default function pluginContentShowcase(
|
|||
const item = Yaml.load(data);
|
||||
const showcaseItem = validateShowcaseItem({
|
||||
item,
|
||||
tags: tagList,
|
||||
showcaseItemSchema,
|
||||
});
|
||||
|
||||
return showcaseItem;
|
||||
|
|
|
@ -9,7 +9,7 @@ import {Joi, validateFrontMatter} from '@docusaurus/utils-validation';
|
|||
import {createTagSchema} from './tags';
|
||||
import type {ShowcaseItem} from '@docusaurus/plugin-content-showcase';
|
||||
|
||||
const createShowcaseItemSchema = (tags: string[]) => {
|
||||
export const createShowcaseItemSchema = (tags: string[]): Joi.ObjectSchema => {
|
||||
const tagsSchema = createTagSchema(tags);
|
||||
|
||||
return Joi.object({
|
||||
|
@ -24,12 +24,10 @@ const createShowcaseItemSchema = (tags: string[]) => {
|
|||
|
||||
export function validateShowcaseItem({
|
||||
item,
|
||||
tags,
|
||||
showcaseItemSchema,
|
||||
}: {
|
||||
item: unknown;
|
||||
tags: string[];
|
||||
showcaseItemSchema: Joi.ObjectSchema;
|
||||
}): ShowcaseItem {
|
||||
const showcaseItemSchema = createShowcaseItemSchema(tags);
|
||||
|
||||
return validateFrontMatter(item, showcaseItemSchema);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue