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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
;;; GuixSD website --- GNU's advanced distro website
;;; Initially written by sirgazil who waves all
;;; copyright interest on this file.
;;; This module defines HTML parts like header, breadcrumbs, footer,
;;; buttons, etc., which are used website-wide.
(define-module (apps base templates components)
#:use-module (apps aux lists)
#:use-module (apps aux strings)
#:use-module (apps aux sxml)
#:use-module (apps aux web)
#:use-module (apps base types)
#:use-module (apps base utils)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (breadcrumbs
button-big
button-little
contact-preview
contact->shtml
horizontal-separator
link-more
link-subtle
link-yellow
navbar
page-indicator
page-selector
screenshot->shtml))
;;;
;;; Components.
;;;
(define (breadcrumbs crumbs)
"Return an SHTML nav element representing the breadcrumbs.
CRUMBS (list)
A non-empty list of <crumb> objects as defined in
(apps base types)."
`(nav
(@ (class "breadcrumbs"))
(h2 (@ (class "a11y-offset")) "Your location:")
(a (@ (class "crumb") (href ,(guix-url))) "Home") (span " → ")
,@(separate (crumbs->shtml crumbs) '(span " → "))))
(define (crumbs->shtml crumbs)
"Return the list of CRUMBS as list of SHTML a elements.
CRUMBS (list)
A non-empty list of <crumb> objects as defined in
(apps base types)."
(cond ((= (length crumbs) 1)
(cons
`(a
(@ (class "crumb crumb-active")
(href ,(crumb-url (first crumbs))))
,(crumb-label (first crumbs)))
'()))
(else
(cons
`(a
(@ (class "crumb")
(href ,(crumb-url (first crumbs))))
,(crumb-label (first crumbs)))
(crumbs->shtml (rest crumbs))))))
(define* (button-big #:key (label "Button") (url "#") (light #false))
"Return an SHTML a element that looks like a big button.
LABEL (string)
The text for the button. For example: 'Download!'.
URL (string)
A URL to use for the href attribute of the a element. If not
specified, the value defaults to #.
LIGHT (boolean)
True if the button is going to be used on a dark background; false
otherwise (this is the default)."
`(a
(@ (class ,(string-append "button-big" (if light " button-light" "")))
(href ,url))
,label))
(define* (button-little #:key (label "Button") (url "#") (active #false))
"Return an SHTML a element that looks like a little button.
LABEL (string)
The text for the button. For example: 'Next'.
URL (string)
A URL to use for the href attribute of the a element. If not
specified, the value defaults to #.
ACTIVE (boolean)
True if the button should be highlighted as active (on)."
`(a
(@ (class ,(string-append "button-little"
(if active " button-little-active" "")))
(href ,url))
,label))
(define (contact-preview contact)
"Return an SHTML preview of the given contact object.
CONTACT (<contact>)
A contact object as defined in (apps base types)."
`(a
(@ (class "item-preview")
(href ,(contact-url contact)))
(h3 ,(contact-name contact))
(p
,(string-summarize
(sxml->string*
(match (contact-description contact)
((and multilingual (((? string?) (? string?)) ...))
(match (assoc "en" multilingual)
(("en" blurb) blurb)))
(blurb
blurb)))
30)
"…")))
(define (language-tag lang)
`(span (@ (class "button-little button-little-active")
(style "text-align: center; width: 20px; vertical-align: middle"))
,lang))
(define (contact->shtml contact)
"Return an SHTML representation of the given contact object.
CONTACT (<contact>)
A contact object as defined in (apps base types)."
`(div
(@ (class "contact-medium"))
(a (@ (href ,(contact-url contact))) (b ,(contact-name contact)))
,(if (string=? (contact-log contact) "")
""
`(small
" (" (a (@ (href ,(contact-log contact))) "archive") ") "))
;; The description can be a list of language/blurb pairs.
,(match (contact-description contact)
((((? string? languages) blurbs) ...)
`(p ,@(map (lambda (language blurb)
`(div (@ (style "display: flex; align-items: center; margin: 0 10px 10px 0"))
,(language-tag language)
(div (@ (lang ,language) (style "flex: 1")) ,blurb)))
languages
blurbs)))
(blurb
blurb))))
(define* (horizontal-separator #:key (light #false))
"Return an SHTML img element that works as a separator.
LIGHT (boolean)
True if the separator is going to be used on a dark background;
false otherwise (this is the default)."
`(img
(@ (class "h-separator")
,(if light
`(src ,(guix-url "static/base/img/h-separator.png"))
`(src ,(guix-url "static/base/img/h-separator-dark.png")))
(alt ""))))
(define* (link-more #:key (label "More") (url "#") (light #false))
"Return an SHTML a element that looks like a 'more →' link.
LABEL (string)
The text for the link. For example: 'Read the manual'.
URL (string)
A URL to use for the href attribute of the a element. If not
specified, the value defaults to #.
LIGHT (boolean)
True if the link is going to be used on a dark background; false
otherwise (this is the default)."
`(a
(@ (class ,(string-append "link-more" (if light " link-more-light" "")))
(href ,url))
,label))
(define* (link-subtle #:key (label "link") (url "#"))
"Return an SHTML a element that does not stand too much on white backgrounds.
LABEL (string)
The text for the link. For example: 'Additional notes'.
URL (string)
The URL of the link. If not specified, the value defaults to #."
`(a (@ (class "link-subtle") (href ,url)) ,label))
(define* (link-yellow #:key (label "link") (url "#"))
"Return a yellow SHTML a element to use on dark backgrounds.
LABEL (string)
The text for the link. For example: 'read the manual'.
URL (string)
The URL of the link. If not specified, the value defaults to #."
`(a (@ (class "link-yellow") (href ,url)) ,label))
(define* (menu-dropdown #:key (label "Item") (active-item "") (url "#") (items '()))
"Return an SHTML li element representing a dropdown for the navbar.
LABEL (string)
The text for the dropdown. For example: 'About'.
ACTIVE-ITEM (string)
A string representing the label of the current active item in the
navigation bar. If the values of LABEL and ACTIVE-ITEM are the
same, the dropdown is highlighted.
URL (string)
The URL of the web resource referenced by the dropdown. Any
value used for an HTML a element is valid. If not specified, the
value defaults to #.
ITEMS (list of menu items)
A list of menu items as returned by the menu-item procedure in this
same module. If not provided, the value defaults to an empty list."
`(li
(@ (class "dropdown"))
(a
(@ (class
,(if (string=? (string-downcase label) (string-downcase active-item))
"menu-item menu-item-active dropdown-btn"
"menu-item dropdown-btn"))
(href ,url))
,label)
(div
(@ (class "submenu"))
(div (@ (class "submenu-triangle")) " ")
(ul ,@items))))
(define* (menu-item #:key (label "Item") (active-item "") (url "#"))
"Return an SHTML li element representing an item for the navbar.
LABEL (string)
The text for the item. For example: 'About'.
ACTIVE-ITEM (string)
A string representing the label of the current active item in the
navigation bar. If the values of LABEL and ACTIVE-ITEM are the
same, the menu item is highlighted.
URL (string)
The URL of the web resource referenced by the menu item. Any
value used for an HTML a element is valid. If not specified, the
value defaults to #."
`(li
(a
(@ (class
,(if (string=? (string-downcase label) (string-downcase active-item))
"menu-item menu-item-active"
"menu-item"))
(href ,url))
,label)))
(define* (navbar #:key (active-item "About"))
"Return an SHTML header element with the given ACTIVE ITEM highlighted."
`(header
(@ (class "navbar"))
;; Branding.
(h1
(a
(@ (class "branding") (href ,(guix-url)))
(span (@ (class "a11y-offset")) "Guix")))
;; Menu.
(nav (@ (class "menu"))
(h2 (@ (class "a11y-offset")) "Website menu:")
(ul
,(menu-item #:label "Overview" #:active-item active-item #:url (guix-url))
,(menu-item #:label "Download" #:active-item active-item #:url (guix-url "download/"))
,(menu-item #:label "Packages" #:active-item active-item #:url (guix-url "packages/"))
,(menu-item #:label "Blog" #:active-item active-item #:url (guix-url "blog/"))
,(menu-item #:label "Help" #:active-item active-item #:url (guix-url "help/"))
,(menu-item #:label "Donate" #:active-item active-item #:url (guix-url "donate/"))
,(menu-dropdown #:label "About" #:active-item active-item #:url (guix-url "about/")
#:items
(list
(menu-item #:label "Contact" #:active-item active-item #:url (guix-url "contact/"))
(menu-item #:label "Contribute" #:active-item active-item #:url (guix-url "contribute/"))
(menu-item #:label "Security" #:active-item active-item #:url (guix-url "security/"))
(menu-item #:label "Graphics" #:active-item active-item #:url (guix-url "graphics/"))))))
;; Menu button.
(a
(@ (class "menu-btn")
(href ,(guix-url "menu/"))) "")))
(define (page-indicator page-number total-pages)
"Return an SHTML span element in the form 'page X of Y' if there is
more than one page. Otherwise, return an empty string.
PAGE-NUMBER (number)
The number of the page that the user is seeing.
TOTAL-PAGES (number)
The total number of pages that should be displayed."
(if (> total-pages 1)
`(span
(@ (class "page-number-indicator"))
" (Page " ,(number->string page-number)
" of " ,(number->string total-pages) ")")
""))
(define (page-selector pages active-page base-url)
"Return an SHTML nav element representing a page selection widget.
PAGES (number)
The total number of pages that should be displayed.
ACTIVE-PAGE (number)
The number of the page that should be displayed as active.
BASE-URL (string)
Absolute URL path to prepend to page numbers. For example:
'/en/blog'. This would result in URLs like: '/en/blog/page/N',
where N is the number of the page."
`(nav
(@ (class "page-selector"))
(h3
(@ (class "a11y-offset"))
,(string-append "Page " (number->string active-page) " of "
(number->string pages) ". Go to another page: "))
,(if (> pages 1)
(map
(lambda (page-number)
(list
(button-little
#:label page-number
#:url (url-path-join base-url "page"
(number->string page-number) "")
#:active (= page-number active-page))
" ")) ; NOTE: Force space for readability in non-CSS browsers.
(iota pages 1))
"")))
(define (screenshot->shtml shot)
"Return an SHTML representation of the given screenshot object.
SHOT (<screenshot>)
A screenshot object as defined in (apps base types)."
`(div
(@ (class "screenshot-preview"))
(a
(@ (href ,(guix-url (url-path-join "screenshots"
(screenshot-slug shot) ""))))
(img
(@ (class "responsive-image")
(src ,(screenshot-preview shot))
(alt "")))
(span (@ (class "screenshot-inset-shadow")) ""))
(p ,(screenshot-caption shot) (span (@ (class "hidden")) "."))))
|