aboutsummaryrefslogtreecommitdiff
path: root/src/mixins/comment.pug
blob: 3af1f53835631db4ed5f71992f3b6b92532b91d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
include ../utils

mixin infoContainer(data)
  div.comment-info-container
    div.info-item #{fmtnum(data.ups)}div.info-item u/#{data.author} #{data.is_submitter ? '(OP)' : ''}
    if data.collapsed_reason_code == "DELETED"
      div.info-item
        a(href=`https://undelete.pullpush.io${data.permalink}`) search on undelete
    div.info-item #{timeDifference(Date.now(), data.created * 1000)}

-
  function hasReplies(data) {
    return data.replies && data.replies.data && data.replies.data.children && data.replies.data.children.length > 0;
  }

mixin comment(com, isfirst)
  - var data = com.data
  - var kind = com.kind
  - var hasReplyData = hasReplies(data)
  
  if kind == "more"
    div(class=`${isfirst ? 'first' : ''}`)
      div.more #{data.count} more comments
  else
    div(class=`comment ${isfirst ? 'first' : ''}`)
      if hasReplyData
        details(id=`${data.id}` open="")
          summary.expand-comments
            +infoContainer(data)
          div.comment-body
            != data.body_html
    
          div.replies
            each reply in data.replies.data.children
              +comment(reply, false)
    
      else
        +infoContainer(data)
        div.comment-body
          != data.body_html