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
|
#+BEGIN_EXPORT html
<h1>Theming and Templating</h1>
#+END_EXPORT
The purpose of this build process is to implement the default layout of this
website. To that end, it provides a template file (~main.html~), and a
collection of SASS files that *~cleopatra~* then compiles into a single CSS file
using ~sassc~.
We first discuss the structure of the website, by defining the default HTML
template =soupault= will use to generate the website. Then, we specify its
minimal design, implemented in SASS. Finally, we discuss the necessary build
instructions for *~cleopatra~*.
* Main HTML Template
#+BEGIN_SRC html :tangle templates/main.html :noweb yes
<html lang="en">
<head>
<<meta-tags>>
<title><!-- page title will be inserted here --></title>
<<syncloading_html>>
<<asyncloading_html>>
</head>
<<body>>
</html>
#+END_SRC
** ~<head>~
#+NAME: meta-tags
#+BEGIN_SRC html :noweb no-export
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
#+END_SRC
*** Assets Loading
#+NAME: syncloading_html
#+BEGIN_SRC html
<link href="https://soap.coffee/+vendors/normalize.css.8.0.1/normalize.css"
rel="stylesheet">
<link rel="stylesheet" href="/style/main.css">
<link rel="icon" type="image/ico" href="/img/merida.webp">
#+END_SRC
#+NAME: asyncloading_js
#+BEGIN_SRC js
let noscript = document.getElementById('asyncloading');
noscript.insertAdjacentHTML('beforebegin', noscript.innerText);
noscript.parentNode.removeChild(noscript);
#+END_SRC
#+NAME: asyncloading_html
#+BEGIN_SRC html
<noscript id="asyncloading">
<link href="https://soap.coffee/+vendors/fira-code.2+swap/font.css"
rel="stylesheet">
<link href="https://soap.coffee/+vendors/katex.0.11.1+swap/katex.css"
rel="stylesheet">
<link href="https://soap.coffee/+vendors/fork-awesome.1.1.7+swap/css/fork-awesome.min.css"
rel="stylesheet">
<link href="https://soap.coffee/+vendors/Spectral/extra-light.css"
rel="stylesheet">
</noscript>
#+END_SRC
** ~body~
#+NAME: body
#+BEGIN_SRC html :noweb no-export
<body>
<header>
<a href="/">Technical Articles</a> /
<a href="/opinions">Opinions</a> /
<a href="/news">News</a> /
<a href="/projects">Projects</a>
</header>
<main>
<!-- page content will be inserted here -->
</main>
<footer>
<img src="https://soap.coffee/~lthms/img/merida.webp"
alt="Merida from the movie Ralph 2.0 from Disney is the
avatar I use most of the time on the Internet"
title="lthms’ avatar" />
<p>
Hi, I’m <strong>lthms</strong>, and this is my humble corner of the
Internet. You are very welcome here! If you are interested in
<em>functional programming</em>, <em>formal verification</em>, or <em>free
software projects in the making</em>, you may even enjoy your stay!
</p>
<p>
This website has been generated using a collection of <a
href="/posts/Thanks.html">awesome free software projects</a>. You can have
a look at <a href="https://code.soap.coffee/writing/lthms.git/">the source
of this website</a> or <a href="/cleopatra.html">how it is being
generated</a>, and if you run into an error, feel free to <a
href="mailto:lthms@soap.coffee">shoot me a friendly email</a>.
</p>
</footer>
<script>
<<asyncloading_js>>
</script>
</body>
#+END_SRC
* Main SASS File
First, we introduce a set of variables.
#+BEGIN_SRC sass :tangle site/style/main.sass
$content-width : 35rem
$large-side-margin : 7rem
$small-side-margin : 2rem
#+END_SRC
Then, we introduce a key CSS variable whose definition will change according to
the current width of the page (something we cannot achieve with SASS variables,
whose behavior is purely static).
#+BEGIN_SRC sass :tangle site/style/main.sass
\:root
@media screen and (min-width: calc(#{$content-width} + 2 * #{$large-side-margin}))
--side-margin : #{$large-side-margin}
@media screen and (max-width: calc(#{$content-width} + 2 * #{$large-side-margin}))
--side-margin : #{$small-side-margin}
#+END_SRC
Then, we style!
#+BEGIN_SRC sass :tangle site/style/main.sass
*
box-sizing : border-box
html
width : 100%
height : 100%
font-size : 115%
body
font-family : Spectral, serif
margin : 0 var(--side-margin) 0 calc(var(--side-margin) - 2rem) !important
padding : 2rem
@media screen and (min-width: calc(#{$content-width} + 2 * #{$large-side-margin}))
border-left : 1px solid #ccc
main p,
main h1,
main h2,
main h3,
main h4,
main h5,
main h6,
main ul,
main dl,
main ol,
header,
footer
max-width : $content-width
line-height : 140%
main h1,
main h2,
main h3,
main h4,
main h5,
main h6
font-weight : bold
header a,
footer p
font-size : 90%
main
padding-top : 4rem
padding-bottom : 4rem
footer img
border-radius : 100%
max-width : 7rem
float : right
margin-left : 1rem
margin-bottom : 1rem
pre
overflow-x : auto
code,
tt,
pre
font-family : 'Fira Code', monospace
font-size : 80%
line-height : 140%
#gallery
display : flex
flex-wrap : wrap
align-content : flex-start
img
max-width : 20rem
@import plugins
@import org
@import coq
#+END_SRC
* Build Instructions
The build instruction are pretty straightforward. We start by how to compile the
main CSS file.
#+BEGIN_SRC makefile :tangle theme.mk
SASS := $(wildcard site/style/*.sass)
MAIN_SASS := site/style/main.sass
CSS := $(MAIN_SASS:.sass=.css)
${CSS} : ${SASS}
@cleopatra echo Compiling "${CSS}"
@sassc --style=compressed --sass ${MAIN_SASS} ${CSS}
#+END_SRC
Since the HTML template does not need any particular processing, the
=theme-build= phase is only responsible for generating the main CSS file. The
[[./soupault.org][=soupault= build phase]] needs to start after the CSS file is
compiled (since it copies all relevant files to the ~build/~ directory), so we
explicit this dependency.
#+BEGIN_SRC makefile :tangle theme.mk
theme-build : ${CSS}
soupault-build : theme-build
#+END_SRC
Therefore, at the end of this generation process only one file has been
generated.
#+BEGIN_SRC makefile :tangle theme.mk
ARTIFACTS += ${CSS}
#+END_SRC
|