diff --git a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.js b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.js index e17027c7d5b5..afea10a29f9a 100644 --- a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.js +++ b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.js @@ -345,6 +345,27 @@ describe('themeConfig', () => { }); }); + test('should allow width and height specification for logo ', () => { + const altTagConfig = { + navbar: { + logo: { + alt: '', + src: '/arbitrary-logo.png', + srcDark: '/arbitrary-dark-logo.png', + width: '20px', + height: '20%', + }, + }, + }; + expect(testValidateThemeConfig(altTagConfig)).toEqual({ + ...DEFAULT_CONFIG, + navbar: { + ...DEFAULT_CONFIG.navbar, + ...altTagConfig.navbar, + }, + }); + }); + test('should accept valid prism config', () => { const prismConfig = { prism: { diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/index.tsx index ecf37cefb56f..3e5281eeebf6 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Footer/index.tsx @@ -52,8 +52,16 @@ function FooterLink({ const FooterLogo = ({ sources, alt, -}: Pick) => ( - + width, + height, +}: Pick) => ( + ); function Footer(): JSX.Element | null { @@ -115,7 +123,12 @@ function Footer(): JSX.Element | null {
{logo.href ? ( - + ) : ( diff --git a/packages/docusaurus-theme-classic/src/theme/Logo/index.tsx b/packages/docusaurus-theme-classic/src/theme/Logo/index.tsx index 0054cae8bd28..ba1aa1653973 100644 --- a/packages/docusaurus-theme-classic/src/theme/Logo/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Logo/index.tsx @@ -29,7 +29,12 @@ const Logo = (props: Props): JSX.Element => { dark: useBaseUrl(logo.srcDark || logo.src), }; const themedImage = ( - + ); return ( diff --git a/packages/docusaurus-theme-classic/src/validateThemeConfig.ts b/packages/docusaurus-theme-classic/src/validateThemeConfig.ts index d079b2a574a9..18e2146ddeab 100644 --- a/packages/docusaurus-theme-classic/src/validateThemeConfig.ts +++ b/packages/docusaurus-theme-classic/src/validateThemeConfig.ts @@ -290,6 +290,8 @@ const ThemeConfigSchema = Joi.object({ alt: Joi.string().allow(''), src: Joi.string().required(), srcDark: Joi.string(), + width: Joi.alternatives().try(Joi.string(), Joi.number()), + height: Joi.alternatives().try(Joi.string(), Joi.number()), href: Joi.string(), target: Joi.string(), }), @@ -300,6 +302,9 @@ const ThemeConfigSchema = Joi.object({ alt: Joi.string().allow(''), src: Joi.string(), srcDark: Joi.string(), + // TODO infer this from reading the image + width: Joi.alternatives().try(Joi.string(), Joi.number()), + height: Joi.alternatives().try(Joi.string(), Joi.number()), href: Joi.string(), }), copyright: Joi.string(), diff --git a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts index 5159f23766ff..e2cdbe28f78d 100644 --- a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts +++ b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts @@ -22,6 +22,8 @@ export type NavbarItem = { export type NavbarLogo = { src: string; srcDark?: string; + width?: string | number; + height?: string | number; href?: string; target?: string; alt?: string; @@ -80,6 +82,8 @@ export type Footer = { alt?: string; src?: string; srcDark?: string; + width?: string | number; + height?: string | number; href?: string; }; copyright?: string; diff --git a/website/docs/api/docusaurus.config.js.md b/website/docs/api/docusaurus.config.js.md index 638388dd2b85..92fe87b4e7f2 100644 --- a/website/docs/api/docusaurus.config.js.md +++ b/website/docs/api/docusaurus.config.js.md @@ -264,6 +264,8 @@ module.exports = { logo: { alt: 'Site Logo', src: 'img/logo.svg', + width: 32, + height: 32, }, items: [ { @@ -292,6 +294,8 @@ module.exports = { logo: { alt: 'Facebook Open Source Logo', src: 'https://docusaurus.io/img/oss_logo.png', + width: 160, + height: 51, }, copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc.`, // You can also put own HTML here }, diff --git a/website/docs/api/themes/theme-configuration.md b/website/docs/api/themes/theme-configuration.md index af90e16d4bd1..4b91fad475e7 100644 --- a/website/docs/api/themes/theme-configuration.md +++ b/website/docs/api/themes/theme-configuration.md @@ -187,6 +187,8 @@ Accepted fields: | `src` | `string` | **Required** | URL to the logo image. Base URL is appended by default. | | `srcDark` | `string` | `logo.src` | An alternative image URL to use in dark mode. | | `href` | `string` | `siteConfig.baseUrl` | Link to navigate to when the logo is clicked. | +| `width` | string \| number | `undefined` | Specifies the `width` attribute. | +| `height` | string \| number | `undefined` | Specifies the `height` attribute. | | `target` | `string` | Calculated based on `href` (external links will open in a new tab, all others in the current one). | The `target` attribute of the link; controls whether the link is opened in a new tab, the current one, or otherwise. | @@ -205,6 +207,8 @@ module.exports = { srcDark: 'img/logo_dark.svg', href: 'https://docusaurus.io/', target: '_self', + width: 32, + height: 32, }, // highlight-end }, @@ -679,6 +683,8 @@ module.exports = { alt: 'Facebook Open Source Logo', src: 'img/oss_logo.png', href: 'https://opensource.facebook.com', + width: 160, + height: 51, }, copyright: `Copyright © ${new Date().getFullYear()} My Project, Inc. Built with Docusaurus.`, }, diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 722563564d35..0da2f9af6b11 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -334,6 +334,8 @@ const config = { alt: 'Docusaurus Logo', src: 'img/docusaurus.svg', srcDark: 'img/docusaurus_keytar.svg', + width: 32, + height: 32, }, items: [ { @@ -487,6 +489,8 @@ const config = { logo: { alt: 'Facebook Open Source Logo', src: 'img/oss_logo.png', + width: 160, + height: 51, href: 'https://opensource.facebook.com', }, copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc. Built with Docusaurus.`,