Blob


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