Skip to content

Commit 9cb27e6

Browse files
authored
Merge pull request #149 from laurentmmeyer/feature/add-gist
F!!: add a way to render github gist
2 parents ef47010 + 8d57202 commit 9cb27e6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

‎components/RenderContent.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import React from 'react'
22
import rehypeReact, { ComponentProps, ComponentPropsWithNode } from 'rehype-react'
33
import unified from 'unified'
44
import { Node } from 'unist'
5+
import ReactGist from 'react-gist'
56

67
import { NextLink } from '@components/NextLink'
78
import { NextImage } from '@components/NextImage'
89

10+
const gist_regex = /https:\/\/gist.github.com\/\S+\/([a-f0-9]+)\.js/g
11+
12+
type ScriptNode = {
13+
src: string
14+
}
15+
916
/* eslint-disable react/display-name */
1017
const options = {
1118
createElement: React.createElement,
@@ -14,6 +21,15 @@ const options = {
1421
components: {
1522
Link: (props: ComponentProps) => <NextLink {...(props as ComponentPropsWithNode)} />,
1623
Image: (props: ComponentProps) => <NextImage {...(props as ComponentPropsWithNode)} />,
24+
script: (props: ComponentProps) => {
25+
const properties = props as ScriptNode
26+
const myRegexp = new RegExp(gist_regex);
27+
const match = myRegexp.exec(properties.src);
28+
if (!!match && match.length > 1){
29+
return <ReactGist id={match[1]}/>
30+
}
31+
return null;
32+
}
1733
},
1834
}
1935

‎package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"probe-image-size": "^7.2.2",
5454
"react": "17.0.2",
5555
"react-dom": "17.0.2",
56+
"react-gist": "^1.2.4",
5657
"react-is": "^17.0.2",
5758
"refractor": "^3.3.1",
5859
"rehype": "^11.0.0",

‎yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4036,6 +4036,11 @@ react-dom@17.0.2:
40364036
object-assign "^4.1.1"
40374037
scheduler "^0.20.2"
40384038

4039+
react-gist@^1.2.4:
4040+
version "1.2.4"
4041+
resolved "https://registry.yarnpkg.com/react-gist/-/react-gist-1.2.4.tgz#4ee71f24cc6f60836354e2ad6e30f6d24e06e0f7"
4042+
integrity sha512-uDgPJ08IJsl/7auK3CS53JKGC1P/X7tNCzo9k0r6D/5l+ilsxE1+SAaylJCh0aeyZoJOoxQikKU+MHsAvA9iFw==
4043+
40394044
react-is@17.0.2, react-is@^17.0.1, react-is@^17.0.2:
40404045
version "17.0.2"
40414046
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"

0 commit comments

Comments
 (0)