aboutsummaryrefslogtreecommitdiff
path: root/src/mixins/postUtils.pug
blob: 816adf71c5c8e412ceaa3fd8a348de1878defe3b (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
-
  function isPostGallery(p) {
    return (p.is_gallery && p.is_gallery == true);
  }
-
  function isPostImage(p) {
    const imgRe = /\.(png|jpg|jpeg|gif|webp|bmp|tiff|svg)$/i;
    return (p.post_hint == "image" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default")
      || imgRe.test(p.url);
  }
-
  function postThumbnail(p) {
    if (p.thumbnail == "image" || p.thumbnail == "") {
        return p.url;
    } else if (p.over_18) {
        return "/nsfw.svg";
    } else if (p.thumbnail == "spoiler") {
        return "/spoiler.svg";
    } 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;
    }
  }