-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.shen
93 lines (81 loc) · 3.11 KB
/
index.shen
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
(load "data.shen")
(load "utils.shen")
(load "fetch.shen")
(define string-contains
S T -> (>= ((. S "indexOf") T) 0))
(define link-icon
Url -> "far fa-envelope" where (string-contains Url "mailto:")
Url -> "fab fa-github" where (string-contains Url "github.com")
_ -> "fas fa-link")
(define link
Url Name -> [span [i [@class (link-icon Url)]] [a [@href Url] Name]])
(define version-attributes
Kernel -> [[@class "latest"] [@title "Up-to-date with the latest"]] where (>= Kernel (value *latest-kernel-version*))
Kernel -> [[@class "recent"] [@title "Compatible with recent versions"]] where (>= Kernel (value *recent-kernel-version*))
_ -> [[@class "outdated"] [@title "Several versions out-of-date"]])
(define port-row
Port ->
[tr
[td (. Port "platform")]
[td
(link
(js.raw.or (. Port "url") (@s "https://github.com/" (. Port "github")))
(js.raw.or (. Port "name") (after-last-slash (js.raw.or (. Port "github") (. Port "url")))))]
[td (. Port "kernel") | (version-attributes (js.parse-float (. Port "kernel")))]])
(define ports-table
Certified Uncertified ->
[table
[thead [tr [th "Platform"] [th "Port"] [th "Kernel"]]]
[tbody |
(append
[[tr [th [@colspan 3] "Certified"]] | (map (function port-row) Certified)]
[[tr [th [@colspan 3] "Uncertified"]] | (map (function port-row) Uncertified)])]])
(define setup-downloads-table ->
(let NonArchival (filter (/. P (js.falsy? (. P "archival"))) (value *ports*))
Sorted (sort-by (/. P (. P "platform")) NonArchival)
Certified (filter (/. P (js.truthy? (. P "certified"))) Sorted)
Uncertified (filter (/. P (js.falsy? (. P "certified"))) Sorted)
(dom.replace
(dom.query "#downloads-table")
(dom.build
(ports-table Certified Uncertified)))))
(define contributor-row
C ->
[tr
(sift
[td (js.raw.or (. C "name") (. C "github"))])
(sift
[td
(js.raw.and (. C "github") (link (@s "https://github.com/" (. C "github")) (. C "github")))
(js.raw.and (. C "blog") (link (. C "blog") "blog"))])])
(define community-table
Contributors ->
[table
[thead [tr [th "Contributor"] [th "Links"]]]
[tbody |
(map (function contributor-row)
(sort-by (/. C ((. (js.raw.or (js.raw.or (. C "name") (. C "github")) "") "toLowerCase")))
Contributors))]])
(define setup-community-table ->
(dom.replace
(dom.query "#community-table")
(dom.build
(trap-error
(community-table (sift (load-contributors)))
(/. E
(do
((. (js.console) "error") E)
[div
[p "Unable to load contributors"]
[p "GitHub rate limit may be expended, try again later"]]))))))
(define scroll-to-anchor ->
(let Hash (. (web.document) "location" "hash")
(if (and (js.truthy? Hash) (> (. Hash "length") 0))
((. (dom.query (@s "#" (tlstr Hash))) "scrollIntoView"))
())))
(dom.onready
(freeze
(do
(setup-downloads-table)
(setup-community-table)
(scroll-to-anchor))))