aboutsummaryrefslogtreecommitdiff
path: root/src/mixins/postUtils.pug
blob: 555e3880f18c747a0088f222201b45ee4cab9466 (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
-
  function isPostGallery(p) {
    return (p.is_gallery && p.is_gallery == true);
  }
-
  function isPostImage(p) {
    return (p.post_hint == "image" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default");
  }
-
  function postThumbnail(p) {
    if (p.thumbnail == "image") {
        return p.url
    } else {
        return p.thumbnail;
    }
  }
-
  function isPostVideo(p) {
    return (p.post_hint == "hosted:video");
  }
-
  function isPostLink(p) {
    return (p.post_hint == "link");
  }
-
  function imgExt(p, id) {
    var metadata = p.media_metadata;
    if (metadata[id].status == 'valid') {
      return stripPrefix(metadata[id].m, "image/");
    } else {
      // dosent matter
      return 'jpg';
    }
  }
-
  function postGalleryItems(p) {
    if (p.gallery_data && p.gallery_data.items) {
      return p.gallery_data.items.map((item, idx) => ({
        id: item.media_id,
        url: `https://i.redd.it/${item.media_id}.${imgExt(p, item.media_id)}`,
        total: p.gallery_data.items.length,
        idx: idx+1,
      }));
    } else {
      return null;
    }
  }