From 72cc7ad58cf702f5e5e9989eba53643f0bde21c5 Mon Sep 17 00:00:00 2001 From: ozakione <29860391+OzakIOne@users.noreply.github.com> Date: Wed, 15 May 2024 16:42:05 +0200 Subject: [PATCH] better naming --- .../src/docs.ts | 26 +++++++++++-------- .../src/tags.ts | 6 ++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index fef4fdc06fb3..0145a58bee54 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -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, @@ -79,21 +83,21 @@ export async function readVersionDocs( export type DocEnv = 'production' | 'development'; -async function getTagDefinition( +async function getDefinedTags( options: MetadataOptions, contentPath: string, ): Promise { - 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({ @@ -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, diff --git a/packages/docusaurus-plugin-content-docs/src/tags.ts b/packages/docusaurus-plugin-content-docs/src/tags.ts index a9e58e4a0e5d..b74bcbf38573 100644 --- a/packages/docusaurus-plugin-content-docs/src/tags.ts +++ b/packages/docusaurus-plugin-content-docs/src/tags.ts @@ -32,7 +32,7 @@ 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(), @@ -40,8 +40,8 @@ export const tagSchema = Joi.object().pattern( }), ); -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 {