Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed May 16, 2024
1 parent 72cc7ad commit 257564e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 10 additions & 3 deletions packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ async function getDefinedTags(
options: MetadataOptions,
contentPath: string,
): Promise<Tag[]> {
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);
Expand All @@ -113,7 +116,11 @@ export async function processFileTagsPath({
frontMatterTags: FrontMatterTag[] | undefined;
versionTagsPath: string;
}): Promise<Tag[]> {
if (!options.tagsFilePath || options.onBrokenTags === 'ignore') {
if (
options.tagsFilePath === false ||
options.tagsFilePath === null ||
options.onUnknownTags === 'ignore'
) {
return normalizeFrontMatterTags(versionTagsPath, frontMatterTags);
}

Expand All @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions packages/docusaurus-plugin-content-docs/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
sidebarCollapsible: true,
sidebarCollapsed: true,
breadcrumbs: true,
onBrokenTags: 'warn',
tagsFilePath: '',
onUnknownTags: 'warn',
tagsFilePath: 'tags.yml',
};

const VersionOptionsSchema = Joi.object({
Expand Down Expand Up @@ -144,8 +144,11 @@ const OptionsSchema = Joi.object<PluginOptions>({
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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function validateFrontMatterTags({
frontMatterTags: FrontMatterTag[] | undefined;
validTagsSchema: Joi.Schema<string[]>;
source: string;
onBrokenTags: MetadataOptions['onBrokenTags'];
onBrokenTags: MetadataOptions['onUnknownTags'];
}): void {
if (frontMatterTags === undefined || !Array.isArray(frontMatterTags)) {
return;
Expand Down

0 comments on commit 257564e

Please sign in to comment.