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/Avatar.vue

32 lines
838 B
Vue
Raw Normal View History

2020-10-15 15:41:41 -07:00
<template>
<img :src="gravatar" alt="" class="rounded-circle"/>
2020-10-15 15:41:41 -07:00
</template>
<script>
import md5 from 'js-md5';
import { Base64 } from 'js-base64';
export default {
props: {
user: { required: true },
size: { 'default': 128 }
2020-10-15 15:41:41 -07:00
},
computed: {
2020-10-15 15:41:41 -07:00
gravatar(email, size = 128) {
const fallback = `https://avi.avris.it/${this.size}/${Base64.encode(this.user.username).replace(/\+/g, '-').replace(/\//g, '_')}.png`;
2020-10-15 15:41:41 -07:00
return `https://www.gravatar.com/avatar/${this.user.emailHash || md5(this.user.email)}?d=${encodeURIComponent(fallback)}&s=${this.size}`;
2020-10-15 15:41:41 -07:00
}
},
}
</script>
<style lang="scss" scoped>
$size: 6rem;
img {
width: 100%;
max-width: $size;
max-height: $size;
}
</style>