-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
TopLayoutBlog.js
360 lines (349 loc) · 10.9 KB
/
TopLayoutBlog.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled, alpha } from '@mui/material/styles';
import { useRouter } from 'next/router';
import { exactProp } from '@mui/utils';
import ChevronLeftRoundedIcon from '@mui/icons-material/ChevronLeftRounded';
import Divider from '@mui/material/Divider';
import Typography from '@mui/material/Typography';
import Avatar from '@mui/material/Avatar';
import Head from 'docs/src/modules/components/Head';
import BrandingProvider from 'docs/src/BrandingProvider';
import AppHeader from 'docs/src/layouts/AppHeader';
import AppContainer from 'docs/src/modules/components/AppContainer';
import AppFooter from 'docs/src/layouts/AppFooter';
import HeroEnd from 'docs/src/components/home/HeroEnd';
import MarkdownElement from 'docs/src/modules/components/MarkdownElement';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import ROUTES from 'docs/src/route';
import Link from 'docs/src/modules/components/Link';
export const authors = {
oliviertassinari: {
name: 'Olivier Tassinari',
avatar: 'https://avatars.githubusercontent.com/u/3165635',
github: 'oliviertassinari',
},
mbrookes: {
name: 'Matt Brookes',
avatar: 'https://avatars.githubusercontent.com/u/357702',
github: 'mbrookes',
},
eps1lon: {
name: 'Sebastian Silbermann',
avatar: 'https://avatars.githubusercontent.com/u/12292047',
github: 'eps1lon',
},
mnajdova: {
name: 'Marija Najdova',
avatar: 'https://avatars.githubusercontent.com/u/4512430',
github: 'mnajdova',
},
michaldudak: {
name: 'Michał Dudak',
avatar: 'https://avatars.githubusercontent.com/u/4696105',
github: 'michaldudak',
},
siriwatknp: {
name: 'Siriwat Kunaporn',
avatar: 'https://avatars.githubusercontent.com/u/18292247',
github: 'siriwatknp',
},
'danilo-leal': {
name: 'Danilo Leal',
avatar: 'https://avatars.githubusercontent.com/u/67129314',
github: 'danilo-leal',
},
m4theushw: {
name: 'Matheus Wichman',
avatar: 'https://avatars.githubusercontent.com/u/42154031',
github: 'm4theushw',
},
flaviendelangle: {
name: 'Flavien Delangle',
avatar: 'https://avatars.githubusercontent.com/u/3309670',
github: 'flaviendelangle',
},
DanailH: {
name: 'Danail Hadjiatanasov',
avatar: 'https://avatars.githubusercontent.com/u/5858539',
github: 'DanailH',
},
alexfauquette: {
name: 'Alexandre Fauquette',
avatar: 'https://avatars.githubusercontent.com/u/45398769',
github: 'alexfauquette',
},
samuelsycamore: {
name: 'Sam Sycamore',
avatar: 'https://avatars.githubusercontent.com/u/71297412',
github: 'samuelsycamore',
},
josefreitas: {
name: 'José Freitas',
avatar: 'https://avatars.githubusercontent.com/u/550141',
github: 'joserodolfofreitas',
},
cherniavskii: {
name: 'Andrew Cherniavskyi',
avatar: 'https://avatars.githubusercontent.com/u/13808724',
github: 'cherniavskii',
},
};
const classes = {
back: 'TopLayoutBlog-back',
time: 'TopLayoutBlog-time',
container: 'TopLayoutBlog-container',
};
// Replicate the value used by https://medium.com/, a trusted reference.
const BLOG_MAX_WIDTH = 692;
const styles = ({ theme }) => ({
flexGrow: 1,
background:
theme.palette.mode === 'dark'
? `linear-gradient(180deg, ${theme.palette.primaryDark[900]} 0%, #001E3C 100%)`
: `linear-gradient(180deg, ${theme.palette.grey[50]} 0%, #FFFFFF 100%)`,
backgroundSize: '100% 300px',
backgroundRepeat: 'no-repeat',
[`& .${classes.back}`]: {
display: 'flex',
alignItems: 'center',
marginBottom: theme.spacing(2),
marginLeft: theme.spacing(-1),
},
[`& .${classes.container}`]: {
paddingTop: 60 + 20,
marginBottom: theme.spacing(12),
maxWidth: `calc(${BLOG_MAX_WIDTH}px + ${theme.spacing(2 * 2)})`,
[theme.breakpoints.up('md')]: {
maxWidth: `calc(${BLOG_MAX_WIDTH}px + ${theme.spacing(3 * 2)})`,
},
[theme.breakpoints.up('lg')]: {
maxWidth: `calc(${BLOG_MAX_WIDTH}px + ${theme.spacing(8 * 2)})`,
},
'& h1': {
marginBottom: theme.spacing(3),
},
'& .markdown-body': {
fontSize: theme.typography.pxToRem(16),
lineHeight: 1.7,
},
'& img, & video': {
display: 'block',
margin: 'auto',
},
'& strong': {
color: theme.palette.mode === 'dark' ? theme.palette.grey[100] : theme.palette.grey[900],
},
'& summary': {
padding: 8,
fontSize: theme.typography.pxToRem(14),
fontWeight: theme.typography.fontWeightMedium,
color: theme.palette.mode === 'dark' ? theme.palette.grey[300] : theme.palette.grey[900],
},
'& details': {
paddingLeft: 16,
paddingRight: 16,
background:
theme.palette.mode === 'dark'
? alpha(theme.palette.primary[900], 0.3)
: alpha(theme.palette.grey[50], 0.5),
border: '1px solid',
borderRadius: 10,
borderColor:
theme.palette.mode === 'dark' ? theme.palette.primaryDark[700] : theme.palette.grey[200],
transitionProperty: 'all',
transitionTiming: 'cubic-bezier(0.4, 0, 0.2, 1)',
transitionDuration: '200ms',
'&:hover, &:focus-visible': {
background:
theme.palette.mode === 'dark'
? alpha(theme.palette.primary[900], 0.4)
: theme.palette.grey[50],
borderColor:
theme.palette.mode === 'dark' ? theme.palette.primaryDark[500] : theme.palette.grey[300],
},
},
'& th': {
textAlign: 'left',
borderBottom: `3px solid rgba(62, 80, 96, 0.2) !important`,
},
'& .blog-description': {
fontSize: theme.typography.pxToRem(13),
textAlign: 'left',
color: theme.palette.grey[600],
'& a': {
color:
theme.palette.mode === 'dark' ? theme.palette.primary[300] : theme.palette.primary[600],
textDecoration: 'underline',
},
},
},
[`& .${classes.time}`]: {
color: theme.palette.text.secondary,
...theme.typography.caption,
fontWeight: 500,
},
});
const AuthorsContainer = styled('div')(({ theme }) => ({
display: 'flex',
flexWrap: 'wrap',
marginBottom: theme.spacing(2),
'& .author': {
display: 'flex',
alignItems: 'center',
paddingBottom: theme.spacing(2),
paddingRight: theme.spacing(3),
'& .MuiAvatar-root': {
marginRight: theme.spacing(1),
},
},
}));
const Root = styled('div')(styles);
function TopLayoutBlog(props) {
const { className, docs } = props;
const { description, rendered, title, headers } = docs.en;
const finalTitle = title || headers.title;
const router = useRouter();
const slug = router.pathname.replace(/\/blog\//, '');
const { canonicalAsServer } = pathnameToLanguage(router.asPath);
const card =
headers.card === 'true'
? `https://mui.com/static/blog/${slug}/card.png`
: 'https://mui.com/static/logo.png';
return (
<BrandingProvider>
<AppHeader />
<Head
title={`${finalTitle} - MUI`}
description={description}
largeCard={headers.card === 'true'}
disableAlternateLocale
card={card}
type="article"
/>
<Root className={className}>
<AppContainer component="main" className={classes.container}>
<Link
href={ROUTES.blog}
{...(ROUTES.blog.startsWith('http') && {
rel: 'nofollow',
})}
color="primary"
variant="body2"
className={classes.back}
>
<ChevronLeftRoundedIcon fontSize="small" sx={{ mr: 0.5 }} />
{/* eslint-disable-next-line material-ui/no-hardcoded-labels */}
{'Back to blog'}
</Link>
{headers.title ? (
<React.Fragment>
<time dateTime={headers.date} className={classes.time}>
{new Intl.DateTimeFormat('en', {
weekday: 'long',
year: 'numeric',
month: 'short',
day: 'numeric',
}).format(new Date(headers.date))}
</time>
<MarkdownElement>
<h1>{headers.title}</h1>
</MarkdownElement>
<AuthorsContainer>
{headers.authors.map((author) => (
<div key={author} className="author">
<Avatar
sx={{ width: 36, height: 36 }}
alt=""
src={`${authors[author].avatar}?s=${36}`}
srcSet={`${authors[author].avatar}?s=${36 * 2} 2x`}
/>
<div>
<Typography variant="body2" fontWeight="500">
{authors[author].name}
</Typography>
<Link
href={`https://github.com/${authors[author].github}`}
target="_blank"
rel="noreferrer noopener"
color="primary"
variant="body2"
sx={{ fontWeight: 500 }}
>
@{authors[author].github}
</Link>
</div>
</div>
))}
</AuthorsContainer>
</React.Fragment>
) : null}
{rendered.map((chunk, index) => {
return <MarkdownElement key={index} renderedMarkdown={chunk} />;
})}
</AppContainer>
<HeroEnd />
<Divider />
<AppFooter />
</Root>
<script
type="application/ld+json"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `
{
"@context": "https://schema.org",
"@type": "Article",
"publisher": {
"@type": "Organization",
"name": "MUI blog",
"url": "https://mui.com/blog/",
"logo": {
"@type": "ImageObject",
"url": "https://mui.com/static/icons/512x512.png"
}
},
"author": {
"@type": "Person",
"name": "${authors[headers.authors[0]].name}",
"image": {
"@type": "ImageObject",
"url": "${authors[headers.authors[0]].avatar}?s=${250}",
"width": 250,
"height": 250
},
"sameAs": [
"https://github.com/${authors[headers.authors[0]].github}"
]
},
"headline": "${finalTitle}",
"url": "https://mui.com${canonicalAsServer}",
"datePublished": "${headers.date}",
"dateModified": "${headers.date}",
"image": {
"@type": "ImageObject",
"url": "${card}",
"width": 1280,
"height": 640
},
"keywords": "${headers.tags.join(', ')}",
"description": "${description}",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://mui.com/blog/"
}
}
`,
}}
/>
</BrandingProvider>
);
}
TopLayoutBlog.propTypes = {
className: PropTypes.string,
docs: PropTypes.object.isRequired,
};
if (process.env.NODE_ENV !== 'production') {
TopLayoutBlog.propTypes = exactProp(TopLayoutBlog.propTypes);
}
export default TopLayoutBlog;