2020-10-16 11:17:50 -07:00
|
|
|
<template>
|
|
|
|
<span>
|
2020-10-25 05:05:52 -07:00
|
|
|
<img v-if="provider.icon.startsWith('https://')" :src="provider.icon" class="icon"/>
|
|
|
|
<Icon v-else :v="provider.icon" :set="provider.iconSet || 'l'"/>
|
2020-10-16 11:17:50 -07:00
|
|
|
<a :href="link" target="_blank" rel="noopener">
|
2020-10-25 05:05:52 -07:00
|
|
|
{{provider.text}}
|
2020-10-16 11:17:50 -07:00
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {clearUrl} from "../src/helpers";
|
|
|
|
|
2020-10-25 05:05:52 -07:00
|
|
|
const LINK_PROVIDERS = {
|
|
|
|
twitter: {
|
2020-11-09 13:49:36 -08:00
|
|
|
regex: '^https?://(?:www.)?twitter.com/([^/]+)',
|
2020-10-25 05:05:52 -07:00
|
|
|
icon: 'twitter',
|
|
|
|
iconSet: 'b',
|
|
|
|
},
|
2020-11-09 13:49:36 -08:00
|
|
|
facebook: {
|
|
|
|
regex: '^https?://(?:www.)?facebook.com/([^/]+)',
|
|
|
|
icon: 'facebook',
|
|
|
|
iconSet: 'b',
|
|
|
|
},
|
|
|
|
instagram: {
|
|
|
|
regex: '^https?://(?:www.)?instagram.com/([^/]+)',
|
|
|
|
icon: 'instagram',
|
|
|
|
iconSet: 'b',
|
|
|
|
},
|
2020-10-25 05:05:52 -07:00
|
|
|
email: {
|
|
|
|
regex: '^mailto:([^/]+)',
|
|
|
|
icon: 'envelope',
|
|
|
|
},
|
|
|
|
reddit: {
|
2020-11-09 13:49:36 -08:00
|
|
|
regex: '^https?://(?:www.)?reddit.com/u/([^/]+)',
|
2020-10-25 05:05:52 -07:00
|
|
|
icon: 'reddit',
|
|
|
|
iconSet: 'b',
|
|
|
|
},
|
|
|
|
telegram: {
|
2020-11-09 13:49:36 -08:00
|
|
|
regex: '^https?://(?:www.)?t.me/([^/]+)',
|
2020-10-25 05:05:52 -07:00
|
|
|
icon: 'telegram',
|
|
|
|
iconSet: 'b',
|
|
|
|
},
|
|
|
|
paypal: {
|
2020-11-09 13:49:36 -08:00
|
|
|
regex: '^https?://(?:www.)?paypal.me/([^/]+)',
|
2020-10-25 05:05:52 -07:00
|
|
|
icon: 'paypal',
|
|
|
|
iconSet: 'b',
|
|
|
|
},
|
|
|
|
cake: {
|
|
|
|
regex: '^https://cake.avris.it/([bgoprc][A-E][0-6])$',
|
|
|
|
icon: 'https://cake.avris.it/favicon.png',
|
|
|
|
},
|
|
|
|
};
|
2020-10-16 11:17:50 -07:00
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
link: { required: true },
|
|
|
|
},
|
|
|
|
computed: {
|
2020-10-25 05:05:52 -07:00
|
|
|
provider() {
|
|
|
|
for (let name in LINK_PROVIDERS) {
|
|
|
|
if (!LINK_PROVIDERS.hasOwnProperty(name)) { continue; }
|
|
|
|
const provider = LINK_PROVIDERS[name];
|
|
|
|
const m = this.link.match(provider.regex);
|
|
|
|
if (m) {
|
|
|
|
return {
|
|
|
|
...provider,
|
|
|
|
text: m[1],
|
|
|
|
};
|
|
|
|
}
|
2020-10-18 02:43:56 -07:00
|
|
|
}
|
|
|
|
|
2020-10-16 11:17:50 -07:00
|
|
|
return {
|
2020-10-25 05:05:52 -07:00
|
|
|
icon: 'globe-europe',
|
|
|
|
text: clearUrl(this.link),
|
2020-10-18 02:43:56 -07:00
|
|
|
}
|
2020-10-16 11:17:50 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
2020-10-18 02:43:56 -07:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.icon {
|
|
|
|
height: 1em;
|
|
|
|
}
|
|
|
|
</style>
|