Browse Source

Fixed an issue where emojis rendered improperly.

pull/182/head
Eric 9 months ago
parent
commit
990baa61fc
  1. 25
      src/custom-emojis.ts
  2. 4
      src/utils.ts

25
src/custom-emojis.ts

@ -1,5 +1,6 @@
import { BASE_PATH } from './isProduction';
import emojis from './emojis.json';
import { unique } from './utils';
const EMOJI_DIR_PATH = `${BASE_PATH}emojis/`;
@ -22,19 +23,17 @@ export const customEmojis = emojis
})
.flat();
export const emojiReplacements = emojis
.map(category => {
return category.emojis.map(path => {
const key = `${path.split('.')[0]}`;
return {
key,
val: `<img class="icon icon-navbar icon-emoji" src="${
EMOJI_DIR_PATH + path
}" tag="emote" title=":${key}:" alt=":${key}:" />`,
};
});
})
.flat();
const emojiPaths = unique(emojis.map(category => category.emojis).flat());
export const emojiReplacements = emojiPaths.map(path => {
const key = `${path.split('.')[0]}`;
return {
key,
val: `<img class="icon icon-navbar icon-emoji" src="${
EMOJI_DIR_PATH + path
}" tag="emote" title=":${key}:" alt=":${key}:" />`,
};
});
export function replaceEmojis(html) {
let newHtml = html;

4
src/utils.ts

@ -1211,3 +1211,7 @@ export function truncateAtWord(input: string, maxLength = 256): string {
if (input.length < maxLength) return input;
return input.replace(new RegExp(`^(.{${maxLength}}[^ ]*).*`), '$1...');
}
export function unique<T = any>(input: T[]): T[] {
return input.filter((value, index, array) => array.indexOf(value) === index);
}
Loading…
Cancel
Save