forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (43 loc) · 1.26 KB
/
index.js
File metadata and controls
52 lines (43 loc) · 1.26 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
import React from 'react';
import { Container, Row } from './elements';
function getFontFamily(search) {
const hashes = search.slice(search.indexOf('?') + 1).split('&');
const family = hashes
.find(hash => hash.split('=')[0] === 'family')
.split('=')[1];
return family.split('+').join(' ');
}
function getName(resource) {
if (resource.includes('https://fonts.googleapis.com/css')) {
return `${getFontFamily(resource)} (Google Fonts)`;
}
if (resource.endsWith('.css') || resource.endsWith('.js')) {
const match = resource.match(/.*\/(.*)/);
if (match && match[1]) {
return match[1];
}
}
// Add trailing / but no double one
const normalizedUrl = `${resource.replace(/\/$/g, '')}/`;
return normalizedUrl;
}
function ExternalResources({ sandbox }) {
const externalResources = sandbox.externalResources || [];
return (
<Container>
{externalResources.length > 0 && (
<>
{externalResources.map(dep => (
<Row key={dep}>
<span>{getName(dep)}</span>
<a href={dep} rel="nofollow noopener noreferrer" target="_blank">
open
</a>
</Row>
))}
</>
)}
</Container>
);
}
export default ExternalResources;