This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/ProfileLink.vue

90 lines
2.4 KiB
Vue
Raw Normal View History

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