fix(theme-classic): fix translation when footer has no links (#6144)

This commit is contained in:
Joshua Chen 2021-12-21 20:12:19 +08:00 committed by GitHub
parent 287292497d
commit 0384a7919e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 23 deletions

View file

@ -74,21 +74,21 @@ function translateNavbar(
function isMultiColumnFooterLinks(
links: MultiColumnFooter['links'] | SimpleFooter['links'],
): links is MultiColumnFooter['links'] {
return 'title' in links[0];
return links.length > 0 && 'title' in links[0];
}
function getFooterTranslationFile(footer: Footer): TranslationFileContent {
const footerLinkTitles: TranslationFileContent = isMultiColumnFooterLinks(
footer.links,
const footerLinkTitles: TranslationFileContent = chain(
isMultiColumnFooterLinks(footer.links)
? footer.links.filter((link) => !!link.title)
: [],
)
? chain(footer.links.filter((link) => !!link.title))
.keyBy((link) => `link.title.${link.title}`)
.mapValues((link) => ({
message: link.title!,
description: `The title of the footer links column with title=${link.title} in the footer`,
}))
.value()
: {};
.keyBy((link) => `link.title.${link.title}`)
.mapValues((link) => ({
message: link.title!,
description: `The title of the footer links column with title=${link.title} in the footer`,
}))
.value();
const footerLinkLabels: TranslationFileContent = chain(
isMultiColumnFooterLinks(footer.links)

View file

@ -312,18 +312,18 @@ const ThemeConfigSchema = Joi.object({
}),
copyright: Joi.string(),
links: Joi.alternatives(
Joi.array()
.items(
Joi.object({
title: Joi.string().allow(null).default(null),
items: Joi.array().items(FooterLinkItemSchema).default([]),
}),
)
.default([]),
Joi.array().items(FooterLinkItemSchema).default([]),
).messages({
'alternatives.match': `The footer must be either simple or multi-column, and not a mix of the two. See: https://docusaurus.io/docs/api/themes/configuration#footer-links`,
}),
Joi.array().items(
Joi.object({
title: Joi.string().allow(null).default(null),
items: Joi.array().items(FooterLinkItemSchema).default([]),
}),
),
Joi.array().items(FooterLinkItemSchema),
)
.messages({
'alternatives.match': `The footer must be either simple or multi-column, and not a mix of the two. See: https://docusaurus.io/docs/api/themes/configuration#footer-links`,
})
.default([]),
}).optional(),
prism: Joi.object({
theme: Joi.object({