FIX: Support emoji in "Popular Links"
This commit is contained in:
parent
7c092b0fe0
commit
87b52e4cea
|
@ -1,5 +1,11 @@
|
||||||
import { createWidget } from 'discourse/widgets/widget';
|
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', {
|
export default createWidget('emoji', {
|
||||||
tagName: 'img.emoji',
|
tagName: 'img.emoji',
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { iconNode } from 'discourse/helpers/fa-icon';
|
import { iconNode } from 'discourse/helpers/fa-icon';
|
||||||
import { createWidget } from 'discourse/widgets/widget';
|
import { createWidget } from 'discourse/widgets/widget';
|
||||||
import { h } from 'virtual-dom';
|
import { h } from 'virtual-dom';
|
||||||
import RawHtml from 'discourse/widgets/raw-html';
|
import { replaceEmoji } from 'discourse/widgets/emoji';
|
||||||
import { emojiUnescape } from 'discourse/lib/text';
|
|
||||||
|
|
||||||
export default createWidget('post-links', {
|
export default createWidget('post-links', {
|
||||||
tagName: 'div.post-links-container',
|
tagName: 'div.post-links-container',
|
||||||
|
@ -13,8 +12,7 @@ export default createWidget('post-links', {
|
||||||
},
|
},
|
||||||
|
|
||||||
linkHtml(link) {
|
linkHtml(link) {
|
||||||
const escapedTitle = emojiUnescape(Handlebars.Utils.escapeExpression(link.title));
|
const linkBody = replaceEmoji(link.title);
|
||||||
const linkBody = [new RawHtml({ html: `<span>${escapedTitle}</span>` })];
|
|
||||||
if (link.clicks) {
|
if (link.clicks) {
|
||||||
linkBody.push(h('span.badge.badge-notification.clicks', link.clicks.toString()));
|
linkBody.push(h('span.badge.badge-notification.clicks', link.clicks.toString()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { createWidget } from 'discourse/widgets/widget';
|
||||||
import { h } from 'virtual-dom';
|
import { h } from 'virtual-dom';
|
||||||
import { avatarImg, avatarFor } from 'discourse/widgets/post';
|
import { avatarImg, avatarFor } from 'discourse/widgets/post';
|
||||||
import { dateNode, numberNode } from 'discourse/helpers/node';
|
import { dateNode, numberNode } from 'discourse/helpers/node';
|
||||||
|
import { replaceEmoji } from 'discourse/widgets/emoji';
|
||||||
|
|
||||||
const LINKS_SHOWN = 5;
|
const LINKS_SHOWN = 5;
|
||||||
|
|
||||||
|
@ -115,8 +116,7 @@ createWidget('topic-map-link', {
|
||||||
},
|
},
|
||||||
|
|
||||||
html(attrs) {
|
html(attrs) {
|
||||||
if (attrs.title) { return attrs.title; }
|
return attrs.title ? replaceEmoji(attrs.title) : attrs.url;
|
||||||
return attrs.url;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue