@@ -33,111 +33,110 @@ export const LinkRenderer = ({ href }: { href: string }) => {
33
33
}
34
34
} , [ href ] )
35
35
36
- if ( url ) {
37
- switch ( true ) {
38
- case isTweetUrl ( url ) : {
39
- const id = getTweetId ( url )
36
+ if ( ! url ) {
37
+ return (
38
+ < p >
39
+ < MLink href = { href } >
40
+ < span > { href } </ span >
41
+ </ MLink >
42
+ </ p >
43
+ )
44
+ }
45
+ switch ( true ) {
46
+ case isTweetUrl ( url ) : {
47
+ const id = getTweetId ( url )
40
48
41
- return < Tweet id = { id } />
42
- }
49
+ return < Tweet id = { id } />
50
+ }
43
51
44
- case isGithubRepoUrl ( url ) : {
45
- const { owner, repo } = parseGithubRepoUrl ( url )
46
- return < LinkCard id = { `${ owner } /${ repo } ` } source = "gh" />
47
- }
52
+ case isGithubRepoUrl ( url ) : {
53
+ const { owner, repo } = parseGithubRepoUrl ( url )
54
+ return < LinkCard id = { `${ owner } /${ repo } ` } source = "gh" />
55
+ }
48
56
49
- case isYoutubeUrl ( url ) : {
50
- const id = url . searchParams . get ( 'v' ) !
51
- return (
52
- < FixedRatioContainer >
53
- < iframe
54
- src = { `https://www.youtube.com/embed/${ id } ` }
55
- className = "absolute inset-0 h-full w-full border-0"
56
- allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
57
- allowFullScreen
58
- title = "YouTube video player"
59
- />
60
- </ FixedRatioContainer >
61
- )
62
- }
63
- case isGistUrl ( url ) : {
64
- const { owner, id } = parseGithubGistUrl ( url )
65
- return (
66
- < >
67
- < iframe
68
- src = { `https://gist.github.com/${ owner } /${ id } .pibb` }
69
- className = "h-[300px] w-full overflow-auto border-0"
70
- />
57
+ case isYoutubeUrl ( url ) : {
58
+ const id = url . searchParams . get ( 'v' ) !
59
+ return (
60
+ < FixedRatioContainer >
61
+ < iframe
62
+ src = { `https://www.youtube.com/embed/${ id } ` }
63
+ className = "absolute inset-0 h-full w-full border-0"
64
+ allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
65
+ allowFullScreen
66
+ title = "YouTube video player"
67
+ />
68
+ </ FixedRatioContainer >
69
+ )
70
+ }
71
+ case isGistUrl ( url ) : {
72
+ const { owner, id } = parseGithubGistUrl ( url )
73
+ return (
74
+ < >
75
+ < iframe
76
+ src = { `https://gist.github.com/${ owner } /${ id } .pibb` }
77
+ className = "h-[300px] w-full overflow-auto border-0"
78
+ />
71
79
72
- < a
73
- className = "mt-2 flex space-x-2 center"
74
- href = { href }
75
- target = "_blank"
76
- rel = "noreferrer"
77
- >
78
- < GitHubBrandIcon />
79
- < span > { href } </ span >
80
- </ a >
81
- </ >
82
- )
83
- }
80
+ < a
81
+ className = "mt-2 flex space-x-2 center"
82
+ href = { href }
83
+ target = "_blank"
84
+ rel = "noreferrer"
85
+ >
86
+ < GitHubBrandIcon />
87
+ < span > { href } </ span >
88
+ </ a >
89
+ </ >
90
+ )
91
+ }
84
92
85
- case isGithubCommitUrl ( url ) : {
86
- const { owner, repo, id } = parseGithubTypedUrl ( url )
87
- return (
88
- < >
89
- < p >
90
- < MLink href = { href } > { href } </ MLink >
91
- </ p >
92
- < LinkCard id = { `${ owner } /${ repo } /commit/${ id } ` } source = "gh-commit" />
93
- </ >
94
- )
95
- }
96
- case isGithubFilePreviewUrl ( url ) : {
97
- const { owner, repo, afterTypeString } = parseGithubTypedUrl ( url )
98
- const splitString = afterTypeString . split ( '/' )
99
- const ref = splitString [ 0 ]
100
- const path = ref ? splitString . slice ( 1 ) . join ( '/' ) : afterTypeString
101
- return (
102
- < >
93
+ case isGithubCommitUrl ( url ) : {
94
+ const { owner, repo, id } = parseGithubTypedUrl ( url )
95
+ return (
96
+ < >
97
+ < p >
103
98
< MLink href = { href } > { href } </ MLink >
104
- < EmbedGithubFile
105
- owner = { owner }
106
- repo = { repo }
107
- path = { path }
108
- refType = { ref }
109
- />
110
- </ >
111
- )
112
- }
113
- case isCodesandboxUrl ( url ) : {
114
- // https://codesandbox.io/s/framer-motion-layoutroot-prop-forked-p39g96
115
- // to
116
- // https://codesandbox.io/embed/framer-motion-layoutroot-prop-forked-p39g96?fontsize=14&hidenavigation=1&theme=dark
117
- return (
118
- < FixedRatioContainer >
119
- < iframe
120
- className = "absolute inset-0 h-full w-full rounded-md border-0"
121
- src = { `https://codesandbox.io/embed/${ url . pathname . slice (
122
- 2 ,
123
- ) } ?fontsize=14&hidenavigation=1&theme=dark${ url . search } `}
124
- />
125
- </ FixedRatioContainer >
126
- )
127
- }
128
- case isSelfArticleUrl ( url ) : {
129
- return < LinkCard source = "self" id = { url . pathname . slice ( 1 ) } />
130
- }
99
+ </ p >
100
+ < LinkCard id = { `${ owner } /${ repo } /commit/${ id } ` } source = "gh-commit" />
101
+ </ >
102
+ )
103
+ }
104
+ case isGithubFilePreviewUrl ( url ) : {
105
+ const { owner, repo, afterTypeString } = parseGithubTypedUrl ( url )
106
+ const splitString = afterTypeString . split ( '/' )
107
+ const ref = splitString [ 0 ]
108
+ const path = ref ? splitString . slice ( 1 ) . join ( '/' ) : afterTypeString
109
+ return (
110
+ < >
111
+ < MLink href = { href } > { href } </ MLink >
112
+ < EmbedGithubFile
113
+ owner = { owner }
114
+ repo = { repo }
115
+ path = { path }
116
+ refType = { ref }
117
+ />
118
+ </ >
119
+ )
120
+ }
121
+ case isCodesandboxUrl ( url ) : {
122
+ // https://codesandbox.io/s/framer-motion-layoutroot-prop-forked-p39g96
123
+ // to
124
+ // https://codesandbox.io/embed/framer-motion-layoutroot-prop-forked-p39g96?fontsize=14&hidenavigation=1&theme=dark
125
+ return (
126
+ < FixedRatioContainer >
127
+ < iframe
128
+ className = "absolute inset-0 h-full w-full rounded-md border-0"
129
+ src = { `https://codesandbox.io/embed/${ url . pathname . slice (
130
+ 2 ,
131
+ ) } ?fontsize=14&hidenavigation=1&theme=dark${ url . search } `}
132
+ />
133
+ </ FixedRatioContainer >
134
+ )
135
+ }
136
+ case isSelfArticleUrl ( url ) : {
137
+ return < LinkCard source = "self" id = { url . pathname . slice ( 1 ) } />
131
138
}
132
139
}
133
- // fallback to default renderer
134
- return (
135
- < p >
136
- < MLink href = { href } >
137
- < span > { href } </ span >
138
- </ MLink >
139
- </ p >
140
- )
141
140
}
142
141
143
142
const FixedRatioContainer = ( {
0 commit comments