diff --git a/packages/docusaurus/src/server/__tests__/configValidation.test.ts b/packages/docusaurus/src/server/__tests__/configValidation.test.ts index 63dce02913f5..a94d8d18ba9a 100644 --- a/packages/docusaurus/src/server/__tests__/configValidation.test.ts +++ b/packages/docusaurus/src/server/__tests__/configValidation.test.ts @@ -330,24 +330,40 @@ describe('headTags', () => { ).not.toThrow(); }); - it("throws error if headTags doesn't have string attributes", () => { + it('throws error if headTags has invalid attribute values', () => { expect(() => { normalizeConfig({ headTags: [ { tagName: 'link', attributes: { - rel: false, + rel: 123, href: 'img/docusaurus.png', }, }, ], }); }).toThrowErrorMatchingInlineSnapshot(` - [Error: "headTags[0].attributes.rel" must be a string + [Error: "headTags[0].attributes.rel" must be one of [string, boolean] ] `); }); + + it('accepts headTags with boolean attributes', () => { + expect(() => { + normalizeConfig({ + headTags: [ + { + tagName: 'script', + attributes: { + src: '/analytics.js', + async: true, + }, + }, + ], + }); + }).not.toThrow(); + }); }); describe('css', () => { diff --git a/packages/docusaurus/src/server/configValidation.ts b/packages/docusaurus/src/server/configValidation.ts index 462e5b2274d6..1c4ea8dacbfe 100644 --- a/packages/docusaurus/src/server/configValidation.ts +++ b/packages/docusaurus/src/server/configValidation.ts @@ -469,7 +469,10 @@ export const ConfigSchema = Joi.object({ is: Joi.valid(true), then: Joi.optional(), otherwise: Joi.object() - .pattern(/[\w-]+/, Joi.string()) + .pattern( + /[\w-]+/, + Joi.alternatives().try(Joi.string(), Joi.boolean()), + ) .required(), }), customElement: Joi.bool().default(false),