-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmdx-components.jsx
More file actions
81 lines (68 loc) · 1.57 KB
/
Copy pathmdx-components.jsx
File metadata and controls
81 lines (68 loc) · 1.57 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
import Link from 'next/link'
import Image from 'next/image'
import React from 'react'
// highlight code blocks
// https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
// https://github.com/highlightjs/highlight.js/tree/main/src/languages
function a(props) {
let href = props.href
if (href.startsWith('/')) {
return (
<Link href={href} {...props}>
{props.children}
</Link>
)
}
if (href.startsWith('#')) {
return <a {...props} />
}
return <a target="_blank" rel="noopener noreferrer" {...props} />
}
function p(props) {
return (
<p className="font-light"> {props.children}</p>
)
}
const Video = props => {
let { size, pos, full, grid } = props
if (!size) size = 'md'
let margin = 'none'
if (pos === 'center') {
margin = '0 auto 0 auto'
}
const style = {
boxShadow: '0 0 1rem rgba(128, 128, 128, 0.2)',
borderRadius: '1rem',
margin
}
if (full) {
style.width = '100%'
}
if (grid) {
style.height = '100%'
style.margin = '1rem'
}
return (
<video {...props} style={style} className={`d-block blog-video-${size}`}></video>
)
}
const Img = ({ src, size, float }) => {
if (!size) size = 'sm'
return (
<div
className={`img-container blog-img-${size}`}
style={{ margin: `${float ? 'none' : '2rem auto 2rem auto'}`, maxWidth: `${float && '50rem'}` }}
>
<Image src={src} sizes="60vw" fill alt='image' quality={75} />
</div>
)
}
const components = {
a,
p,
Video,
Img,
}
export function useMDXComponents() {
return components
}