-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyles.rkt
297 lines (252 loc) · 6.4 KB
/
styles.rkt
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#lang at-exp racket/base
(require "lowkey/css.rkt"
racket/match
racket/format
racket/string)
(provide (all-defined-out))
;; Provides styles and attributes to use in HTML destined to be sent as the content of an email.
;; Helpers and constants
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(define accent-color "#71862D")
(define link-color "#71862D") ; AABA16?
(define font-size '(font-size "17px"))
(define line-height '(line-height "25px"))
(define font-fam '(font-family "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'"))
(define heading-font '(font-family "'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif"))
(define code-font '(font-family "ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace"))
;; Styles
;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; Email clients, you may know, are not only stupid when it comes to rendering HTML, they are all
;; stupid in their own unique ways. To counteract this, we not only inline a stylesheet within
;; the <head> of the HTML document, we also squirt styles into the style attribute of almost every
;; single tag.
;; Here we construct a reference of these styles in such a way that they can be grabbed for use
;; in individual tags by the renderer (email-renderer.rkt), as well as duplicated in the main
;; stylesheet.
(define attr
(make-attr-ref
`(body
,(style (zero 'margin)
(zero 'padding)
font-fam
line-height
'(color "#111")
'(background-color "#fff")
'(-webkit-font-smoothing antialiased)
'(-webkit-text-size-adjust none)
'(width "100%")
'(height "100%")
'(min-height "100%")
'(position relative)
'(font-variation-settings "'wdth' 95")))
`(div.content
(class "content")
,(style '(margin "0 auto 0 auto")
'(width "600px")
'(max-width "100%")
'(padding "25px 8px 25px 8px")))
`(div.web
(class "web")
,(style '(margin "0 0 25px 0")
'(width "100%")
'(text-align right)
'(color "#666")))
`(p
,(style '(margin "0 0 25px 0")
(zero 'padding)
font-size
line-height
font-fam))
`(h2
,(style '(margin "0 auto 25px auto")
line-height
`(color ,accent-color)
heading-font
'(font-size "24px")
'(font-style italic)
'(font-weight bold)))
`(a
,(style `(color ,link-color)))
`(blockquote
,(style '(margin "0 0 0 25px")
'(color "#625F50")))
`(div.figure
(class "figure")
,(style '(margin "0 auto 25px auto")
'(display block)
'(width "600px")
'(max-width "100%")))
`(img
(loading "eager")
(decoding "async")
,(style '(box-shadow "0 0 13px rgba(0, 0, 0, 0.125);")
'(border none)
'(display block)
'(width "100%")
'(max-width "100%")
'(height auto)
'(margin "0 0 13px 0")
(zero 'padding)))
`(div.figcaption
,(style (zero 'margin)
(zero 'padding)
'(display block)
font-fam
'(font-size "13px")
'(line-height "13px")
'(text-align right)
'(color "#666")
'(width "100%")
'(height "auto")
'(max-width "100%")))
`(hr
,(style '(border none)
'(outline none)
`(border-bottom ,(format "1px solid ~a" link-color))
'(margin "2rem 0 2rem 0")))
`(p.meta
(class "meta")
,(style '(margin "0 auto 25px auto")
'(padding "17px")
font-size
line-height
'(color "#666")
'(background-color "#eee")
'(border-radius "8px")))
`(code
,(style code-font
'(color "#625F50")
'(line-height "18px")
'(font-size "13px")))
`(ol
,(style '(margin "0 0 25px 0")))
`(ul
,(style '(margin "0 0 25px 0")))
`(li
,(style (zero 'margin)
font-size
line-height))))
(define (css tag)
(format "~a { ~a }\n" tag (attr tag 'style)))
(define css-stylesheet
@~a{<style type="text/css">
body,
h1, h2, h3, h4,
p,
ol, ul, li,
blockquote,
div {
margin: 0;
}
* {
box-sizing: border-box;
}
html {
font-size: 17px;
min-height: 100%;
background-color: #fff;
}
@css['body]
@css['div.content]
@css['hr]
h1 {
display: none;
}
@css['h2]
h3 {
font-family: @(cadr heading-font);
text-align: center;
font-style: italic;
font-weight: normal;
font-size: 22px;
line-height: 25px;
margin: 0 auto 25px auto;
}
@css['p]
a,
a:link,
a:visited {
color: hsl(12, 76%, 55%);
}
a:active,
a:hover {
color: #111;
}
@css['p.meta]
p.meta a,
p.meta a:link,
p.meta a:visited {
color: #666;
}
p.meta a:active {
color: #111;
}
@css['ul]
@css['ol]
@css['img]
/* gmail */
span.emoji img {
display: inline !important;
width: auto !important;
max-width: none !important;
min-height: 0 !important;
}
@css['div.web]
div.web a,
div.web a:link,
div.web a:visited {
color: #666;
}
div.web a:hover,
div.web a:active {
color: @link-color;
}
@css['div.figure]
div.figure picture, div.figure img {
display: block;
width: 100%;
height: auto;
max-width: 100%;
margin: 0 0 13px 0;
padding: 0 0 0 0;
box-shadow: 0 0 13px rgba(0, 0, 0, 0.125);
}
div.figure picture.no-shadow, div.figure img.no-shadow {
box-shadow: none;
background: transparent;
}
div.figure picture.blend {
mix-blend-mode: multiply;
}
@css['div.figcaption]
div.figcaption a,
div.figcaption a:link,
div.figcaption a:visited {
text-decoration-color: #666;
color: #666;
}
div.figcaption a:hover,
div.figcaption a:active {
text-decoration-color: @accent-color;
color: @accent-color;
}
@css['blockquote]
small {
text-transform: uppercase;
font-size: 14px;
}
pre {
width: 100%;
max-width: 100%;
overflow-x: hidden;
font-size: 13px;
line-height: 18px;
margin-left: 25px;
color: #625F50;
}
@css['code]
span.nobr {
white-space: nowrap;
}
</style>
})