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

@ -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}
---

View file

@ -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>
@ -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>
@ -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>
@ -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>
@ -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>

View file

@ -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',
@ -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',
@ -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',
@ -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: '/',
@ -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: '',

View file

@ -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];
@ -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,

View file

@ -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>({

View file

@ -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;

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'

View file

@ -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 {

View file

@ -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: '/',
@ -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',
@ -98,7 +98,7 @@ describe('docusaurus-plugin-content-pages', () => {
'docusaurus-plugin-content-pages',
);
expect(pagesMetadatas).toEqual([
expect(pagesMetadata).toEqual([
{
type: 'jsx',
permalink: '/',

View file

@ -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',
}}

View file

@ -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',
}}

View file

@ -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',
}}

View file

@ -58,7 +58,7 @@ function DocPageContent({
<Layout
wrapperClassName={ThemeClassNames.wrapper.docsPages}
pageClassName={ThemeClassNames.page.docsDocPage}
searchMetadatas={{
searchMetadata={{
version,
tag: docVersionSearchTag(pluginId, version),
}}>

View file

@ -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',
}}>

View file

@ -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',
}}>

View file

@ -10,7 +10,7 @@ import Head from '@docusaurus/Head';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useBaseUrl from '@docusaurus/useBaseUrl';
import type {Props} from '@theme/Layout';
import SearchMetadatas from '@theme/SearchMetadatas';
import SearchMetadata from '@theme/SearchMetadata';
import Seo from '@theme/Seo';
import {
DEFAULT_SEARCH_TAG,
@ -87,8 +87,8 @@ export default function LayoutHead(props: Props): JSX.Element {
siteConfig: {favicon},
i18n: {currentLocale, localeConfigs},
} = useDocusaurusContext();
const {metadatas, image: defaultImage} = useThemeConfig();
const {title, description, image, keywords, searchMetadatas} = props;
const {metadata, image: defaultImage} = useThemeConfig();
const {title, description, image, keywords, searchMetadata} = props;
const faviconUrl = useBaseUrl(favicon);
const pageTitle = useTitleFormatter(title);
@ -117,21 +117,22 @@ export default function LayoutHead(props: Props): JSX.Element {
<AlternateLangHeaders />
<SearchMetadatas
<SearchMetadata
tag={DEFAULT_SEARCH_TAG}
locale={currentLocale}
{...searchMetadatas}
{...searchMetadata}
/>
<Head
// it's important to have an additional <Head> element here,
// as it allows react-helmet to override values set in previous <Head>
// ie we can override default metadatas such as "twitter:card"
// ie we can override default metadata such as "twitter:card"
// In same Head, the same meta would appear twice instead of overriding
// See react-helmet doc
>
{metadatas.map((metadata, i) => (
<meta key={`metadata_${i}`} {...metadata} />
{/* Yes, "metadatum" is the grammatically correct term */}
{metadata.map((metadatum, i) => (
<meta key={`metadata_${i}`} {...metadatum} />
))}
</Head>
</>

View file

@ -8,12 +8,12 @@
import React from 'react';
import Head from '@docusaurus/Head';
import type {Props} from '@theme/SearchMetadatas';
import type {Props} from '@theme/SearchMetadata';
// Note: we don't couple this to Algolia/DocSearch on purpose
// We may want to support other search engine plugins too
// Search plugins should swizzle/override this comp to add their behavior
export default function SearchMetadatas({
export default function SearchMetadata({
locale,
version,
tag,

View file

@ -301,7 +301,7 @@ declare module '@theme/Layout' {
readonly permalink?: string;
readonly wrapperClassName?: string;
readonly pageClassName?: string;
readonly searchMetadatas?: {
readonly searchMetadata?: {
readonly version?: string;
readonly tag?: string;
};
@ -320,15 +320,15 @@ declare module '@theme/LayoutHead' {
export default LayoutHead;
}
declare module '@theme/SearchMetadatas' {
declare module '@theme/SearchMetadata' {
export interface Props {
readonly locale?: string;
readonly version?: string;
readonly tag?: string;
}
const SearchMetadatas: (props: Props) => JSX.Element;
export default SearchMetadatas;
const SearchMetadata: (props: Props) => JSX.Element;
export default SearchMetadata;
}
declare module '@theme/LastUpdated' {

View file

@ -32,7 +32,7 @@ const DEFAULT_COLOR_MODE_CONFIG = {
const DEFAULT_CONFIG = {
colorMode: DEFAULT_COLOR_MODE_CONFIG,
docs: DEFAULT_DOCS_CONFIG,
metadatas: [],
metadata: [],
prism: {
additionalLanguages: [],
},
@ -46,7 +46,6 @@ const DEFAULT_CONFIG = {
maxHeadingLevel: 3,
},
};
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
const NavbarItemPosition = Joi.string().equal('left', 'right').default('left');
@ -264,9 +263,13 @@ const ThemeConfigSchema = Joi.object({
colorMode: ColorModeSchema,
image: Joi.string(),
docs: DocsSchema,
metadatas: Joi.array()
metadata: Joi.array()
.items(HtmlMetadataSchema)
.default(DEFAULT_CONFIG.metadatas),
.default(DEFAULT_CONFIG.metadata),
metadatas: Joi.any().forbidden().messages({
'any.unknown':
'themeConfig.metadatas has been renamed as themeConfig.metadata. See https://github.com/facebook/docusaurus/pull/5871',
}),
announcementBar: Joi.object({
id: Joi.string().default('announcement-bar'),
content: Joi.string().required(),
@ -358,7 +361,7 @@ const ThemeConfigSchema = Joi.object({
}).default(DEFAULT_CONFIG.tableOfContents),
});
export {ThemeConfigSchema};
export {DEFAULT_CONFIG, ThemeConfigSchema};
export function validateThemeConfig({
validate,

View file

@ -28,13 +28,13 @@ describe('parseCodeBlockTitle', () => {
expect(parseCodeBlockTitle(`{1,2-3}`)).toEqual(``);
});
test('should parse with multiple metadatas title first', () => {
test('should parse with multiple metadata title first', () => {
expect(parseCodeBlockTitle(`title="index.js" label="JavaScript"`)).toEqual(
`index.js`,
);
});
test('should parse with multiple metadatas title last', () => {
test('should parse with multiple metadata title last', () => {
expect(parseCodeBlockTitle(`label="JavaScript" title="index.js"`)).toEqual(
`index.js`,
);

View file

@ -113,7 +113,7 @@ export type ThemeConfig = {
footer?: Footer;
hideableSidebar: boolean;
image?: string;
metadatas: Array<Record<string, string>>;
metadata: Array<Record<string, string>>;
sidebarCollapsible: boolean;
tableOfContents: TableOfContents;
};

View file

@ -9,8 +9,8 @@ import React from 'react';
import Head from '@docusaurus/Head';
// Override default/agnostic SearchMetas to use Algolia-specific metadatas
export default function AlgoliaSearchMetadatas({locale, version, tag}) {
// Override default/agnostic SearchMetas to use Algolia-specific metadata
export default function AlgoliaSearchMetadata({locale, version, tag}) {
// Seems safe to consider here the locale is the language,
// as the existing docsearch:language filter is afaik a regular string-based filter
const language = locale;

View file

@ -11,7 +11,7 @@ import useContextualSearchFilters from '@theme/hooks/useContextualSearchFilters'
export default function useAlgoliaContextualFacetFilters() {
const {locale, tags} = useContextualSearchFilters();
// seems safe to convert locale->language, see AlgoliaSearchMetadatas comment
// seems safe to convert locale->language, see AlgoliaSearchMetadata comment
const languageFilter = `language:${locale}`;
const tagsFilter = tags.map((tag) => `docusaurus_tag:${tag}`);

View file

@ -36,7 +36,7 @@ describe('createExcerpt', () => {
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
`),
).toEqual(
// h1 title is skipped on purpose, because we don't want the page to have SEO metadatas title === description
// h1 title is skipped on purpose, because we don't want the page to have SEO metadata title === description
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
);
});
@ -53,7 +53,7 @@ describe('createExcerpt', () => {
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
`),
).toEqual(
// h1 title is skipped on purpose, because we don't want the page to have SEO metadatas title === description
// h1 title is skipped on purpose, because we don't want the page to have SEO metadata title === description
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
);
});