Add clickable image to comments and support for emojis

This commit is contained in:
Tissevert 2019-03-03 12:16:08 +01:00
parent 2c6be28d76
commit 7138680c91

View file

@ -53,16 +53,36 @@ function Metadata(modules) {
])]; ])];
} }
function getContent(descendant) {
return descendant.content.replace(/:([^: ]+):/g, function(pattern, shortcode) {
var emoji = descendant.emojis.find(function(e) {return e.shortcode == shortcode;});
if(emoji) {
return [
'<img title=', shortcode, ' alt=', shortcode, ' src=', emoji.url, ' class="emoji"/>'
].join('"');
} else {
return pattern;
}
});
}
function render(comments) { function render(comments) {
return comments.descendants.map(function(descendant) { return comments.descendants.map(function(descendant) {
return modules.dom.make('li', {}, [ return modules.dom.make('li', {}, [
modules.dom.make('a', {href: descendant.account.url}, [
modules.dom.make('img', {
src: descendant.account.avatar,
alt: descendant.account.username + "'s profile picture"
})
]),
modules.dom.make('div', { modules.dom.make('div', {
class: "metadata",
innerHTML: modules.template.render('metadata', { innerHTML: modules.template.render('metadata', {
author: author(descendant.account.url, descendant.account.username), author: author(descendant.account.url, descendant.account.username),
date: date(descendant.created_at) date: date(descendant.created_at)
}) })
}), }),
modules.dom.make('div', {innerHTML: descendant.content}) modules.dom.make('div', {innerHTML: getContent(descendant)})
]); ]);
}); });
} }
@ -103,6 +123,7 @@ function Metadata(modules) {
function get(key) { function get(key) {
return modules.dom.make('div', { return modules.dom.make('div', {
class: "metadata",
innerHTML: modules.template.render('metadata', { innerHTML: modules.template.render('metadata', {
author: author(key), author: author(key),
date: date(key), date: date(key),