-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLayout.tsx
More file actions
145 lines (131 loc) · 4.75 KB
/
Copy pathLayout.tsx
File metadata and controls
145 lines (131 loc) · 4.75 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React from 'react';
import NextHead from 'next/head';
import Link from 'next/link';
import { useThemeState } from '../theme/ThemeContext';
import { Theme } from '../theme/theme';
import ThemePicker from './common/ThemePicker';
import Footer from './Footer';
import { useLoadingState } from './LoadingContext';
import { ScriptifiedLogo } from './icons/icons';
import { useRouter } from 'next/router';
import FloatingShareButton from './common/FloatingShareButton';
import Text from './common/Text';
export const siteConfig = {
name: 'Scriptified',
description: 'Insightful tips, tools, resources & more on React and JavaScript',
url: 'https://scriptified.dev',
ogImg: 'https://scriptified.dev/images/landing-page-og.jpg',
};
const Loader = () => (
<div className="flex items-center justify-center h-screen w-screen">
<ScriptifiedLogo color={`text-black-900`} additionalStyles="w-24 h-24 animate-pulse" />
</div>
);
type SEO = {
title?: string;
description?: string;
url?: string;
image?: string;
twitter?: string;
author?: string;
faviconPath?: Theme;
};
const Head = ({
title = siteConfig.name,
description = siteConfig.description,
url = siteConfig.url,
image = siteConfig.ogImg,
twitter = '@scriptified_dev',
author = siteConfig.name,
faviconPath,
}: SEO) => (
<NextHead>
{/* Title and Description */}
<title>{title}</title>
<meta name="description" content={`${description}. Curated by Prateek Surana and Ayush Gupta.`} />
<meta name="title" content={title} />
{/* Essentials */}
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{/* General */}
<meta httpEquiv="Content-Language" content="en" />
<meta name="author" content={author} />
<meta name="description" content={description} />
<meta property="apple-mobile-web-app-title" content={title} />
{/* Open Graph */}
<meta property="og:url" content={url} />
<meta property="og:type" content="website" />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={image} />
{/* Twitter */}
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:site" content={twitter} />
<meta property="twitter:title" content={title} />
<meta property="twitter:image" content={image} />
<meta property="twitter:description" content={description} />
<meta property="twitter:url" content={url} />
{/* Facebook */}
<meta property="fb:app_id" content={process.env.NEXT_PUBLIC_FACEBOOK_APP_ID} />
{/* Favicons */}
<link rel="icon" type="image/png" sizes="16x16" href={`/icons/${faviconPath}/favicon-16x16.png`} />
<link rel="icon" type="image/png" sizes="32x32" href={`/icons/${faviconPath}/favicon-32x32.png`} />
<link rel="icon" type="image/png" sizes="96x96" href={`/icons/${faviconPath}/favicon-96x96.png`} />
<link rel="icon" type="image/png" sizes="128x128" href={`/icons/${faviconPath}/favicon-128.png`} />
<link rel="shortcut icon" href={`/icons/${faviconPath}/favicon.ico`} />
<link rel="icon" href={`/icons/${faviconPath}/favicon.ico`} />
</NextHead>
);
export default function Layout({
children,
home,
additionalStyles,
...seoProps
}: {
children: React.ReactNode;
home?: boolean;
additionalStyles?: string;
} & SEO): JSX.Element {
const theme = useThemeState();
const loading = useLoadingState();
const router = useRouter();
const renderFloatingShareBtn = () => {
if (router.pathname === '/issues/[id]') {
return <FloatingShareButton />;
} else {
return null;
}
};
return (
<>
<Head {...seoProps} faviconPath={theme} />
{loading ? (
<Loader />
) : (
<>
<ThemePicker textColor={home ? 'text-gray-100' : `text-${theme}-900`} />
<div className={`py-0 mx-auto ${additionalStyles ? additionalStyles : ''} relative z-10`}>
<header className="flex flex-col items-center">
{home ? (
<div />
) : (
<>
<Link href="/" aria-label={siteConfig.name}>
<ScriptifiedLogo color={`text-${theme}-900`} additionalStyles="w-24 h-24" />
</Link>
<Text as="h1" size="6xl" additionalStyles="leading-snug my-4 mx-0">
<Link href="/" className={`no-underline hover:underline text-${theme}-900 font-bold font-sniglet`}>
{siteConfig.name}
</Link>
</Text>
</>
)}
</header>
<main className="relative">{children}</main>
<Footer />
{renderFloatingShareBtn()}
</div>
</>
)}
</>
);
}