selfhostable, read-only reddit client
at main 66 lines 2.7 kB view raw
1include ../utils 2include postUtils 3 4mixin infoContainer(data, next_id, prev_id) 5 - var hats = (data.is_submitter?['op']:[]).concat(data.distinguished=="moderator"?['mod']:[]) 6 div.comment-info-container 7 p 8 | #{fmtnum(data.ups)} ↑ 9 | ·&nbsp; 10 if next_id 11 a(href=`#${next_id}` title="scroll to next comment").nav-link next 12 | &nbsp;·&nbsp; 13 if prev_id 14 a(href=`#${prev_id}` title="scroll to previous comment").nav-link prev 15 | &nbsp;·&nbsp; 16 if data.gilded > 0 17 span.gilded 18 | #{data.gilded} ☆ 19 | &nbsp;·&nbsp; 20 span(class=`${data.is_submitter ? 'op' : ''}`) 21 | u/#{data.author} #{hats.length==0?'':`(${hats.join('|')})`} 22 | &nbsp;·&nbsp; 23 if data.collapsed_reason_code == "DELETED" || data.author == "[deleted]" 24 a(href=`https://undelete.pullpush.io${data.permalink}`) search on undelete 25 | &nbsp;·&nbsp; 26 | #{timeDifference(Date.now(), data.created * 1000)} 27 | &nbsp;·&nbsp; 28 if data.edited !== false 29 | edited #{timeDifference(Date.now(), data.edited * 1000)} ago 30 | &nbsp;·&nbsp; 31 if data.stickied 32 | stickied 33 | &nbsp;·&nbsp; 34 a(href=`https://reddit.com${data.permalink}` title="view on reddit").nav-link open ↗ 35 36- 37 function hasReplies(data) { 38 return data.replies && data.replies.data && data.replies.data.children && data.replies.data.children.length > 0; 39 } 40 41mixin comment(com, isfirst, parent_id, next_id, prev_id) 42 - var data = com.data 43 - var hasReplyData = hasReplies(data) 44 45 if com.kind == "more" 46 div(class=`more ${isfirst ? 'first' : ''}`) 47 a(href=`/comments/${parent_id}/comment/${data.id}`) 48 | #{data.count} more #{fmttxt(data.count, 'comment')} 49 else 50 div(class=`comment ${isfirst ? 'first' : ''} ${data.stickied ? 'sticky' : ''}`) 51 details(id=`${data.id}` open="") 52 summary.expand-comments 53 +infoContainer(data, next_id, prev_id) 54 div.comment-body 55 != convertInlineImageLinks(data.body_html) 56 if hasReplyData 57 div.replies 58 - var total = data.replies.data.children.length 59 each reply, index in data.replies.data.children 60 - var next_idx = index + 1 61 - var prev_idx = index - 1 62 - var next_com = next_idx < total ? data.replies.data.children[next_idx] : null 63 - var prev_com = prev_idx >= 0 ? data.replies.data.children[prev_idx] : null 64 - var next_id = next_com ? next_com.data.id : null 65 - var prev_id = prev_com ? prev_com.data.id : null 66 +comment(reply, false, parent_id, next_id, prev_id)