-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
/
Copy pathHead.js
75 lines (71 loc) · 2.56 KB
/
Head.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import * as React from 'react';
import NextHead from 'next/head';
import { useRouter } from 'next/router';
import PropTypes from 'prop-types';
import { LANGUAGES_SSR } from 'docs/src/modules/constants';
import { useUserLanguage, useTranslate } from 'docs/src/modules/utils/i18n';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
// #major-version-switch
const HOST = 'https://mui.com';
export default function Head(props) {
const t = useTranslate();
const {
card = '/static/social-previews/default-preview.jpg',
children,
description = t('strapline'),
disableAlternateLocale = false,
largeCard = true,
title = t('headTitle'),
} = props;
const userLanguage = useUserLanguage();
const router = useRouter();
const preview = card.startsWith('http') ? card : `${HOST}${card}`;
const { canonicalAs } = pathnameToLanguage(router.asPath);
return (
<NextHead>
<title>{title}</title>
<meta name="description" content={description} />
{/* Twitter */}
<meta name="twitter:card" content={largeCard ? 'summary_large_image' : 'summary'} />
{/* https://twitter.com/MUI_hq */}
<meta name="twitter:site" content="@MUI_hq" />
{/* #major-version-switch */}
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:image" content={preview} />
{/* Facebook */}
<meta property="og:type" content="website" />
<meta property="og:title" content={title} />
{/* #major-version-switch */}
<meta property="og:url" content={`${HOST}${router.asPath}`} />
<meta property="og:description" content={description} />
<meta property="og:image" content={preview} />
<meta property="og:ttl" content="604800" />
{/* Algolia */}
<meta name="docsearch:language" content={userLanguage} />
{/* #major-version-switch */}
<meta name="docsearch:version" content="master" />
{disableAlternateLocale
? null
: LANGUAGES_SSR.map((userLanguage2) => (
<link
key={userLanguage2}
rel="alternate"
href={`https://mui.com${
userLanguage2 === 'en' ? '' : `/${userLanguage2}`
}${canonicalAs}`}
hrefLang={userLanguage2}
/>
))}
{children}
</NextHead>
);
}
Head.propTypes = {
card: PropTypes.string,
children: PropTypes.node,
description: PropTypes.string,
disableAlternateLocale: PropTypes.bool,
largeCard: PropTypes.bool,
title: PropTypes.string,
};