Skip to content

Commit

Permalink
fix(v2): fix external URL for og:image tag (#2420)
Browse files Browse the repository at this point in the history
* fix(v2): og:image

* Use isInternalUrl()

* Update index.js

* Update index.js

* Update index.js

* Update index.js

* Update index.js

Co-authored-by: Yangshun Tay <tay.yang.shun@gmail.com>
  • Loading branch information
38elements and yangshun authored Mar 18, 2020
1 parent 2619a06 commit 8152b47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/docusaurus-theme-classic/src/theme/DocItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -75,7 +76,10 @@ function DocItem(props) {
},
} = DocContent;

const metaImageUrl = siteUrl + useBaseUrl(metaImage);
let metaImageUrl = siteUrl + useBaseUrl(metaImage);
if (!isInternalUrl(metaImage)) {
metaImageUrl = metaImage;
}

return (
<>
Expand Down
9 changes: 7 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -36,8 +37,12 @@ function Layout(props) {
version,
} = props;
const metaTitle = title ? `${title} | ${siteTitle}` : siteTitle;
const metaImage = image || defaultImage;
const metaImageUrl = siteUrl + useBaseUrl(metaImage);

let metaImageUrl = siteUrl + useBaseUrl(metaImage);
if (!isInternalUrl(metaImage)) {
metaImageUrl = metaImage;
}

const faviconUrl = useBaseUrl(favicon);

return (
Expand Down

0 comments on commit 8152b47

Please sign in to comment.