From 257564e051b39d642b77d29e5856b4fbfe340c1c Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Thu, 16 May 2024 15:47:59 +0200 Subject: [PATCH] wip --- packages/docusaurus-plugin-content-docs/src/docs.ts | 13 ++++++++++--- .../docusaurus-plugin-content-docs/src/options.ts | 11 +++++++---- .../src/plugin-content-docs.d.ts | 4 ++-- packages/docusaurus-plugin-content-docs/src/tags.ts | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 0145a58bee54..6af3b3b0a53e 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -87,7 +87,10 @@ async function getDefinedTags( options: MetadataOptions, contentPath: string, ): Promise { - const tagDefinitionPath = path.join(contentPath, options.tagsFilePath); + const tagDefinitionPath = path.join( + contentPath, + options.tagsFilePath ? options.tagsFilePath : 'tags.yml', + ); const tagDefinitionContent = await fs.readFile(tagDefinitionPath, 'utf-8'); const data = YAML.load(tagDefinitionContent); const definedTags = validateDefinedTags(data); @@ -113,7 +116,11 @@ export async function processFileTagsPath({ frontMatterTags: FrontMatterTag[] | undefined; versionTagsPath: string; }): Promise { - if (!options.tagsFilePath || options.onBrokenTags === 'ignore') { + if ( + options.tagsFilePath === false || + options.tagsFilePath === null || + options.onUnknownTags === 'ignore' + ) { return normalizeFrontMatterTags(versionTagsPath, frontMatterTags); } @@ -123,7 +130,7 @@ export async function processFileTagsPath({ frontMatterTags, validTagsSchema, source, - onBrokenTags: options.onBrokenTags, + onBrokenTags: options.onUnknownTags, }); const transformedTags = Object.entries(definedTags).map(([key, value]) => ({ label: value.label, diff --git a/packages/docusaurus-plugin-content-docs/src/options.ts b/packages/docusaurus-plugin-content-docs/src/options.ts index f2f4b43fa4c8..18180fc1948c 100644 --- a/packages/docusaurus-plugin-content-docs/src/options.ts +++ b/packages/docusaurus-plugin-content-docs/src/options.ts @@ -54,8 +54,8 @@ export const DEFAULT_OPTIONS: Omit = { sidebarCollapsible: true, sidebarCollapsed: true, breadcrumbs: true, - onBrokenTags: 'warn', - tagsFilePath: '', + onUnknownTags: 'warn', + tagsFilePath: 'tags.yml', }; const VersionOptionsSchema = Joi.object({ @@ -144,8 +144,11 @@ const OptionsSchema = Joi.object({ breadcrumbs: Joi.bool().default(DEFAULT_OPTIONS.breadcrumbs), onBrokenTags: Joi.string() .equal('ignore', 'log', 'warn', 'throw') - .default(DEFAULT_OPTIONS.onBrokenTags), - tagsFilePath: Joi.string().default(DEFAULT_OPTIONS.tagsFilePath), + .default(DEFAULT_OPTIONS.onUnknownTags), + tagsFilePath: Joi.string() + .allow(null, false, undefined) + .disallow('') + .default(DEFAULT_OPTIONS.tagsFilePath), }); export function validateOptions({ diff --git a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts index 3ff7a998fa4c..6c09758a5c40 100644 --- a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts +++ b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts @@ -101,8 +101,8 @@ declare module '@docusaurus/plugin-content-docs' { numberPrefixParser: NumberPrefixParser; /** Enable or disable the breadcrumbs on doc pages. */ breadcrumbs: boolean; - tagsFilePath: string; - onBrokenTags: 'ignore' | 'log' | 'warn' | 'throw'; + tagsFilePath: string | null | undefined | false; + onUnknownTags: 'ignore' | 'log' | 'warn' | 'throw'; }; export type PathOptions = { diff --git a/packages/docusaurus-plugin-content-docs/src/tags.ts b/packages/docusaurus-plugin-content-docs/src/tags.ts index b74bcbf38573..388e8c963763 100644 --- a/packages/docusaurus-plugin-content-docs/src/tags.ts +++ b/packages/docusaurus-plugin-content-docs/src/tags.ts @@ -57,7 +57,7 @@ export function validateFrontMatterTags({ frontMatterTags: FrontMatterTag[] | undefined; validTagsSchema: Joi.Schema; source: string; - onBrokenTags: MetadataOptions['onBrokenTags']; + onBrokenTags: MetadataOptions['onUnknownTags']; }): void { if (frontMatterTags === undefined || !Array.isArray(frontMatterTags)) { return;