aboutsummaryrefslogtreecommitdiff
path: root/src/views/index.pug
blob: 8bbef651078a875f46be46e6a40aca46b7db2992 (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
include ../mixins/post
include ../mixins/sub
- var subs = []
doctype html
html
  head
    meta(charset='UTF-8')
    title reddit
    link(rel='stylesheet', href='/styles.css')
    script(src="https://cdn.dashjs.org/latest/dash.all.min.js")

  +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);
    }

    document.addEventListener('DOMContentLoaded', ()=>updateButton("#{subreddit}"));
  body
    main#content
      div.header
        div.header-item
          a(href=`/`) home
        div.header-item
          a(href=`/subs`) subscriptions
        div.header-item
          a(href=`/r/popular`) popular

      div.hero
        a(href=`/r/${subreddit}`)
          h1 r/#{subreddit}
        if about
          p #{about.public_description}
        div#button-container

      each child in posts.posts
        +post(child.data)

    script(src='https://unpkg.com/[email protected]')