File tree Expand file tree Collapse file tree 6 files changed +30
-4
lines changed
Expand file tree Collapse file tree 6 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import codeHikeStyles from '@code-hike/mdx/dist/index.css';
44
55export const Head = ( { data } : { data : DocumentationLoader } ) => {
66 const favicon = getFavicon ( { data } ) ;
7-
7+ data . repo ;
88 return (
99 < Helmet >
1010 { data . config . googleAnalytics && (
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import reactMediumImage from 'react-medium-image-zoom/dist/styles.css';
1616import { BadRequest , NotFound , ServerError } from '~/components/Errors' ;
1717import Documentation from '~/components/Documentation' ;
1818import { Head } from '~/components/Head' ;
19+ import { getSocialImage } from '~/utils' ;
1920
2021//@ts -ignore
2122export 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 } ` : ''
Original file line number Diff line number Diff line change @@ -10,18 +10,19 @@ import {
1010} from '@heroicons/react/solid' ;
1111import { Checkout } from '~/components/Checkout' ;
1212import { Footer } from '~/components/Footer' ;
13+ import { getSocialImage } from '~/utils' ;
1314
1415export 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
Original file line number Diff line number Diff line change 1+ import { DocumentationLoader } from '~/loaders/documentation.server' ;
12import { getValue } from './get' ;
23
34export 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+ }
You can’t perform that action at this time.
0 commit comments