mirror of https://github.com/Lissy93/dashy.git
✨ Adds emoji icon feature
This commit is contained in:
parent
c747efefda
commit
b5116bbc01
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="item-icon">
|
<div class="item-icon">
|
||||||
<i v-if="iconType === 'font-awesome'" :class="`${icon} ${size}`" ></i>
|
<i v-if="iconType === 'font-awesome'" :class="`${icon} ${size}`" ></i>
|
||||||
|
<i v-else-if="iconType === 'emoji'" :class="`emoji-icon ${size}`" >{{getEmoji(iconPath)}}</i>
|
||||||
<img v-else-if="icon" :src="iconPath" @error="imageNotFound"
|
<img v-else-if="icon" :src="iconPath" @error="imageNotFound"
|
||||||
:class="`tile-icon ${size} ${broken ? 'broken' : ''}`"
|
:class="`tile-icon ${size} ${broken ? 'broken' : ''}`"
|
||||||
/>
|
/>
|
||||||
|
@ -12,6 +13,8 @@
|
||||||
import BrokenImage from '@/assets/interface-icons/broken-icon.svg';
|
import BrokenImage from '@/assets/interface-icons/broken-icon.svg';
|
||||||
import ErrorHandler from '@/utils/ErrorHandler';
|
import ErrorHandler from '@/utils/ErrorHandler';
|
||||||
import { faviconApi as defaultFaviconApi, faviconApiEndpoints } from '@/utils/defaults';
|
import { faviconApi as defaultFaviconApi, faviconApiEndpoints } from '@/utils/defaults';
|
||||||
|
import EmojiUnicodeRegex from '@/utils/EmojiUnicodeRegex';
|
||||||
|
import emojiLookup from '@/utils/emojis.json';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Icon',
|
name: 'Icon',
|
||||||
|
@ -52,6 +55,27 @@ export default {
|
||||||
if (splitPath.length >= 1) return validImgExtensions.includes(splitPath[1]);
|
if (splitPath.length >= 1) return validImgExtensions.includes(splitPath[1]);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
/* Determins if a given string is an emoji, and if so what type it is */
|
||||||
|
isEmoji(img) {
|
||||||
|
if (EmojiUnicodeRegex.test(img) && img.match(/./gu).length) { // Is a unicode emoji
|
||||||
|
return { isEmoji: true, emojiType: 'glyph' };
|
||||||
|
} else if (new RegExp(/^:.*:$/).test(img)) { // Is a shortcode emoji
|
||||||
|
return { isEmoji: true, emojiType: 'shortcode' };
|
||||||
|
} else if (img.substring(0, 2) === 'U+' && img.length === 7) {
|
||||||
|
return { isEmoji: true, emojiType: 'unicode' };
|
||||||
|
}
|
||||||
|
return { isEmoji: false, emojiType: '' };
|
||||||
|
},
|
||||||
|
/* Formats and gets emoji from unicode or shortcode */
|
||||||
|
getEmoji(emojiCode) {
|
||||||
|
const { emojiType } = this.isEmoji(emojiCode);
|
||||||
|
if (emojiType === 'shortcode') {
|
||||||
|
if (emojiLookup[emojiCode]) return emojiLookup[emojiCode];
|
||||||
|
} else if (emojiType === 'unicode') {
|
||||||
|
return String.fromCodePoint(parseInt(emojiCode.substr(2), 16));
|
||||||
|
}
|
||||||
|
return emojiCode; // Emoji is a glyph already, just return
|
||||||
|
},
|
||||||
/* Get favicon URL, for items which use the favicon as their icon */
|
/* Get favicon URL, for items which use the favicon as their icon */
|
||||||
getFavicon(fullUrl) {
|
getFavicon(fullUrl) {
|
||||||
if (this.shouldUseDefaultFavicon(fullUrl)) { // Check if we should use local icon
|
if (this.shouldUseDefaultFavicon(fullUrl)) { // Check if we should use local icon
|
||||||
|
@ -85,6 +109,7 @@ export default {
|
||||||
case 'favicon': return this.getFavicon(url);
|
case 'favicon': return this.getFavicon(url);
|
||||||
case 'generative': return this.getGenerativeIcon(url);
|
case 'generative': return this.getGenerativeIcon(url);
|
||||||
case 'svg': return img;
|
case 'svg': return img;
|
||||||
|
case 'emoji': return img;
|
||||||
default: return '';
|
default: return '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -98,6 +123,7 @@ export default {
|
||||||
else if (img.includes('fa-')) imgType = 'font-awesome';
|
else if (img.includes('fa-')) imgType = 'font-awesome';
|
||||||
else if (img === 'favicon') imgType = 'favicon';
|
else if (img === 'favicon') imgType = 'favicon';
|
||||||
else if (img === 'generative') imgType = 'generative';
|
else if (img === 'generative') imgType = 'generative';
|
||||||
|
else if (this.isEmoji(img).isEmoji) imgType = 'emoji';
|
||||||
else imgType = 'none';
|
else imgType = 'none';
|
||||||
return imgType;
|
return imgType;
|
||||||
},
|
},
|
||||||
|
@ -144,7 +170,17 @@ export default {
|
||||||
fill: currentColor;
|
fill: currentColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
i.emoji-icon {
|
||||||
|
font-style: normal;
|
||||||
|
font-size: 2rem;
|
||||||
|
margin: 0.2rem;
|
||||||
|
&.small {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
&.large {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
.missing-image {
|
.missing-image {
|
||||||
width: 3.5rem;
|
width: 3.5rem;
|
||||||
path {
|
path {
|
||||||
|
|
Loading…
Reference in New Issue