From 5832639481eb6f18f0b989032d16095e2601c617 Mon Sep 17 00:00:00 2001 From: 38elements Date: Tue, 17 Mar 2020 08:03:11 +0900 Subject: [PATCH 1/7] fix(v2): og:image --- .../docusaurus-theme-classic/src/theme/DocItem/index.js | 6 +++++- packages/docusaurus-theme-classic/src/theme/Layout/index.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 8325244d35e7..b2c273db6f44 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -75,7 +75,11 @@ function DocItem(props) { }, } = DocContent; - const metaImageUrl = siteUrl + useBaseUrl(metaImage); + const _metaImageUrl = siteUrl + useBaseUrl(metaImage); + const externalRegex = /^(https?:|\/\/)/; + const metaImageUrl = externalRegex.test(metaImage) + ? metaImage + : _metaImageUrl; return ( <> diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.js b/packages/docusaurus-theme-classic/src/theme/Layout/index.js index 571a10db98b7..52e595e55350 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.js @@ -37,7 +37,11 @@ function Layout(props) { } = props; const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle; const metaImage = image || defaultImage; - const metaImageUrl = siteUrl + useBaseUrl(metaImage); + const _metaImageUrl = siteUrl + useBaseUrl(metaImage); + const externalRegex = /^(https?:|\/\/)/; + const metaImageUrl = externalRegex.test(metaImage) + ? metaImage + : _metaImageUrl; const faviconUrl = useBaseUrl(favicon); return ( From 7344e8b895a95c46c6fd2cd4f68a7850b14fc35b Mon Sep 17 00:00:00 2001 From: 38elements Date: Tue, 17 Mar 2020 20:00:39 +0900 Subject: [PATCH 2/7] Use isInternalUrl() --- .../src/theme/DocItem/index.js | 10 +++++----- .../docusaurus-theme-classic/src/theme/Layout/index.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index b2c273db6f44..96b77ffa091a 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -8,6 +8,7 @@ import React from 'react'; import Head from '@docusaurus/Head'; +import isInternalUrl from '@docusaurus/isInternalUrl'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useBaseUrl from '@docusaurus/useBaseUrl'; import DocPaginator from '@theme/DocPaginator'; @@ -75,11 +76,10 @@ function DocItem(props) { }, } = DocContent; - const _metaImageUrl = siteUrl + useBaseUrl(metaImage); - const externalRegex = /^(https?:|\/\/)/; - const metaImageUrl = externalRegex.test(metaImage) - ? metaImage - : _metaImageUrl; + let metaImageUrl = siteUrl + useBaseUrl(metaImage); + if (!isInternalUrl(metaImage)) { + metaImageUrl = metaImage; + } return ( <> diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.js b/packages/docusaurus-theme-classic/src/theme/Layout/index.js index 52e595e55350..86a50b526214 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.js @@ -7,6 +7,7 @@ import React from 'react'; import Head from '@docusaurus/Head'; +import isInternalUrl from '@docusaurus/isInternalUrl'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useBaseUrl from '@docusaurus/useBaseUrl'; @@ -37,11 +38,10 @@ function Layout(props) { } = props; const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle; const metaImage = image || defaultImage; - const _metaImageUrl = siteUrl + useBaseUrl(metaImage); - const externalRegex = /^(https?:|\/\/)/; - const metaImageUrl = externalRegex.test(metaImage) - ? metaImage - : _metaImageUrl; + let metaImageUrl = siteUrl + useBaseUrl(metaImage); + if (!isInternalUrl(metaImage)) { + metaImageUrl = metaImage; + } const faviconUrl = useBaseUrl(favicon); return ( From 037115e83666b9a8fe489e1e2989677ac8236bbe Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Wed, 18 Mar 2020 17:55:39 +0800 Subject: [PATCH 3/7] Update index.js --- .../docusaurus-theme-classic/src/theme/DocItem/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index 96b77ffa091a..b035ed334800 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -76,10 +76,9 @@ function DocItem(props) { }, } = DocContent; - let metaImageUrl = siteUrl + useBaseUrl(metaImage); - if (!isInternalUrl(metaImage)) { - metaImageUrl = metaImage; - } + const metaImageUrl = isInternalUrl(metaImage) + ? metaImage + : siteUrl + useBaseUrl(metaImage); return ( <> From d36774d918756c5effe37112b7bcbf34168d4898 Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Wed, 18 Mar 2020 17:56:14 +0800 Subject: [PATCH 4/7] Update index.js --- .../docusaurus-theme-classic/src/theme/Layout/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.js b/packages/docusaurus-theme-classic/src/theme/Layout/index.js index 86a50b526214..28a4d1fa29bb 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.js @@ -37,11 +37,12 @@ function Layout(props) { version, } = props; const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle; + const metaImage = image || defaultImage; - let metaImageUrl = siteUrl + useBaseUrl(metaImage); - if (!isInternalUrl(metaImage)) { - metaImageUrl = metaImage; - } + const metaImageUrl = isInternalUrl(metaImage) + ? metaImage + : siteUrl + useBaseUrl(metaImage); + const faviconUrl = useBaseUrl(favicon); return ( From 1562ce98e06174a375660a5ce5d659ded7e84bc9 Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Wed, 18 Mar 2020 17:57:58 +0800 Subject: [PATCH 5/7] Update index.js --- packages/docusaurus-theme-classic/src/theme/Layout/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.js b/packages/docusaurus-theme-classic/src/theme/Layout/index.js index 28a4d1fa29bb..c53f4f1a5c3a 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.js @@ -42,7 +42,7 @@ function Layout(props) { const metaImageUrl = isInternalUrl(metaImage) ? metaImage : siteUrl + useBaseUrl(metaImage); - + const faviconUrl = useBaseUrl(favicon); return ( From d64b644cfa8ae319d3ecb393a74179e851da10bd Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Wed, 18 Mar 2020 18:04:37 +0800 Subject: [PATCH 6/7] Update index.js --- .../docusaurus-theme-classic/src/theme/DocItem/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js index b035ed334800..96b77ffa091a 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-classic/src/theme/DocItem/index.js @@ -76,9 +76,10 @@ function DocItem(props) { }, } = DocContent; - const metaImageUrl = isInternalUrl(metaImage) - ? metaImage - : siteUrl + useBaseUrl(metaImage); + let metaImageUrl = siteUrl + useBaseUrl(metaImage); + if (!isInternalUrl(metaImage)) { + metaImageUrl = metaImage; + } return ( <> From 6d5c797da4b52ccccda8169f1a415fdfada0edab Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Wed, 18 Mar 2020 18:04:52 +0800 Subject: [PATCH 7/7] Update index.js --- .../docusaurus-theme-classic/src/theme/Layout/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.js b/packages/docusaurus-theme-classic/src/theme/Layout/index.js index c53f4f1a5c3a..e733f40ee5a0 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.js +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.js @@ -38,10 +38,10 @@ function Layout(props) { } = props; const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle; - const metaImage = image || defaultImage; - const metaImageUrl = isInternalUrl(metaImage) - ? metaImage - : siteUrl + useBaseUrl(metaImage); + let metaImageUrl = siteUrl + useBaseUrl(metaImage); + if (!isInternalUrl(metaImage)) { + metaImageUrl = metaImage; + } const faviconUrl = useBaseUrl(favicon);