]> git.f4mnq.fr Git - site-web-pro.git/commitdiff
Le fichier style.css est maintenant *vraiment* du OCaml
authorAmélia Coutard-Sander <git@f4mnq.fr>
Sun, 15 Feb 2026 01:28:57 +0000 (02:28 +0100)
committerAmélia Coutard-Sander <git@f4mnq.fr>
Sun, 15 Feb 2026 01:28:57 +0000 (02:28 +0100)
f4mnq/dune
f4mnq/style.ml
html/CSS.ml [new file with mode: 0644]
html/CSS.mli [new file with mode: 0644]
html/dune [new file with mode: 0644]

index 4d3745127bce4c9212d0c9c5ab18db6d8756ccb4..e174c5741db7aea40fa503a1290c226fdc6e11ea 100644 (file)
@@ -1,5 +1,6 @@
 (executables
- (public_names index style))
+ (public_names index style)
+ (libraries html))
 
 (install
  (files
index 2c79b043be4dd5c6df189f575677343bd82026eb..5900d6566b769e2a4431c49a411b190bd9dbe2cd 100644 (file)
  * along with this website.  If not, see <https://www.gnu.org/licenses/>.
  *)
 
-Printf.printf "%s"
-  {|@media (prefers-color-scheme: light) {
-body {
-       background-color: #ffc;
-       color: #000;
-}
-a {
-       color: #099;
-}
-a:visited {
-       color: #c3c;
-}
-}
-@media (prefers-color-scheme: dark) {
-body {
-       background-color: #003;
-       color: #fff;
-}
-a {
-       color: #ff9;
-}
-a:visited {
-       color: #f99;
-}
-}
+open Html
 
-#content {
-       min-height: calc(100vh - 200px);
-}
+let colorscheme ~scheme ~fg ~bg ~link ~used_link =
+        let open CSS in
+        media ~feature:("prefers-color-scheme", scheme)
+          [
+            block [tag "body"] [property "background-color" ("#" ^ bg); property "color" ("#" ^ fg)];
+            block [tag "a"] [property "color" ("#" ^ link)];
+            block [tag "a:visited"] [property "color" ("#" ^ used_link)];
+          ]
 
-#mpring {
-       margin-left: calc(50% - 100px);
-       border: 0;
-}
-|}
+let () =
+        let open CSS in
+        CSS.print
+          [
+            colorscheme ~scheme:"light" ~fg:"000" ~bg:"ffc" ~link:"099" ~used_link:"c3c";
+            colorscheme ~scheme:"dark" ~fg:"fff" ~bg:"003" ~link:"ff9" ~used_link:"f99";
+            block [id "content"] [property "min-height" "calc(100vh - 200px)"];
+            block [id "mpring"] [property "margin-left" "calc(50% - 100px)"; property "border" "0"];
+          ]
diff --git a/html/CSS.ml b/html/CSS.ml
new file mode 100644 (file)
index 0000000..78ed2d6
--- /dev/null
@@ -0,0 +1,40 @@
+(* f4mnq.fr
+ * Copyright 2026 Amélia COUTARD-SANDER <https://www.f4mnq.fr>.
+
+ * This website is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+
+ * This website is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
+ * for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this website.  If not, see <https://www.gnu.org/licenses/>.
+ *)
+
+type t = string -> unit
+
+type selector = string
+
+type property = string -> unit
+
+let print = List.iter (fun f -> f "")
+
+let media ~feature:(n, v) blocks indent =
+        Printf.printf "%s@media (%s: %s) {\n" indent n v;
+        List.iter (fun f -> f indent) blocks;
+        Printf.printf "%s}\n" indent
+
+let block selectors properties indent =
+        Printf.printf "%s%s {\n" indent (String.concat " " selectors);
+        List.iter (fun f -> f @@ indent ^ "\t") properties;
+        Printf.printf "%s}\n" indent
+
+let tag s = s
+
+let id s = "#" ^ s
+
+let property name value indent = Printf.printf "%s%s: %s;\n" indent name value
diff --git a/html/CSS.mli b/html/CSS.mli
new file mode 100644 (file)
index 0000000..da0b487
--- /dev/null
@@ -0,0 +1,34 @@
+(* f4mnq.fr
+ * Copyright 2026 Amélia COUTARD-SANDER <https://www.f4mnq.fr>.
+
+ * This website is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+
+ * This website is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
+ * for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this website.  If not, see <https://www.gnu.org/licenses/>.
+ *)
+
+type t
+
+type selector
+
+type property
+
+val print : t list -> unit
+
+val media : feature:string * string -> t list -> t
+
+val block : selector list -> property list -> t
+
+val tag : string -> selector
+
+val id : string -> selector
+
+val property : string -> string -> property
diff --git a/html/dune b/html/dune
new file mode 100644 (file)
index 0000000..d3de825
--- /dev/null
+++ b/html/dune
@@ -0,0 +1,2 @@
+(library
+ (name html))