Render link flairs

This commit is contained in:
StevenNMeza
2020-12-21 12:33:43 +01:00
parent 5057018fb6
commit fb202af1e5
6 changed files with 35 additions and 23 deletions
+23
View File
@@ -198,6 +198,29 @@ module.exports = function(request, fs) {
}
}
this.formatLinkFlair = (post) => {
const wrap = (inner) => `<span class="flair">${inner}</span>`
if (post.link_flair_text === null)
return ''
if (post.link_flair_type === 'text')
return wrap(post.link_flair_text)
if (post.link_flair_type === 'richtext') {
let flair = ''
for (let fragment of post.link_flair_richtext) {
if (fragment.e === 'text')
flair += fragment.t
else if (fragment.e === 'emoji')
flair += `<span class="emoji" style="background-image: url(${fragment.u})"></span>`
}
return wrap(flair)
}
return ''
}
this.formatUserFlair = (post) => {
// Generate the entire HTML here for consistency in both pug and HTML
const wrap = (inner) => `<span class="flair">${inner}</span>`
+1
View File
@@ -33,6 +33,7 @@ module.exports = function(fetch) {
images: null,
crosspost: false,
selftext: unescape(post.selftext_html),
link_flair: formatLinkFlair(post),
user_flair: formatUserFlair(post)
}
+1
View File
@@ -74,6 +74,7 @@ module.exports = function() {
stickied: data.stickied,
is_self_link: is_self_link,
subreddit_front: subreddit_front,
link_flair: formatLinkFlair(data),
user_flair: formatUserFlair(data)
}
ret.links.push(obj)