mirror of
https://codeberg.org/teddit/teddit.git
synced 2026-04-18 21:45:06 -04:00
Render link flairs
This commit is contained in:
@@ -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>`
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user