-
Notifications
You must be signed in to change notification settings - Fork 160
/
DefaultLayout.jsx
49 lines (44 loc) · 1.91 KB
/
DefaultLayout.jsx
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
import React from 'react';
import Head from 'next/head';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import cfg from '../data/config.js';
import Navbar from '../components/Navbar.jsx';
import Footer from '../components/Footer.jsx';
const DefaultLayout = ({ title, description, author, image, type = 'website', children }) => {
const { t } = useTranslation('common');
const { asPath, locale } = useRouter();
const fullTitle = title ? `${title} | ${cfg.title}` : cfg.title;
const metaDescription = description || t('description');
const metaAuthor = author || t('author');
const [path] = asPath.split('?');
const prefix = locale === 'ru' ? `/${locale}` : '';
const url = `${cfg.siteUrl}${prefix}${path}`;
const imageUrl = `${cfg.siteUrl}${image}`;
return (
<>
<Head>
<title>{fullTitle}</title>
<link rel="icon" href={cfg.favicon} />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="author" content={metaAuthor} />
<meta name="description" content={metaDescription} />
<link rel="canonical" href={url} />
<meta property="og:title" content={title} />
<meta property="og:locale" content={t('locale')} />
<meta property="og:description" content={metaDescription} />
<meta property="og:url" content={url} />
<meta property="og:site_name" content={cfg.title} />
<meta property="og:type" content={type} />
{image && <meta property="og:image" content={imageUrl} />}
<meta property="twitter:title" content={title} />
<meta name="twitter:card" content={image ? 'summary_large_image' : 'summary'} />
{image && <meta name="twitter:image" content={imageUrl} />}
</Head>
<Navbar />
<main className="container">{children}</main>
<Footer />
</>
);
};
export default DefaultLayout;