git.fiddlerwoaroof.com
Browse code

feat: update gallery demo

Ed Langley authored on 20/11/2019 18:34:14
Showing 1 changed files
... ...
@@ -7,6 +7,7 @@
7 7
                    :yason
8 8
                    :ningle
9 9
                    :lass))
10
+    (ql:quickload :fwoar.gallery)
10 11
     nil)
11 12
 
12 13
 (defpackage :fwoar.gallery
... ...
@@ -45,7 +46,9 @@
45 46
 (defmethod print-object ((o video) s)
46 47
   (format s "#.(make-video \"~a\")" (url o)))
47 48
 (defmethod print-object ((o gallery) s)
48
-  (format s "#.(make-gallery (~a images))" (length (images o))))
49
+  (if *print-readably*
50
+      (format s "#.(make-gallery (list ~{~a~^~%~22t~}))" (images o))
51
+      (format s "#.(make-gallery (~a images))" (length (images o)))))
49 52
 
50 53
 (defun make-image (url)
51 54
   (new 'image url))
... ...
@@ -95,10 +98,11 @@
95 98
     (make-image (puri:render-uri uri nil)))
96 99
   (:method ((site (eql :gfycat)) uri)
97 100
     (make-video
98
-     (format nil "~a.mp4"
101
+     (format nil "~a"
99 102
              (puri:render-uri
100 103
               (fw.lu:prog1-bind (uri (puri:copy-uri uri))
101
-                (setf (puri:uri-host uri) "giant.gfycat.com"))
104
+                (setf (puri:uri-host uri) "gfycat.com"
105
+                      (puri:uri-path uri) (format nil "/ifr~a" (puri:uri-path uri))))
102 106
               nil))))
103 107
   (:method ((site (eql :imgur)) uri)
104 108
     (make-image
... ...
@@ -108,7 +112,12 @@
108 112
                 (setf (puri:uri-host uri) "i.imgur.com"))
109 113
               nil))))
110 114
   (:method ((site (eql :vreddit)) uri)
111
-    (make-video (puri:render-uri uri nil))))
115
+    (make-video (puri:render-uri
116
+                 (fw.lu:prog1-bind (uri (puri:copy-uri uri))
117
+                   (setf (puri:uri-path uri)
118
+                         (format nil "~a/HLSPlaylist.m3u8"
119
+                                 (puri:uri-path uri))))
120
+                 nil))))
112 121
 
113 122
 (defun ensure-uri (uri)
114 123
   (etypecase uri
... ...
@@ -153,47 +162,30 @@
153 162
          :padding 0)
154 163
 
155 164
         (.gallery
156
-         :position relative
157
-         :column-count 4
158
-         :width 100vw
165
+         :display block
166
+         :background "#888"
159 167
          :height #(gallery-height)
160 168
          :overflow-y scroll
161
-         :background "#888"
169
+         :scroll-snap-type "y mandatory"
162 170
 
163 171
          :flex-wrap wrap)
164
-        ((.gallery > div)
165
-         :text-align center
166
-         :max-height 25vh
167
-         :overflow hidden)
172
+
168 173
         ((.gallery img)
169
-         :width 98%
170
-         :height 98%
171
-         :object-fit cover)
172
-        ((.gallery video)
173
-         :width 98%
174
-         :height 98%
174
+         :width 100%
175
+         :height 100%
176
+         :scroll-snap-align start
175 177
          :object-fit contain)
176
-        ((.gallery > div.expanded)
177
-         :position fixed
178
-         :top 0
179
-         :left 0
180
-         :max-height #(gallery-height)
178
+        ((.gallery video)
179
+         :width 100%
181 180
          :height 100%
181
+         :scroll-snap-align start
182
+         :object-fit contain)
183
+        ((.gallery iframe)
182 184
          :width 100%
183
-         :background "#eee")
184
-        ((.gallery > (:and div.expanded :before))
185
-         :content " "
186
-         :display inline-block
187
-         :vertical-align middle
188
-         :height 100%)
189
-        ((.gallery > div.expanded > img)
190
-         :display inline-block
191
-         :object-fit contain
192
-         :vertical-align middle
193
-         :height (calc (- 100vh 2em)))
194
-        ((.gallery > div.expanded > video)
195
-         :display inline-block
196
-         :vertical-align middle)))))
185
+         :height 100%
186
+         :scroll-snap-align start
187
+         :object-fit contain)
188
+        ))))
197 189
 
198 190
 (defun gallery-js ()
199 191
   (js
... ...
@@ -238,13 +230,16 @@
238 230
 
239 231
 (define-view root ((model image))
240 232
   (spinneret:with-html
241
-    (:div.image
242
-     (:img :src (url model)))))
233
+    (:img :src (url model))))
243 234
 
244 235
 (define-view root ((model video))
245 236
   (spinneret:with-html
246
-    (:div.image
247
-     (:video :autoplay "autoplay" :loop "loop" (:source :src (url model) :type "video/mp4")))))
237
+    (if (string-contains-p "/ifr/" (url model))
238
+        (:iframe :src (url model))
239
+        (:video :autoplay "autoplay"
240
+                :loop "loop"
241
+                (:source :src (url model)
242
+                         :type "video/mp4")))))
248 243
 
249 244
 (defun initialize-app (app gallery)
250 245
   (defroutes app
... ...
@@ -253,8 +248,8 @@
253 248
 (defun get-reddit-items (r)
254 249
   (process-uri-list
255 250
    (mapcar (lambda (i)
256
-             (fw.lu:pick '("data" "url") i))
257
-           (fw.lu:pick '("data" "children") r))))
251
+             (fw.lu:dive '("data" "url") i))
252
+           (fw.lu:dive '("data" "children") r))))
258 253
 
259 254
 (defun main (url)
260 255
   (let* ((app (make-instance 'ningle:<app>))