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