Libravatar.vue 769 B

1234567891011121314151617181920212223242526272829303132
  1. <template>
  2. <img v-bind:src="getAvatar(email)"/>
  3. </template>
  4. <script>
  5. export default {
  6. name: "Libravatar",
  7. data() {
  8. return {
  9. }
  10. },
  11. props: ["email","size"],
  12. methods: {
  13. getAvatar: function(email) {
  14. let hexval = this.getHash(email);
  15. return `https://www.libravatar.org/avatar/${hexval}?s=${this.size}`;
  16. },
  17. getHash: function(text) {
  18. try {
  19. const crypto = require('crypto');
  20. const hash = crypto.createHash('sha256')
  21. .update(text)
  22. .digest('hex');
  23. return hash;
  24. } catch (err) {
  25. console.log('crypto support is disabled!');
  26. }
  27. }
  28. }
  29. }
  30. </script>