-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rkt
154 lines (125 loc) · 5.17 KB
/
main.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
#!/usr/bin/racket
#lang racket
(define (generate-html reading-list)
(let* ([yearly-strings (map apply-year->html reading-list)]
[content (apply string-append yearly-strings)])
(string-append
"<html>\n"
" <head>\n"
" <title>loosetypes</title>\n"
" <link rel=\"shortcut icon\" href='./res/favicon.ico' type='image/png'>\n"
" <link rel='stylesheet' href='./styles.css' type='text/css'>\n"
" <meta charset='utf-8'>\n"
" </head>\n"
" <body>\n\n"
" <div class='banner'>\n"
" <div class='banner-top-space'> </div>\n"
" <hr class='hr-solid' />\n"
" <hr class='hr-dashed' />\n"
" <hr class='hr-solid' />\n"
" </div>\n\n"
" <div class='site'>\n\n"
" <div class='vr'> </div>\n\n"
" <img class='banner-img'\n"
" style='height: 125px;'\n"
" src='./res/loose_types_logo.png' alt='Loose Types'></img>\n\n"
" <h1 class='title'>What I've Been Reading</h1>\n\n"
content
" <!-- footer -->\n"
" <br/>\n"
" <div class='footer'>\n"
" <div class='contact'>\n\n"
" <h2 class='footer-h2'>Made by </h2>\n"
" <img class='icon' src='./res/hand_icon.png' alt='hands'></img>\n"
" <h2 class='footer-h2'> on a </h2>\n"
" <img class='icon' src='./res/computer_icon.png' alt='computer'></img>\n"
" <h2 class='footer-h2'>.</h2>\n\n"
" </div>\n"
" </div>\n"
" <!-- end .footer -->\n\n"
" </div>\n"
" <!-- end .site -->\n\n"
" </body>\n"
"</html>\n"
)))
(define (fmt-bg-and-width background width)
(let ([how-long (number->string width)])
(string-append "style='"
"background: " background "; "
"width: " how-long ";'")))
(define (fmt-top-and-z-index n)
(let ([multiSpineOffset (number->string (* 29 (- n 1)))])
(string-append "style='"
"top: calc(100% - " multiSpineOffset "px - 59.8px); "
"z-index: " (number->string n) ";'")))
(define (fmt-prop prop-name prop-value)
(if (not (string=? prop-value ""))
(string-append " " prop-name "='" prop-value "'")
""))
(define (fmt-class classes)
(fmt-prop "class" classes))
(define (fmt-style styles)
(fmt-prop "style" styles))
(define (html-element type content classes styles)
(string-append
"<" type (fmt-class classes) (fmt-style styles) ">"
(if (string=? type "div") "\n" "")
content
"</" type ">"
"\n"))
(define (comment message)
(string-append "<!-- " message " -->\n"))
(define (h1 [content ""] [classes ""] [styles ""])
(html-element "h1" content classes styles))
(define (div [content ""] [classes ""] [styles ""])
(html-element "div" content classes styles))
;;;(div big-content "books" (string-append ))
(define (book->html book-number title author background title-color author-color width)
(let* ([top-z-index-styling (fmt-top-and-z-index book-number)]
[bg-width-styling (fmt-bg-and-width background width)]
[margin (number->string (+ 2 width))])
(string-append
" <div class='books' " top-z-index-styling ">\n"
" <div class='level-row-perspective'>\n"
" <div class='above' " bg-width-styling " ></div>\n"
" <div class='spine' " bg-width-styling ">\n"
" <a style='color:" title-color ";' href='#'>" title "</a>\n"
" <span style='color:" author-color ";'>" author "</span>\n"
" </div>\n"
" <div class='pages' style='margin-left:" margin "px;'>\n"
" <div class='inner-pages'></div>\n"
" </div>\n"
" </div>\n"
" </div>\n\n")))
(define (apply-book->html book)
(apply book->html book))
(define (num-books-calc n)
(+ 30.8 (* 29 n)))
(define (year->html annual-list)
(let* ([year (number->string (car annual-list))]
[books (cdr annual-list)]
[quantity (number->string (length books))]
[h1-content (string-append year " (" quantity ")")]
[height (number->string (num-books-calc (length books)))]
[div-styles (string-append "height: " height "px;")]
[list-of-content (map apply-book->html books)]
[start-comment (string-append "start " year)]
[end-comment (string-append "end " year)]
[content (apply string-append list-of-content)])
(string-append
" " (comment start-comment)
" " (h1 h1-content) "\n"
" " (div content "stack-of-books" div-styles) "\n"
" " (comment end-comment))))
(define (apply-year->html annual-list)
(year->html annual-list))
(define (main reading-list [output-file "index.html"] [delete-existing-p #true])
(when (and delete-existing-p (file-exists? output-file))
(delete-file output-file))
(let* ([out (open-output-file output-file)]
[static-page (generate-html reading-list)])
;; html formatter?
(display static-page out)))
;; evaluate buffer from here rather than eshell
(let ([reading-list (file->list "./data-input.rkt")])
(main reading-list))