aboutsummaryrefslogtreecommitdiff
path: root/src/views/index.pug
blob: add4c8e7e99296848c4f4ce1d11922c435425377 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
include ../mixins/post
include ../mixins/sub
include ../mixins/header
include ../mixins/head
include ../utils
- var subs = []
doctype html
html
  +head()
  +subMgmt()
  script.
    function updateButton(sub) {
      var b = document.getElementById("button-container");
      b.innerHTML = '';

      const button = document.createElement("button");

      if (issub(sub)) {
         button.innerText = "unsubscribe";
         button.onclick = ()=>unsubscribe(sub);
      } else {
         button.innerText = "subscribe";
         button.onclick = ()=>subscribe(sub);
      }
      b.appendChild(button);
    }

    function toggleDetails(details_id) {
      var detailsElement = document.getElementById(details_id);
      if (detailsElement) {
        detailsElement.open = !detailsElement.open;
      }
    }

    document.addEventListener('DOMContentLoaded', ()=>updateButton("#{subreddit}"));
  body
    main#content
      +header()

      div.hero
        div.sub-title
          h1 
            a(href=`/r/${subreddit}`)
              | r/#{subreddit}
          div#button-container
        if about
          p #{about.public_description}
        details
          summary.sorting sorting by #{query.sort + (query.t?' '+query.t:'')}
          div.sort-opts
            a(href=`/r/${subreddit}?sort=hot`) hot
            a(href=`/r/${subreddit}?sort=new`) new
            a(href=`/r/${subreddit}?sort=rising`) rising
            a(href=`/r/${subreddit}?sort=top`) top
            a(href=`/r/${subreddit}?sort=top&t=day`) top day
            a(href=`/r/${subreddit}?sort=top&t=week`) top week
            a(href=`/r/${subreddit}?sort=top&t=month`) top month
            a(href=`/r/${subreddit}?sort=top&t=year`) top year
            a(href=`/r/${subreddit}?sort=top&t=all`) top all

      if posts
        each child in posts.posts
          +post(child.data)
        
        if posts.after
          div.footer
            div.footer-item
              - var newQuery = {...query, after: posts.after}
              a(href=`/r/${subreddit}?${encodeQueryParams(newQuery)}`) next ⟶