Skip to content

Commit 6cfd2d0

Browse files
committed
chore: add mdx embed lib
1 parent 609336e commit 6cfd2d0

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"gatsby-transformer-remark": "^5.14.0",
4444
"gatsby-transformer-sharp": "^4.13.0",
4545
"github-slugger": "^1.4.0",
46+
"mdx-embed": "^1.1.2",
4647
"prism-react-renderer": "^1.3.3",
4748
"react": "^17.0.1",
4849
"react-dom": "^17.0.1",

src/GlobalStyle.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ const GlobalStyle = createGlobalStyle`
226226
border-radius: 0.325rem;
227227
font-size: 80%;
228228
}
229+
230+
blockquote {
231+
font-size: 1rem;
232+
border-left: 0.2rem solid #333;
233+
margin: 1.5rem 0;
234+
padding: 0.5rem 0 0.5rem 1rem;
235+
236+
> p {
237+
margin: 0;
238+
}
239+
}
240+
241+
[data-change="add"] {
242+
background-color: #395d3f;
243+
}
229244
}
230245
`;
231246

src/components/MDX/CodeBlock.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,23 @@ const CodeBlock = ({ children }) => {
5151
<Pre className={className} style={style}>
5252
<code className='code-preview'>
5353
{tokens.map((line, i) => (
54-
<Line {...getLineProps({ line, key: i })}>
54+
<Line
55+
{...getLineProps({ line, key: i })}
56+
data-change={
57+
line
58+
.map(({ content }) => content)
59+
.join('')
60+
.startsWith('++')
61+
? 'add'
62+
: undefined
63+
}
64+
>
5565
<LineNo>{i + 1}</LineNo>
56-
{line.map((token, key) => (
57-
<LineContent {...getTokenProps({ token, key })} />
58-
))}
66+
{line
67+
.filter(({ content }, i) => i >= 2 || (content !== '++' && content !== '--'))
68+
.map((token, key) => (
69+
<LineContent {...getTokenProps({ token, key })} />
70+
))}
5971
</Line>
6072
))}
6173
</code>

src/pages/v/{mdx.slug}.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import { graphql } from 'gatsby';
22
import { MDXRenderer } from 'gatsby-plugin-mdx';
33
import { MDXProvider } from '@mdx-js/react';
44
import styled from 'styled-components';
5+
import { Tweet, CodeSandbox } from 'mdx-embed';
56

67
import Layout from '../../components/layout';
78
import SEO from '../../components/seo';
89
import CodeBlock from '../../components/MDX/CodeBlock';
910
import { H1, H2, H3, H4, H5, H6 } from '../../components/MDX/Title';
1011
import { A } from '../../components/MDX';
1112

13+
const components = {
14+
Tweet,
15+
CodeSandbox,
16+
};
17+
1218
const Container = styled.div`
1319
padding: 32px 0;
1420
@@ -75,6 +81,7 @@ function BlogPost({ data }) {
7581
h4: H4,
7682
h5: H5,
7783
h6: H6,
84+
...components,
7885
}}
7986
>
8087
<MDXRenderer headings={data.mdx.headings}>{data.mdx.body}</MDXRenderer>

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9134,6 +9134,11 @@ mdurl@^1.0.0:
91349134
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
91359135
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=
91369136

9137+
mdx-embed@^1.1.2:
9138+
version "1.1.2"
9139+
resolved "https://registry.yarnpkg.com/mdx-embed/-/mdx-embed-1.1.2.tgz#04468e8dcb3be9fe3e65207e88a83d2f76555a24"
9140+
integrity sha512-AAronHC/sh4py+RhJOuX8+9+lyUbJsmCLquXNPCEHZ0llPWjMuwls77hII/lWI2kwBSPZPahrqti8kGTv1pi1w==
9141+
91379142
meant@^1.0.3:
91389143
version "1.0.3"
91399144
resolved "https://registry.yarnpkg.com/meant/-/meant-1.0.3.tgz#67769af9de1d158773e928ae82c456114903554c"

0 commit comments

Comments
 (0)