-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathTopLayoutBlog.js
443 lines (433 loc) · 14.2 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled, alpha } from '@mui/material/styles';
import { useTheme } from '@mui/system';
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 BrandingCssVarsProvider from 'docs/src/BrandingCssVarsProvider';
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 RichMarkdownElement from 'docs/src/modules/components/RichMarkdownElement';
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',
},
mikailaread: {
name: 'Mikaila Read',
avatar: 'https://avatars.githubusercontent.com/u/76401606',
github: 'mikailaread',
},
prakhargupta: {
name: 'Prakhar Gupta',
avatar: 'https://avatars.githubusercontent.com/u/92228082',
github: 'prakhargupta1',
},
richbustos: {
name: 'Rich Bustos',
avatar: 'https://avatars.githubusercontent.com/u/92274722',
github: 'richbustos',
},
colmtuite: {
name: 'Colm Tuite',
avatar: 'https://avatars.githubusercontent.com/u/805073',
github: 'colmtuite',
},
};
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 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')(
({ theme }) => ({
flexGrow: 1,
background: `linear-gradient(180deg, ${
(theme.vars || theme).palette.grey[50]
} 0%, #FFFFFF 100%)`,
backgroundSize: '100% 500px',
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': {
lineHeight: 1.7,
'& img, & video': {
border: '1px solid',
borderColor: (theme.vars || theme).palette.grey[200],
borderRadius: 12,
display: 'block',
margin: 'auto',
marginBottom: 16,
},
'& strong': {
color: (theme.vars || theme).palette.grey[900],
},
'& summary': {
padding: 8,
fontSize: theme.typography.pxToRem(14),
fontWeight: theme.typography.fontWeightMedium,
color: (theme.vars || theme).palette.grey[900],
},
'& details': {
paddingLeft: 16,
paddingRight: 16,
background: alpha(theme.palette.grey[50], 0.5),
border: '1px solid',
borderRadius: 10,
borderColor: (theme.vars || theme).palette.grey[200],
transitionProperty: 'all',
transitionTiming: 'cubic-bezier(0.4, 0, 0.2, 1)',
transitionDuration: '200ms',
'&:hover, &:focus-visible': {
background: (theme.vars || theme).palette.grey[50],
borderColor: (theme.vars || theme).palette.grey[300],
},
},
'& th': {
width: '100%',
textAlign: 'left',
borderBottom: `3px solid rgba(62, 80, 96, 0.2) !important`,
},
'& .blog-description': {
fontSize: theme.typography.pxToRem(13),
marginTop: 8,
textAlign: 'center',
color: (theme.vars || theme).palette.grey[700],
'& a': {
color: 'inherit',
textDecoration: 'underline',
},
},
'& .MuiCode-root + .blog-description': {
marginTop: -20 + 8,
},
},
[`& .${classes.time}`]: {
color: (theme.vars || theme).palette.text.secondary,
...theme.typography.caption,
fontWeight: 500,
},
}),
({ theme }) =>
theme.applyDarkStyles({
background: `linear-gradient(180deg, ${alpha(theme.palette.primary[900], 0.2)} 0%, ${
(theme.vars || theme).palette.primaryDark[900]
} 100%)`,
backgroundSize: '100% 1000px',
backgroundRepeat: 'no-repeat',
'& .markdown-body': {
'& strong': {
color: (theme.vars || theme).palette.grey[100],
},
'& summary': {
color: (theme.vars || theme).palette.grey[300],
},
'& img, & video': {
borderColor: alpha(theme.palette.primaryDark[600], 0.5),
},
'& details': {
background: alpha(theme.palette.primary[900], 0.3),
borderColor: (theme.vars || theme).palette.primaryDark[700],
'&:hover, &:focus-visible': {
background: alpha(theme.palette.primary[900], 0.4),
borderColor: (theme.vars || theme).palette.primaryDark[500],
},
},
'& .blog-description': {
color: (theme.vars || theme).palette.grey[500],
},
},
}),
);
export default function TopLayoutBlog(props) {
const theme = useTheme();
const { className, docs, demos, demoComponents, srcComponents } = props;
const { description, rendered, title, headers } = docs.en;
const finalTitle = title || headers.title;
const router = useRouter();
const slug = router.pathname.replace(/(.*)\/(.*)/, '$2');
const { canonicalAsServer } = pathnameToLanguage(router.asPath);
const card =
headers.card === 'true'
? `https://mui.com/static/blog/${slug}/card.png`
: 'https://mui.com/static/logo.png';
if (process.env.NODE_ENV !== 'production') {
if (headers.card === undefined) {
throw new Error(
[
`MUI: the "card" markdown header for the blog post "${slug}" is missing.`,
`Set card: true or card: false header in docs/pages/blog/${slug}.md.`,
].join('\n'),
);
}
}
return (
<BrandingCssVarsProvider>
<AppHeader />
<Head
title={`${finalTitle} - MUI`}
description={description}
largeCard={headers.card === 'true'}
disableAlternateLocale
card={card}
type="article"
>
<meta name="author" content={headers.authors.map((key) => authors[key].name).join(', ')} />
<meta property="article:published_time" content={headers.date} />
<script
type="application/ld+json"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: JSON.stringify({
'@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,
mainEntityOfPage: {
'@type': 'WebPage',
'@id': 'https://mui.com/blog/',
},
}),
}}
/>
</Head>
<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>
{/*
Depending on the timezone, the display date can change from one day to another.
e.g. Sunday vs. Monday
TODO: Move the date formating to the server.
*/}
<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, ${
authors[author].avatar
}?s=${36 * 3} 3x`}
/>
<div>
<Typography variant="body2" fontWeight="500">
{authors[author].name}
</Typography>
<Link
href={`https://github.com/${authors[author].github}`}
target="_blank"
rel="noopener"
color="primary"
variant="body2"
sx={{ fontWeight: 500 }}
>
@{authors[author].github}
</Link>
</div>
</div>
))}
</AuthorsContainer>
</React.Fragment>
) : null}
{rendered.map((chunk, index) => {
return (
<RichMarkdownElement
key={index}
demos={demos}
demoComponents={demoComponents}
srcComponents={srcComponents}
renderedMarkdown={chunk}
disableAd
localizedDoc={docs.en}
renderedMarkdownOrDemo={chunk}
theme={theme}
WrapperComponent={React.Fragment}
/>
);
})}
</AppContainer>
<Divider />
<HeroEnd />
<Divider />
<AppFooter />
</Root>
</BrandingCssVarsProvider>
);
}
TopLayoutBlog.propTypes = {
className: PropTypes.string,
demoComponents: PropTypes.object,
demos: PropTypes.object,
docs: PropTypes.object.isRequired,
srcComponents: PropTypes.object,
};
if (process.env.NODE_ENV !== 'production') {
TopLayoutBlog.propTypes = exactProp(TopLayoutBlog.propTypes);
}