Skip to content

Commit 255283a

Browse files
authored
fix: remove overriding favicon and fix social preview image (#217)
* fix: remove overriding favicon and fix social preview image * fix: handle socialPreview absolute and relative mode
1 parent 0094049 commit 255283a

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

docs/assets/docs-page-social.png

66.1 KB
Loading

website/app/components/Head.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import codeHikeStyles from '@code-hike/mdx/dist/index.css';
44

55
export const Head = ({ data }: { data: DocumentationLoader }) => {
66
const favicon = getFavicon({ data });
7-
7+
data.repo;
88
return (
99
<Helmet>
1010
{data.config.googleAnalytics && (

website/app/root.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const links: LinksFunction = () => {
3535
},
3636
{ rel: 'stylesheet', href: nProgressStyles },
3737
{ rel: 'stylesheet', href: tailwind },
38-
{ rel: 'icon', href: 'https://docs.page/favicon.ico?v=2' },
3938
];
4039
};
4140

website/app/routes/$owner.$repo.$.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import reactMediumImage from 'react-medium-image-zoom/dist/styles.css';
1616
import { BadRequest, NotFound, ServerError } from '~/components/Errors';
1717
import Documentation from '~/components/Documentation';
1818
import { Head } from '~/components/Head';
19+
import { getSocialImage } from '~/utils';
1920

2021
//@ts-ignore
2122
export function headers({ loaderHeaders }) {
@@ -45,8 +46,12 @@ export const meta: MetaFunction = (props: { data?: DocumentationLoader }) => {
4546
};
4647
}
4748

49+
const socialPreviewImage = getSocialImage(props.data);
50+
4851
return {
4952
'twitter:card': 'summary_large_image',
53+
'twitter:image': socialPreviewImage,
54+
'og:image': socialPreviewImage,
5055
'twiter:image:alt': props.data?.config?.name ?? '',
5156
'og:url': `https://docs.page/${props.data.owner}/${props.data.repo}${
5257
props.data.path ? `/${props.data.path}` : ''

website/app/routes/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ import {
1010
} from '@heroicons/react/solid';
1111
import { Checkout } from '~/components/Checkout';
1212
import { Footer } from '~/components/Footer';
13+
import { getSocialImage } from '~/utils';
1314

1415
export const meta: MetaFunction = () => ({
1516
'theme-color': '#ffffff',
1617
title: 'docs.page | Create an instant Open Source docs page with zero configuration.',
1718
description: 'Create an instant Open Source docs page with zero configuration.',
1819
'og:title': 'docs.page',
1920
'og:description': 'Create an instant Open Source docs page with zero configuration.',
20-
'og:image': 'http://docs.page/assets/docs-page-social.png',
21+
'og:image': getSocialImage(),
2122
'og:url': 'http://docs.page',
2223
'twitter:title': 'docs.page',
2324
'twitter:description': 'Create an instant Open Source docs page with zero configuration.',
24-
'twitter:image': 'http://docs.page/assets/docs-page-social.png',
25+
'twitter:image': getSocialImage(),
2526
'twitter:card': 'summary_large_image',
2627
});
2728

website/app/utils/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DocumentationLoader } from '~/loaders/documentation.server';
12
import { getValue } from './get';
23

34
export function ensureLeadingSlash(path: string) {
@@ -36,3 +37,23 @@ export function hash(value: string): string {
3637
}
3738
return hash.toString();
3839
}
40+
41+
export function getSocialImage(data?: DocumentationLoader): string {
42+
if (!data?.config.socialPreview || !data) {
43+
return 'https://raw.githubusercontent.com/invertase/docs.page/main/docs/assets/docs-page-social.png';
44+
}
45+
46+
let socialPreviewUrl = data.config.socialPreview;
47+
48+
if (socialPreviewUrl.startsWith('http')) {
49+
return new URL(socialPreviewUrl).href;
50+
}
51+
if (!socialPreviewUrl.startsWith('/')) {
52+
socialPreviewUrl = '/' + socialPreviewUrl;
53+
}
54+
const ref = encodeURIComponent(data.source.ref);
55+
56+
socialPreviewUrl = `https://raw.githubusercontent.com/${data.owner}/${data.repo}/${ref}/docs${socialPreviewUrl}`;
57+
58+
return new URL(socialPreviewUrl).href;
59+
}

0 commit comments

Comments
 (0)