-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathGist.tsx
48 lines (42 loc) · 1.37 KB
/
Gist.tsx
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
import React from 'react'
import './paraiso-hljs.css'
import 'isomorphic-fetch'
import {Helmet} from 'react-helmet'
import Markdown from './Markdown'
import { RouteComponentProps } from 'react-router-dom'
import useFetch from './useFetch'
function useFetchGist(user:string, id: string) {
const url = `https://gist.githubusercontent.com/${user}/${id}/raw`
return useFetch(url)
}
type GistRouteParams = {
user: string
id: string
}
interface GistProps extends RouteComponentProps<GistRouteParams> {}
const Gist = (props: GistProps) => {
const { user, id } = props.match.params
const raw = useFetchGist(user, id)
const content = raw
? <Markdown raw={raw}/>
: <p>Loading…</p>
return (
<article className='mw7-ns center ph2 mv4'>
<Helmet>
<title>Gist.io • @{user}/{id}</title>
</Helmet>
<header className='mv4 f6'>
<a href={`https://github.com/${user}/`} target='_blank'>@ {user}</a> / <a href={`https://gist.github.com/${user}/${id}`} target='_blank'>{id}</a>
</header>
<div className='content f3-ns f4'>
{content}
</div>
<footer>
<div className='pt3 mt5 bt b--light-gray gray i'>
<a href='/'>gist.io</a> · writing for hackers · zero setup · publish in seconds
</div>
</footer>
</article>
)
}
export default Gist