forked from radiantearth/stac-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkTab.vue
53 lines (50 loc) · 1.3 KB
/
LinkTab.vue
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
53
<template>
<div class="table-responsive links">
<table class="table table-striped">
<thead>
<tr>
<th>Link</th>
<th>Relation</th>
<th>Content-Type</th>
</tr>
</thead>
<tbody>
<tr v-for="(link, i) in links" :key="i">
<td>
<a
:href="link.href"
:rel="link.rel">{{ title(link) }}</a>
</td>
<td>
<code>{{ link.rel }}</code>
</td>
<td>
<code>{{ link.type }}</code>
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
export default {
name: "LinkTab",
props: ["links"],
methods: {
title(link) {
if (typeof link.title === 'string' && link.title.length > 0) {
return link.title;
}
else if (link.href.length > 50) {
return link.href.replace(/^\w+:\/\/([^\/]+)((\/[^\/\?]+)*\/([^\/\?]+)(\?.*)?)?$/ig, function(...x) {
if (x[4]) {
return x[1] + '/[…]/' + x[4]; // There are invisible zero-width whitespaces after and before the slashes. It allows breaking the link in the browser. Be careful when editing.
}
return x[1];
});
}
return link.href.replace(/^\w+:\/\//i, '');
}
}
};
</script>