Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A new document is now available at `http://localhost:3000/docs/hello`.

Docusaurus automatically **creates a sidebar** from the `docs` folder.

Add metadatas to customize the sidebar label and position:
Add metadata to customize the sidebar label and position:

```md title="docs/hello.md" {1-4}
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A new document is now available at `http://localhost:3000/docs/hello`.

Docusaurus automatically **creates a sidebar** from the `docs` folder.

Add metadatas to customize the sidebar label and position:
Add metadata to customize the sidebar label and position:

```md title="docs/hello.md" {1-4}
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A new document is now available at `http://localhost:3000/docs/hello`.

Docusaurus automatically **creates a sidebar** from the `docs` folder.

Add metadatas to customize the sidebar label and position:
Add metadata to customize the sidebar label and position:

```md title="docs/hello.md" {1-4}
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A new document is now available at `http://localhost:3000/docs/hello`.

Docusaurus automatically **creates a sidebar** from the `docs` folder.

Add metadatas to customize the sidebar label and position:
Add metadata to customize the sidebar label and position:

```md title="docs/hello.md" {1-4}
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`toRedirectFilesMetadata should create appropriate metadatas for empty baseUrl: fileContent baseUrl=empty 1`] = `
exports[`toRedirectFilesMetadata should create appropriate metadata for empty baseUrl: fileContent baseUrl=empty 1`] = `
Array [
"<!DOCTYPE html>
<html>
Expand All @@ -16,7 +16,7 @@ Array [
]
`;

exports[`toRedirectFilesMetadata should create appropriate metadatas for root baseUrl: fileContent baseUrl=/ 1`] = `
exports[`toRedirectFilesMetadata should create appropriate metadata for root baseUrl: fileContent baseUrl=/ 1`] = `
Array [
"<!DOCTYPE html>
<html>
Expand All @@ -32,7 +32,7 @@ Array [
]
`;

exports[`toRedirectFilesMetadata should create appropriate metadatas trailingSlash=false: fileContent 1`] = `
exports[`toRedirectFilesMetadata should create appropriate metadata trailingSlash=false: fileContent 1`] = `
Array [
"<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -70,7 +70,7 @@ Array [
]
`;

exports[`toRedirectFilesMetadata should create appropriate metadatas trailingSlash=true: fileContent 1`] = `
exports[`toRedirectFilesMetadata should create appropriate metadata trailingSlash=true: fileContent 1`] = `
Array [
"<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -108,7 +108,7 @@ Array [
]
`;

exports[`toRedirectFilesMetadata should create appropriate metadatas trailingSlash=undefined: fileContent 1`] = `
exports[`toRedirectFilesMetadata should create appropriate metadata trailingSlash=undefined: fileContent 1`] = `
Array [
"<!DOCTYPE html>
<html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('createToUrl', () => {
});

describe('toRedirectFilesMetadata', () => {
test('should create appropriate metadatas trailingSlash=undefined', async () => {
test('should create appropriate metadata trailingSlash=undefined', async () => {
const pluginContext = {
outDir: '/tmp/someFixedOutDir',
baseUrl: 'https://docusaurus.io',
Expand All @@ -69,7 +69,7 @@ describe('toRedirectFilesMetadata', () => {
);
});

test('should create appropriate metadatas trailingSlash=true', async () => {
test('should create appropriate metadata trailingSlash=true', async () => {
const pluginContext = {
outDir: '/tmp/someFixedOutDir',
baseUrl: 'https://docusaurus.io',
Expand All @@ -96,7 +96,7 @@ describe('toRedirectFilesMetadata', () => {
);
});

test('should create appropriate metadatas trailingSlash=false', async () => {
test('should create appropriate metadata trailingSlash=false', async () => {
const pluginContext = {
outDir: '/tmp/someFixedOutDir',
baseUrl: 'https://docusaurus.io',
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('toRedirectFilesMetadata', () => {
);
});

test('should create appropriate metadatas for root baseUrl', async () => {
test('should create appropriate metadata for root baseUrl', async () => {
const pluginContext = {
outDir: '/tmp/someFixedOutDir',
baseUrl: '/',
Expand All @@ -139,7 +139,7 @@ describe('toRedirectFilesMetadata', () => {
);
});

test('should create appropriate metadatas for empty baseUrl', async () => {
test('should create appropriate metadata for empty baseUrl', async () => {
const pluginContext = {
outDir: '/tmp/someFixedOutDir',
baseUrl: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ describe('site with full autogenerated sidebar', () => {
});
});

test('docs in fully generated sidebar have correct metadatas', async () => {
test('docs in fully generated sidebar have correct metadata', async () => {
const {content, siteDir} = await loadSite();
const version = content.loadedVersions[0];

Expand Down Expand Up @@ -1518,11 +1518,11 @@ describe('site with partial autogenerated sidebars', () => {
});
});

test('docs in partially generated sidebar have correct metadatas', async () => {
test('docs in partially generated sidebar have correct metadata', async () => {
const {content, siteDir} = await loadSite();
const version = content.loadedVersions[0];

// Only looking at the docs of the autogen sidebar, others metadatas should not be affected
// Only looking at the docs of the autogen sidebar, others metadata should not be affected

expect(getDocById(version, 'API/api-end')).toEqual({
...defaultDocMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import {DocFrontMatter} from './types';

// NOTE: we don't add any default value on purpose here
// We don't want default values to magically appear in doc metadatas and props
// We don't want default values to magically appear in doc metadata and props
// While the user did not provide those values explicitly
// We use default values in code instead
const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-docs/src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export function processDocMetadata(args: {
} catch (e) {
console.error(
chalk.red(
`Can't process doc metadatas for doc at path "${args.docFile.filePath}" in version "${args.versionMetadata.versionName}"`,
`Can't process doc metadata for doc at path "${args.docFile.filePath}" in version "${args.versionMetadata.versionName}"`,
),
);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
26 changes: 13 additions & 13 deletions packages/docusaurus-plugin-content-docs/src/sidebars/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand All @@ -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(
Expand All @@ -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}`),
);
Expand Down Expand Up @@ -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]) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getNormalizedSidebarName({
}

/*
// Do we need to translate doc metadatas?
// Do we need to translate doc metadata?
// It seems translating frontmatter labels is good enough
function getDocTranslations(doc: DocMetadata): TranslationFileContent {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ describe('docusaurus-plugin-content-pages', () => {
path: pluginPath,
}),
);
const pagesMetadatas = await plugin.loadContent?.();
const pagesMetadata = await plugin.loadContent?.();

expect(pagesMetadatas).toEqual([
expect(pagesMetadata).toEqual([
{
type: 'jsx',
permalink: '/',
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('docusaurus-plugin-content-pages', () => {
path: pluginPath,
}),
);
const pagesMetadatas = await plugin.loadContent?.();
const pagesMetadata = await plugin.loadContent?.();

const frTranslationsPath = path.posix.join(
'@site',
Expand All @@ -98,7 +98,7 @@ describe('docusaurus-plugin-content-pages', () => {
'docusaurus-plugin-content-pages',
);

expect(pagesMetadatas).toEqual([
expect(pagesMetadata).toEqual([
{
type: 'jsx',
permalink: '/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function BlogListPage(props: Props): JSX.Element {
description={blogDescription}
wrapperClassName={ThemeClassNames.wrapper.blogPages}
pageClassName={ThemeClassNames.page.blogListPage}
searchMetadatas={{
searchMetadata={{
// assign unique search tag to exclude this page from search results!
tag: 'blog_posts_list',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function BlogTagsListPage(props: Props): JSX.Element {
title={title}
wrapperClassName={ThemeClassNames.wrapper.blogPages}
pageClassName={ThemeClassNames.page.blogTagsListPage}
searchMetadatas={{
searchMetadata={{
// assign unique search tag to exclude this page from search results!
tag: 'blog_tags_list',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function BlogTagsPostsPage(props: Props): JSX.Element {
title={title}
wrapperClassName={ThemeClassNames.wrapper.blogPages}
pageClassName={ThemeClassNames.page.blogTagPostListPage}
searchMetadatas={{
searchMetadata={{
// assign unique search tag to exclude this page from search results!
tag: 'blog_tags_posts',
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function DocPageContent({
<Layout
wrapperClassName={ThemeClassNames.wrapper.docsPages}
pageClassName={ThemeClassNames.page.docsDocPage}
searchMetadatas={{
searchMetadata={{
version,
tag: docVersionSearchTag(pluginId, version),
}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function DocTagDocListPage({tag}: Props): JSX.Element {
title={title}
wrapperClassName={ThemeClassNames.wrapper.docsPages}
pageClassName={ThemeClassNames.page.docsTagDocListPage}
searchMetadatas={{
searchMetadata={{
// assign unique search tag to exclude this page from search results!
tag: 'doc_tag_doc_list',
}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function DocTagsListPage({tags}: Props): JSX.Element {
title={title}
wrapperClassName={ThemeClassNames.wrapper.docsPages}
pageClassName={ThemeClassNames.page.docsTagsListPage}
searchMetadatas={{
searchMetadata={{
// assign unique search tag to exclude this page from search results!
tag: 'doc_tags_list',
}}>
Expand Down
Loading