Blame


1 ddc03123 2020-03-28 op The first version of this website had a theme switcher. It was
2 ddc03123 2020-03-28 op implemented with CSS variables (and a bit of javascript). Then the
3 ddc03123 2020-03-28 op javascript switcher was eventually removed, and the theme forced to be
4 ddc03123 2020-03-28 op dark, but I kept the CSS variables *just in case* (read: I'm lazy.)
5 ddc03123 2020-03-28 op
6 ddc03123 2020-03-28 op *Edit*: this is no longer the case. The current version of the website
7 ddc03123 2020-03-28 op is *yet another one*, with a 100% rewritten (and pure) CSS.
8 ddc03123 2020-03-28 op
9 ddc03123 2020-03-28 op The real reason I left the CSS variables was that I didn't wanted to
10 ddc03123 2020-03-28 op use a CSS preprocessor (such as `less` or `sass`) to manage such a
11 ddc03123 2020-03-28 op simple file (306 line, with blanks and comments). But, at the same
12 ddc03123 2020-03-28 op time, I didn't want to copy-paste the colors everywhere.
13 ddc03123 2020-03-28 op
14 ddc03123 2020-03-28 op ## Introducing the C preprocessor
15 ddc03123 2020-03-28 op
16 ddc03123 2020-03-28 op The C preprocessor is a simple and well-known beast (sort of, at
17 ddc03123 2020-03-28 op least), and it's included in the base system installation of most
18 ddc03123 2020-03-28 op (pratically all, I presume) OSes.
19 ddc03123 2020-03-28 op
20 ddc03123 2020-03-28 op If you have never used it, here's a quick howto.
21 ddc03123 2020-03-28 op
22 ddc03123 2020-03-28 op You can define constants with
23 a3ab6f61 2020-09-22 op ```c
24 ddc03123 2020-03-28 op #define PI 3.141592653589793238462643383279502884197169
25 ddc03123 2020-03-28 op ```
26 ddc03123 2020-03-28 op and use them whenever you like, for instance
27 ddc03123 2020-03-28 op
28 ddc03123 2020-03-28 op ```css
29 ddc03123 2020-03-28 op double p = PI / 4;
30 ddc03123 2020-03-28 op ```
31 ddc03123 2020-03-28 op
32 ddc03123 2020-03-28 op The preprocessor is more powerful, it supports `#include`s and
33 ddc03123 2020-03-28 op function-like macro (even variadic). But `#define`s are enough to
34 ddc03123 2020-03-28 op manage a couple of CSS variables.
35 ddc03123 2020-03-28 op
36 ddc03123 2020-03-28 op Now, let's see how this applies to CSS. Given a file with the
37 ddc03123 2020-03-28 op following content
38 ddc03123 2020-03-28 op
39 a3ab6f61 2020-09-22 op ```css
40 a3ab6f61 2020-09-22 op #define BASE1 #221635
41 ddc03123 2020-03-28 op
42 a3ab6f61 2020-09-22 op body {
43 a3ab6f61 2020-09-22 op background-color: BASE1;
44 a3ab6f61 2020-09-22 op }
45 a3ab6f61 2020-09-22 op ```
46 a3ab6f61 2020-09-22 op
47 ddc03123 2020-03-28 op we can *compile* it with
48 ddc03123 2020-03-28 op
49 a3ab6f61 2020-09-22 op ```sh
50 a3ab6f61 2020-09-22 op $ cpp -P file.css > a.css
51 a3ab6f61 2020-09-22 op ```
52 ddc03123 2020-03-28 op
53 ddc03123 2020-03-28 op and obtain a valid CSS file `a.css`.
54 ddc03123 2020-03-28 op
55 ddc03123 2020-03-28 op ## Conclusions
56 ddc03123 2020-03-28 op
57 ddc03123 2020-03-28 op It's weird. It's weird to invoke `cpp` to *build* a CSS files.
58 ddc03123 2020-03-28 op
59 ddc03123 2020-03-28 op But it's also *satisfying*, in some sense.
60 ddc03123 2020-03-28 op
61 ddc03123 2020-03-28 op As a conclusion, I would like to note that another option is to use
62 ddc03123 2020-03-28 op m4, a general purpose macro language that should be present on every
63 ddc03123 2020-03-28 op POSIX system. Unfortunately, I don't know the language very well, so I
64 ddc03123 2020-03-28 op opted to `cpp`.