2021-02-03 18:00:49 +01:00
|
|
|
<template>
|
|
|
|
<p>
|
2021-11-07 21:02:06 +01:00
|
|
|
<a dir="auto" :title="contact" v-if="configLink" :href="configLink.uri">{{
|
2021-02-03 18:00:49 +01:00
|
|
|
configLink.text
|
|
|
|
}}</a>
|
2021-11-07 21:02:06 +01:00
|
|
|
<span dir="auto" v-else-if="contact">{{ contact }}</span>
|
2022-07-12 10:55:28 +02:00
|
|
|
<span v-else>{{ t("contact uninformed") }}</span>
|
2021-02-03 18:00:49 +01:00
|
|
|
</p>
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed } from "vue";
|
|
|
|
import { useI18n } from "vue-i18n";
|
2021-02-03 18:00:49 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
contact?: string;
|
|
|
|
}>();
|
2021-02-03 18:00:49 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { t } = useI18n({ useScope: "global" });
|
2021-02-03 18:00:49 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const configLink = computed((): { uri: string; text: string } | null => {
|
|
|
|
if (!props.contact) return null;
|
|
|
|
if (isContactEmail.value) {
|
|
|
|
return {
|
|
|
|
uri: `mailto:${props.contact}`,
|
|
|
|
text: props.contact,
|
|
|
|
};
|
2021-02-03 18:00:49 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
if (isContactURL.value) {
|
|
|
|
return {
|
|
|
|
uri: props.contact,
|
|
|
|
text: urlToHostname(props.contact) ?? "Contact",
|
|
|
|
};
|
2021-02-03 18:00:49 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return null;
|
|
|
|
});
|
2021-02-03 18:00:49 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isContactEmail = computed((): boolean => {
|
|
|
|
return (props.contact ?? "").includes("@");
|
|
|
|
});
|
|
|
|
|
|
|
|
const isContactURL = computed((): boolean => {
|
|
|
|
return (props.contact ?? "").match(/^https?:\/\//g) !== null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const urlToHostname = (url: string): string | null => {
|
|
|
|
try {
|
|
|
|
return new URL(url).hostname;
|
|
|
|
} catch (e) {
|
|
|
|
return null;
|
2021-02-03 18:00:49 +01:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
};
|
2021-02-03 18:00:49 +01:00
|
|
|
</script>
|