FIX: Support emoji in "Popular Links"

This commit is contained in:
Robin Ward 2016-07-20 16:45:48 -04:00
parent 7c092b0fe0
commit 87b52e4cea
3 changed files with 11 additions and 7 deletions

View File

@ -1,5 +1,11 @@
import { createWidget } from 'discourse/widgets/widget';
import { emojiUrlFor } from 'discourse/lib/text';
import { emojiUrlFor, emojiUnescape } from 'discourse/lib/text';
import RawHtml from 'discourse/widgets/raw-html';
export function replaceEmoji(str) {
const escaped = emojiUnescape(Handlebars.Utils.escapeExpression(str));
return [new RawHtml({ html: `<span>${escaped}</span>` })];
}
export default createWidget('emoji', {
tagName: 'img.emoji',

View File

@ -1,8 +1,7 @@
import { iconNode } from 'discourse/helpers/fa-icon';
import { createWidget } from 'discourse/widgets/widget';
import { h } from 'virtual-dom';
import RawHtml from 'discourse/widgets/raw-html';
import { emojiUnescape } from 'discourse/lib/text';
import { replaceEmoji } from 'discourse/widgets/emoji';
export default createWidget('post-links', {
tagName: 'div.post-links-container',
@ -13,8 +12,7 @@ export default createWidget('post-links', {
},
linkHtml(link) {
const escapedTitle = emojiUnescape(Handlebars.Utils.escapeExpression(link.title));
const linkBody = [new RawHtml({ html: `<span>${escapedTitle}</span>` })];
const linkBody = replaceEmoji(link.title);
if (link.clicks) {
linkBody.push(h('span.badge.badge-notification.clicks', link.clicks.toString()));
}

View File

@ -2,6 +2,7 @@ import { createWidget } from 'discourse/widgets/widget';
import { h } from 'virtual-dom';
import { avatarImg, avatarFor } from 'discourse/widgets/post';
import { dateNode, numberNode } from 'discourse/helpers/node';
import { replaceEmoji } from 'discourse/widgets/emoji';
const LINKS_SHOWN = 5;
@ -115,8 +116,7 @@ createWidget('topic-map-link', {
},
html(attrs) {
if (attrs.title) { return attrs.title; }
return attrs.url;
return attrs.title ? replaceEmoji(attrs.title) : attrs.url;
}
});