diff options
Diffstat (limited to 'src/views/index.pug')
-rw-r--r-- | src/views/index.pug | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/views/index.pug b/src/views/index.pug index d017570..f23405f 100644 --- a/src/views/index.pug +++ b/src/views/index.pug | |||
@@ -1,16 +1,56 @@ | |||
1 | - var subs = [] | ||
1 | doctype html | 2 | doctype html |
2 | html | 3 | html |
3 | head | 4 | head |
4 | meta(charset='UTF-8') | 5 | meta(charset='UTF-8') |
5 | title reddit | 6 | title reddit |
6 | link(rel='stylesheet', href='/styles.css') | 7 | link(rel='stylesheet', href='/styles.css') |
8 | script. | ||
9 | function getSubs() { | ||
10 | var store = localStorage.getItem('subs'); | ||
11 | if (store) { | ||
12 | return store.split(',').map((n)=>n.replace(/\/?r\//,'')); | ||
13 | } else { | ||
14 | return []; | ||
15 | } | ||
16 | } | ||
17 | |||
18 | function subscribe(newsub) { | ||
19 | var subs = getSubs(); | ||
20 | if (!subs.includes(newsub)) { | ||
21 | localStorage.setItem('subs',[...subs,newsub]); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | function newSubItem(newsub) { | ||
26 | var p = document.createElement("p"); | ||
27 | var text = document.createTextNode(newsub); | ||
28 | p.appendChild(text); | ||
29 | return p; | ||
30 | } | ||
31 | |||
32 | function genSubListing() { | ||
33 | const body = document.body; | ||
34 | const subbar = document.createElement('div'); | ||
35 | subbar.id = 'subscriptions'; | ||
36 | body.insertBefore(subbar, body.firstChild); | ||
37 | getSubs().forEach((item) => { | ||
38 | subbar.appendChild(newSubItem(item)); | ||
39 | }); | ||
40 | } | ||
41 | |||
42 | document.addEventListener('DOMContentLoaded', function() { | ||
43 | genSubListing(); | ||
44 | }); | ||
7 | body | 45 | body |
46 | |||
8 | main#content | 47 | main#content |
9 | div.header | 48 | div.header |
10 | a(href=`/r/#{subreddit}`) | 49 | a(href=`/r/${subreddit}`) |
11 | h1 r/#{subreddit} | 50 | h1 r/#{subreddit} |
12 | if about | 51 | if about |
13 | p #{about.public_description} | 52 | p #{about.public_description} |
53 | button(onclick=`subscribe("${subreddit}")`) subscribe | ||
14 | 54 | ||
15 | each child in posts.posts | 55 | each child in posts.posts |
16 | include post | 56 | include post |