2020-10-16 11:17:50 -07:00
|
|
|
<template>
|
|
|
|
<span>
|
2020-10-18 02:43:56 -07:00
|
|
|
<img v-if="icon.startsWith('https://')" :src="icon" class="icon"/>
|
|
|
|
<Icon v-else :v="icon" :set="iconSet"/>
|
2020-10-16 11:17:50 -07:00
|
|
|
<a :href="link" target="_blank" rel="noopener">
|
|
|
|
{{text}}
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {clearUrl} from "../src/helpers";
|
|
|
|
|
|
|
|
const REGEX_TWITTER = '^https://twitter.com/([^/]+)';
|
2020-10-18 02:43:56 -07:00
|
|
|
const REGEX_CAKE = '^https://cake.avris.it/([bgoprc][A-E][0-6])$';
|
2020-10-16 11:17:50 -07:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
link: { required: true },
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
type() {
|
|
|
|
if (this.link.match(REGEX_TWITTER)) {
|
|
|
|
return 'twitter';
|
|
|
|
}
|
|
|
|
|
2020-10-18 02:43:56 -07:00
|
|
|
if (this.link.match(REGEX_CAKE)) {
|
|
|
|
return 'cake';
|
|
|
|
}
|
|
|
|
|
2020-10-16 11:17:50 -07:00
|
|
|
return 'other';
|
|
|
|
},
|
|
|
|
icon() {
|
|
|
|
return {
|
|
|
|
twitter: 'twitter',
|
2020-10-18 02:43:56 -07:00
|
|
|
cake: 'https://cake.avris.it/favicon.png',
|
2020-10-16 11:17:50 -07:00
|
|
|
other: 'globe-europe',
|
|
|
|
}[this.type];
|
|
|
|
},
|
|
|
|
iconSet() {
|
|
|
|
return {
|
|
|
|
twitter: 'b',
|
|
|
|
}[this.type] || 'l';
|
|
|
|
},
|
|
|
|
text() {
|
|
|
|
if (this.type === 'twitter') {
|
|
|
|
return this.link.match(REGEX_TWITTER)[1];
|
|
|
|
}
|
|
|
|
|
2020-10-18 02:43:56 -07:00
|
|
|
if (this.type === 'cake') {
|
|
|
|
return this.link.match(REGEX_CAKE)[1];
|
|
|
|
}
|
|
|
|
|
2020-10-16 11:17:50 -07:00
|
|
|
return clearUrl(this.link);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
2020-10-18 02:43:56 -07:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.icon {
|
|
|
|
height: 1em;
|
|
|
|
}
|
|
|
|
</style>
|