Skip to content

Commit

Permalink
better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
OzakIOne committed May 15, 2024
1 parent 335cbeb commit 72cc7ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {validateDocFrontMatter} from './frontMatter';
import getSlug from './slug';
import {stripPathNumberPrefixes} from './numberPrefix';
import {toDocNavigationLink, toNavigationLink} from './sidebars/utils';
import {createTagSchema, validateFrontMatterTags, validateTags} from './tags';
import {
createTagSchema,
validateFrontMatterTags,
validateDefinedTags,
} from './tags';
import type {FrontMatterTag, Tag} from '@docusaurus/utils';
import type {
MetadataOptions,
Expand Down Expand Up @@ -79,21 +83,21 @@ export async function readVersionDocs(

export type DocEnv = 'production' | 'development';

async function getTagDefinition(
async function getDefinedTags(
options: MetadataOptions,
contentPath: string,
): Promise<Tag[]> {
const tagsPath = path.join(contentPath, options.tagsFilePath);
const tagsFileContent = await fs.readFile(tagsPath, 'utf-8');
const data = YAML.load(tagsFileContent);
const tags = validateTags(data);
if (tags.error) {
const tagDefinitionPath = path.join(contentPath, options.tagsFilePath);
const tagDefinitionContent = await fs.readFile(tagDefinitionPath, 'utf-8');
const data = YAML.load(tagDefinitionContent);
const definedTags = validateDefinedTags(data);
if (definedTags.error) {
throw new Error(
`There was an error extracting tags from file: ${tags.error.message}`,
{cause: tags},
`There was an error extracting tags from file: ${definedTags.error.message}`,
{cause: definedTags},
);
}
return tags.value;
return definedTags.value;
}

export async function processFileTagsPath({
Expand All @@ -113,7 +117,7 @@ export async function processFileTagsPath({
return normalizeFrontMatterTags(versionTagsPath, frontMatterTags);
}

const definedTags = await getTagDefinition(options, contentPath);
const definedTags = await getDefinedTags(options, contentPath);
const validTagsSchema = createTagSchema(Object.keys(definedTags));
validateFrontMatterTags({
frontMatterTags,
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-plugin-content-docs/src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export function getVersionTags(docs: DocMetadata[]): VersionTags {
});
}

export const tagSchema = Joi.object().pattern(
export const tagDefinitionSchema = Joi.object().pattern(
Joi.string(),
Joi.object({
label: Joi.string().required(),
description: Joi.string().required(),
}),
);

export function validateTags(tags: unknown): Joi.ValidationResult {
return tagSchema.validate(tags);
export function validateDefinedTags(tags: unknown): Joi.ValidationResult {
return tagDefinitionSchema.validate(tags);
}

export function createTagSchema(tags: string[]): Joi.Schema {
Expand Down

0 comments on commit 72cc7ad

Please sign in to comment.