e621: use tagged template to suppress falsy expressions
This commit is contained in:
parent
7752274f0d
commit
8c29286ec7
1 changed files with 4 additions and 1 deletions
|
@ -70,6 +70,9 @@ const dom = data => {
|
|||
return el;
|
||||
};
|
||||
|
||||
// tagged template function to suppress falsy expressions
|
||||
const t = (strings, ...values) => String.raw({ raw: strings }, ...values.map(value => value || ''));
|
||||
|
||||
// augment results list with given posts
|
||||
const augment_results = (container, posts, link_params) => {
|
||||
let found, next;
|
||||
|
@ -79,7 +82,7 @@ const augment_results = (container, posts, link_params) => {
|
|||
next = found;
|
||||
} else {
|
||||
const post = posts[i];
|
||||
const el = dom(['article', { class: `post-preview captioned ${post.relationships.parent_id ? 'post-status-has-parent' : ''} ${post.relationships.has_active_children ? 'post-status-has-children' : ''} ${post.flags.pending ? 'post-status-pending' : ''} ${post.flags.flagged ? 'post-status-flagged' : ''} ${post.rating === 's' ? 'post-rating-safe' : post.rating === 'q' ? 'post-rating-questionable' : post.rating === 'e' ? 'post-rating-explicit' : ''}`, 'data-tags': post.tags.meta.includes('animated') ? 'animated' : null, 'data-file-ext': post.file.ext }, ['a', { href: `/posts/${post.id}${make_query(link_params)}` }, ['img', { src: get_preview_url(post), title: `Rating: ${post.rating}\nID: ${post.id}\nStatus: ${post.flags.deleted ? 'deleted' : post.flags.flagged ? 'flagged' : post.flags.pending ? 'pending' : 'active'}\nDate: ${post.created_at}\n\n${[...new Set(Object.values(post.tags).flat())].sort().join(' ')}` }]], ['div', { class: 'desc' }, ['div', { class: 'post-score' }, ['span', { class: `post-score-score ${post.score.total > 0 ? 'score-positive' : post.score.total < 0 ? 'score-negative' : 'score-neutral'}` }, `${post.score.total > 0 ? '↑' : post.score.total < 0 ? '↓' : '↕'}${post.score.total}`], ['span', { class: 'post-score-faves' }, `♥${post.fav_count}`], ['span', { class: 'post-score-comments' }, `C${post.comment_count}`], ['span', { class: 'post-score-rating' }, post.rating.toUpperCase()], ['span', { class: 'post-score-extras' }, `${post.relationships.parent_id ? 'P' : ''}${post.relationships.has_active_children ? 'C' : ''}${post.flags.pending ? 'U' : ''}${post.flags.flagged ? 'F' : ''}`]]]]);
|
||||
const el = dom(['article', { class: t`post-preview captioned ${post.relationships.parent_id && 'post-status-has-parent'} ${post.relationships.has_active_children && 'post-status-has-children'} ${post.flags.pending && 'post-status-pending'} ${post.flags.flagged && 'post-status-flagged'} post-rating-${{ s: 'safe', q: 'questionable', e: 'explicit' }[post.rating]}`, 'data-tags': post.tags.meta.includes('animated') ? 'animated' : null, 'data-file-ext': post.file.ext }, ['a', { href: `/posts/${post.id}${make_query(link_params)}` }, ['img', { src: get_preview_url(post), title: `Rating: ${post.rating}\nID: ${post.id}\nStatus: ${post.flags.deleted ? 'deleted' : post.flags.flagged ? 'flagged' : post.flags.pending ? 'pending' : 'active'}\nDate: ${post.created_at}\n\n${[...new Set(Object.values(post.tags).flat())].sort().join(' ')}` }]], ['div', { class: 'desc' }, ['div', { class: 'post-score' }, ['span', { class: `post-score-score score-${post.score.total > 0 ? 'positive' : post.score.total < 0 ? 'negative' : 'neutral'}` }, `${post.score.total > 0 ? '↑' : post.score.total < 0 ? '↓' : '↕'}${post.score.total}`], ['span', { class: 'post-score-faves' }, `♥${post.fav_count}`], ['span', { class: 'post-score-comments' }, `C${post.comment_count}`], ['span', { class: 'post-score-rating' }, post.rating.toUpperCase()], ['span', { class: 'post-score-extras' }, t`${post.relationships.parent_id && 'P'}${post.relationships.has_active_children && 'C'}${post.flags.pending && 'U'}${post.flags.flagged && 'F'}`]]]]);
|
||||
container.insertBefore(el, next);
|
||||
next = el;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue