feat: custom navbarItem types (workaround) (#7231)

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
Sébastien Lorber 2022-04-29 11:23:46 +02:00 committed by GitHub
parent 0ffdfe9c22
commit 6265f6dabb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 194 additions and 44 deletions

View file

@ -99,11 +99,22 @@ const HtmlNavbarItemSchema = Joi.object({
value: Joi.string().required(),
});
const itemWithType = (type: string | undefined) => {
// A temporary workaround to allow users to add custom navbar items
// See https://github.com/facebook/docusaurus/issues/7227
const CustomNavbarItemRegexp = /custom-.*/;
const CustomNavbarItemSchema = Joi.object({
type: Joi.string().regex(CustomNavbarItemRegexp).required(),
}).unknown();
const itemWithType = (type: string | RegExp | undefined) => {
// Because equal(undefined) is not supported :/
const typeSchema = type
? Joi.string().required().equal(type)
: Joi.string().forbidden();
const typeSchema =
// eslint-disable-next-line no-nested-ternary
type instanceof RegExp
? Joi.string().required().regex(type)
: type
? Joi.string().required().equal(type)
: Joi.string().forbidden();
return Joi.object({
type: typeSchema,
})
@ -135,6 +146,10 @@ const DropdownSubitemSchema = Joi.object({
is: itemWithType('html'),
then: HtmlNavbarItemSchema,
},
{
is: itemWithType(CustomNavbarItemRegexp),
then: CustomNavbarItemSchema,
},
{
is: Joi.alternatives().try(
itemWithType('dropdown'),
@ -210,6 +225,10 @@ const NavbarItemSchema = Joi.object({
is: itemWithType('html'),
then: HtmlNavbarItemSchema,
},
{
is: itemWithType(CustomNavbarItemRegexp),
then: CustomNavbarItemSchema,
},
{
is: itemWithType(undefined),
then: Joi.object().when('.', {