From 1996b870632ab0442d5d4803ed81d3251d58f9fd Mon Sep 17 00:00:00 2001 From: Thi Van Le Date: Fri, 3 Jun 2022 15:36:29 +0200 Subject: [PATCH 1/5] feat: allow specifying custom target for FooterLogo --- .../src/theme/Footer/Logo/index.tsx | 12 +++++++++++- .../src/utils/useThemeConfig.ts | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx index 121e08f758a3..b72ac38e104b 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx @@ -8,6 +8,7 @@ import React from 'react'; import Link from '@docusaurus/Link'; import {useBaseUrlUtils} from '@docusaurus/useBaseUrl'; +import isInternalUrl from '@docusaurus/isInternalUrl'; import ThemedImage from '@theme/ThemedImage'; import type {Props} from '@theme/Footer/Logo'; @@ -31,8 +32,17 @@ function LogoImage({logo}: Props) { } export default function FooterLogo({logo}: Props): JSX.Element { + let logoLinkProps = {}; + if (logo.target) { + logoLinkProps = {target: logo.target}; + } else if (!isInternalUrl(logo.href)) { + logoLinkProps = { + rel: 'noopener noreferrer', + target: '_blank', + }; + } return logo.href ? ( - + ) : ( diff --git a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts index b160bf307c84..400b520bf502 100644 --- a/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts +++ b/packages/docusaurus-theme-common/src/utils/useThemeConfig.ts @@ -75,6 +75,7 @@ export type FooterLogo = { srcDark?: string; width?: string | number; height?: string | number; + target?: string; href?: string; }; From c0046649a3054a67b8782dec404c0372c6c1afdb Mon Sep 17 00:00:00 2001 From: Thi Van Le Date: Fri, 3 Jun 2022 15:58:50 +0200 Subject: [PATCH 2/5] fix: update theme config validation --- .../src/__tests__/validateThemeConfig.test.ts | 1 + packages/docusaurus-theme-classic/src/validateThemeConfig.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts index 850eeb044255..9c8bb7a79e60 100644 --- a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts +++ b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts @@ -102,6 +102,7 @@ describe('themeConfig', () => { alt: 'Facebook Open Source Logo', src: 'img/oss_logo.png', href: 'https://opensource.facebook.com', + target: '_self', }, copyright: `Copyright © ${new Date().getFullYear()} Facebook, Inc. Built with Docusaurus.`, }, diff --git a/packages/docusaurus-theme-classic/src/validateThemeConfig.ts b/packages/docusaurus-theme-classic/src/validateThemeConfig.ts index d64b671f0270..3ce3c618d7a5 100644 --- a/packages/docusaurus-theme-classic/src/validateThemeConfig.ts +++ b/packages/docusaurus-theme-classic/src/validateThemeConfig.ts @@ -364,6 +364,7 @@ export const ThemeConfigSchema = Joi.object({ width: Joi.alternatives().try(Joi.string(), Joi.number()), height: Joi.alternatives().try(Joi.string(), Joi.number()), href: Joi.string(), + target: Joi.string(), }), copyright: Joi.string(), links: Joi.alternatives( From f80d78604e84d40dfedead561cc53a0a1c8853fa Mon Sep 17 00:00:00 2001 From: Thi Van Le Date: Fri, 3 Jun 2022 16:29:50 +0200 Subject: [PATCH 3/5] refactor: remove isInternalUrl --- .../src/theme/Footer/Logo/index.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx index b72ac38e104b..5c6cd813541d 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx @@ -8,7 +8,6 @@ import React from 'react'; import Link from '@docusaurus/Link'; import {useBaseUrlUtils} from '@docusaurus/useBaseUrl'; -import isInternalUrl from '@docusaurus/isInternalUrl'; import ThemedImage from '@theme/ThemedImage'; import type {Props} from '@theme/Footer/Logo'; @@ -35,11 +34,6 @@ export default function FooterLogo({logo}: Props): JSX.Element { let logoLinkProps = {}; if (logo.target) { logoLinkProps = {target: logo.target}; - } else if (!isInternalUrl(logo.href)) { - logoLinkProps = { - rel: 'noopener noreferrer', - target: '_blank', - }; } return logo.href ? ( From bf00188f6833988ca469c9bfb8a0dc90594a408c Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 3 Jun 2022 22:33:27 +0800 Subject: [PATCH 4/5] Update index.tsx --- .../src/theme/Footer/Logo/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx index 5c6cd813541d..bb7b487c2d33 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx @@ -31,12 +31,8 @@ function LogoImage({logo}: Props) { } export default function FooterLogo({logo}: Props): JSX.Element { - let logoLinkProps = {}; - if (logo.target) { - logoLinkProps = {target: logo.target}; - } return logo.href ? ( - + ) : ( From 8770a5e79e99d7c5f9b1e7b34e50d0cbb7dec08b Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Fri, 3 Jun 2022 22:39:10 +0800 Subject: [PATCH 5/5] Update index.tsx --- .../docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx index bb7b487c2d33..b2adfc1f000b 100644 --- a/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Footer/Logo/index.tsx @@ -32,7 +32,10 @@ function LogoImage({logo}: Props) { export default function FooterLogo({logo}: Props): JSX.Element { return logo.href ? ( - + ) : (