misc: replace all "Metadatas" with "Metadata" (#5871)

Co-authored-by: Josh-Cena <sidachen2003@gmail.com>
This commit is contained in:
Swalah Amani 2021-11-10 00:16:10 +05:30 committed by GitHub
parent eab8c7c010
commit c541e2d83c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 107 additions and 106 deletions

View file

@ -5,10 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import {
CategoryMetadatasFile,
DefaultSidebarItemsGenerator,
} from '../generator';
import {CategoryMetadataFile, DefaultSidebarItemsGenerator} from '../generator';
import {Sidebar, SidebarItemsGenerator} from '../types';
import fs from 'fs-extra';
import {DefaultNumberPrefixParser} from '../../numberPrefix';
@ -37,7 +34,7 @@ describe('DefaultSidebarItemsGenerator', () => {
}
function mockCategoryMetadataFiles(
categoryMetadataFiles: Record<string, Partial<CategoryMetadatasFile>>,
categoryMetadataFiles: Record<string, Partial<CategoryMetadataFile>>,
) {
jest.spyOn(fs, 'pathExists').mockImplementation((metadataFilePath) => {
return typeof categoryMetadataFiles[metadataFilePath] !== 'undefined';

View file

@ -27,7 +27,7 @@ const docIdPrefix = '$doc$/';
export const CategoryMetadataFilenameBase = '_category_';
export const CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';
export type CategoryMetadatasFile = {
export type CategoryMetadataFile = {
label?: string;
position?: number;
collapsed?: boolean;
@ -50,7 +50,7 @@ type Dir = {
[item: string]: Dir | null;
};
const CategoryMetadatasFileSchema = Joi.object<CategoryMetadatasFile>({
const CategoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
label: Joi.string(),
position: Joi.number(),
collapsed: Joi.boolean(),
@ -62,14 +62,14 @@ const CategoryMetadatasFileSchema = Joi.object<CategoryMetadatasFile>({
// Example use-case being able to disable number prefix parsing at the folder level, or customize the default route path segment for an intermediate directory...
// TODO later if there is `CategoryFolder/index.md`, we may want to read the metadata as yaml on it
// see https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
async function readCategoryMetadatasFile(
async function readCategoryMetadataFile(
categoryDirPath: string,
): Promise<CategoryMetadatasFile | null> {
async function tryReadFile(filePath: string): Promise<CategoryMetadatasFile> {
): Promise<CategoryMetadataFile | null> {
async function tryReadFile(filePath: string): Promise<CategoryMetadataFile> {
const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
const unsafeContent = Yaml.load(contentString);
try {
return Joi.attempt(unsafeContent, CategoryMetadatasFileSchema);
return Joi.attempt(unsafeContent, CategoryMetadataFileSchema);
} catch (e) {
console.error(
chalk.red(
@ -81,7 +81,7 @@ async function readCategoryMetadatasFile(
}
// eslint-disable-next-line no-restricted-syntax
for (const ext of ['.json', '.yml', '.yaml']) {
// Simpler to use only posix paths for mocking file metadatas in tests
// Simpler to use only posix paths for mocking file metadata in tests
const filePath = posixPath(
path.join(categoryDirPath, `${CategoryMetadataFilenameBase}${ext}`),
);
@ -184,16 +184,16 @@ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
folderName: string,
): Promise<WithPosition<SidebarItemCategory>> {
const categoryPath = path.join(version.contentPath, autogenDir, fullPath);
const categoryMetadatas = await readCategoryMetadatasFile(categoryPath);
const className = categoryMetadatas?.className;
const categoryMetadata = await readCategoryMetadataFile(categoryPath);
const className = categoryMetadata?.className;
const {filename, numberPrefix} = numberPrefixParser(folderName);
return {
type: 'category',
label: categoryMetadatas?.label ?? filename,
label: categoryMetadata?.label ?? filename,
collapsible:
categoryMetadatas?.collapsible ?? options.sidebarCollapsible,
collapsed: categoryMetadatas?.collapsed ?? options.sidebarCollapsed,
position: categoryMetadatas?.position ?? numberPrefix,
categoryMetadata?.collapsible ?? options.sidebarCollapsible,
collapsed: categoryMetadata?.collapsed ?? options.sidebarCollapsed,
position: categoryMetadata?.position ?? numberPrefix,
...(className !== undefined && {className}),
items: await Promise.all(
Object.entries(dir).map(([key, content]) =>

View file

@ -124,8 +124,8 @@ export type PropSidebars = {
};
// Reduce API surface for options.sidebarItemsGenerator
// The user-provided generator fn should receive only a subset of metadatas
// A change to any of these metadatas can be considered as a breaking change
// The user-provided generator fn should receive only a subset of metadata
// A change to any of these metadata can be considered as a breaking change
export type SidebarItemsGeneratorDoc = Pick<
DocMetadataBase,
'id' | 'frontMatter' | 'source' | 'sourceDirName' | 'sidebarPosition'