Skip to content

Commit 9e21bca

Browse files
committed
Add Bootstrap img-responsive class
Will scale images to 100% width on mobile
1 parent 3a20ca8 commit 9e21bca

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

frog/enhance-body.rkt

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@
3535
(define (do-it xs)
3636
(for/list ([x xs])
3737
(match x
38-
[`(div ((class ,classes))
39-
(img ((src ,url) ,attrs ...))
38+
[`(div ([class ,classes])
39+
(img ([src ,url] ,attrs ...))
4040
,content ...)
4141
#:when (and (regexp-match #px"\\bfigure\\b" classes)
4242
(not (url-host (string->url url))))
4343
(let ([sizes-attr (assq 'sizes attrs)])
4444
`(div ([class ,classes])
45-
(img (,@(make-responsive url (cond [sizes-attr => second]
45+
(img ([class "img-responsive"] ; Bootstrap class
46+
,@(make-responsive url (cond [sizes-attr => second]
4647
[#t #f]))
4748
,@(if sizes-attr
4849
(remove sizes-attr attrs)
@@ -77,26 +78,28 @@
7778
(when magick-available?
7879
(test-equal? "Element-specific custom sizes attribute"
7980
(responsive-images
80-
'((div ((class "figure"))
81-
(img ((src "/img/1x1.gif")
82-
(sizes "some-custom-size-spec"))))))
81+
'((div ([class "figure"])
82+
(img ([src "/img/1x1.gif"]
83+
[sizes "some-custom-size-spec"])))))
8384
'((div ((class "figure"))
84-
(img ((src "/img/1x1.gif")
85-
(srcset "/img/1x1.gif 2w")
86-
(sizes "some-custom-size-spec"))))))
85+
(img ([class "img-responsive"]
86+
[src "/img/1x1.gif"]
87+
[srcset "/img/1x1.gif 2w"]
88+
[sizes "some-custom-size-spec"])))))
8789
(test-equal? "Image bigger than maximum size"
8890
(responsive-images
89-
'((div ((class "figure pull-right"))
90-
(img ((src "/img/1300px-image.gif") (alt "")))
91-
(p ((class "caption")) "some text"))))
91+
'((div ([class "figure pull-right"])
92+
(img ([src "/img/1300px-image.gif"] (alt "")))
93+
(p ([class "caption"]) "some text"))))
9294
`((div ((class "figure pull-right"))
93-
(img ((src "/img/resized/600/1300px-image.gif")
94-
(srcset
95+
(img ([class "img-responsive"]
96+
[src "/img/resized/600/1300px-image.gif"]
97+
[srcset
9598
,(string-join
9699
(for/list ([s (current-image-sizes)])
97100
(format "/img/resized/~a/1300px-image.gif ~aw" s s))
98-
", "))
99-
(sizes "(max-width: 1300px) 100vw, 1300px")
101+
", ")]
102+
[sizes "(max-width: 1300px) 100vw, 1300px"]
100103
(alt "")))
101104
(p ((class "caption")) "some text"))))
102105
(test-equal? "Image smaller than biggest size but bigger than smallest size"
@@ -105,7 +108,8 @@
105108
(img ((src "/img/800px-image.gif") (alt "")))
106109
(p ((class "caption")) "some text"))))
107110
`((div ((class "figure"))
108-
(img ((src ,(format "/img/resized/~a/800px-image.gif"
111+
(img ([class "img-responsive"]
112+
(src ,(format "/img/resized/~a/800px-image.gif"
109113
(current-image-default-size)))
110114
(srcset
111115
,(string-append
@@ -123,7 +127,8 @@
123127
(img ((src "/img/600px-image.gif") (alt "")))
124128
(p ((class "caption")) "some text"))))
125129
'((div ((class "figure"))
126-
(img ((src "/img/600px-image.gif")
130+
(img ([class "img-responsive"]
131+
(src "/img/600px-image.gif")
127132
(srcset "/img/resized/320/600px-image.gif 320w, /img/600px-image.gif 600w")
128133
(sizes "(max-width: 600px) 100vw, 600px")
129134
(alt "")))
@@ -134,7 +139,8 @@
134139
(img ((src "/img/1x1.gif") (alt ""))) ; Tiny image
135140
(p ((class "caption")) "some text"))))
136141
'((div ((class "figure"))
137-
(img ((src "/img/1x1.gif")
142+
(img ([class "img-responsive"]
143+
(src "/img/1x1.gif")
138144
(srcset "/img/1x1.gif 2w")
139145
(sizes "(max-width: 2px) 100vw, 2px")
140146
(alt "")))
@@ -250,6 +256,7 @@
250256
"&hide_thread=true"))))
251257
(define js (call/input-url oembed-url get-pure-port read-json))
252258
(define html ('html js))
259+
253260
(cond [html (~>> (with-input-from-string html read-html-as-xexprs)
254261
(append '(div ([class "embed-tweet"]))))]
255262
[else x])]

0 commit comments

Comments
 (0)