mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-28 05:58:38 +02:00
feat: custom navbarItem types (workaround) (#7231)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
0ffdfe9c22
commit
6265f6dabb
9 changed files with 194 additions and 44 deletions
|
@ -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('.', {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue