commit 5385f0c1a0e9efae0fafd479077ad76b9d6300d6
parent bc80caf4d42123a5f6d3da8f9d52c4993f12e3ab
Author: Andrew Laack <andrew@laack.co>
Date: Thu, 27 Aug 2026 09:24:19 -0500
Add css, handle routes
Diffstat:
5 files changed, 165 insertions(+), 5 deletions(-)
diff --git a/example/ocaml.rl b/example/ocaml.rl
@@ -11,3 +11,68 @@ In OCaml we use the 'let' keyword to bind a expressions to names (variables). Sh
```ocaml
let x = 10
```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
+## Syntax
+
+In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:
+
+```ocaml
+let x = 10
+```
+
diff --git a/learning/bin/main.ml b/learning/bin/main.ml
@@ -14,22 +14,45 @@ let handle_normal_line line =
then
"<h" ^ string_of_int hashCount ^ ">" ^ line ^ "</h" ^ string_of_int hashCount ^ ">"
else
- "<div>" ^ line ^ "</div>"
+ "<content-block>" ^ line ^ "</content-block>"
else
- "<div>" ^ line ^ "<div>"
+ (* return nothing if the line is empty *)
+ ""
-let readFile fileName =
+(* Read in the file with the fileName and apply line_application to each line of the file returning the resulting string. *)
+let readFile fileName line_application =
let ic = open_in fileName in
let rec readAll acc =
try
- readAll (acc ^ (handle_normal_line (input_line ic)) ^ "\n")
+ readAll (acc ^ (line_application (input_line ic)) ^ "\n")
with End_of_file ->
close_in_noerr ic;
acc
in readAll ""
+
+let id x = x
+
+let basic_html_prefix =
+ "
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <link rel=\"stylesheet\" href=\"/static/styles.css\" type=\"text/css\">
+ </head>
+ <body>
+ "
+let basic_html_suffix =
+ "</body>
+ </html>"
+
let () =
Dream.run
@@ Dream.logger
- @@ fun _ -> Dream.html (readFile "../example/ocaml.rl")
+ @@ Dream.router [
+
+ Dream.get "/"
+ (fun _ -> Dream.html (basic_html_prefix ^ (readFile "../example/ocaml.rl" handle_normal_line) ^ basic_html_suffix));
+ Dream.get "/static/**" (Dream.static "./static");
+ ]
diff --git a/learning/static/styles.css b/learning/static/styles.css
@@ -0,0 +1,31 @@
+body {
+ background-color: #ffffff;
+ margin: 0;
+}
+h1 {
+ color: #480000 ;
+}
+
+h2 {
+ color: #500000 ;
+}
+
+h3 {
+ color: #580000 ;
+}
+
+h4 {
+ color: #600000 ;
+}
+h5 {
+ color: #680000 ;
+}
+
+h6 {
+ color: #700000 ;
+}
+
+content-block {
+ display: block;
+ color: #000000;
+}
diff --git a/outputs/out.html b/outputs/out.html
@@ -0,0 +1,28 @@
+<link rel="stylesheet" href="styles.css" type="text/css">
+<h1># OCaml</h1>
+<content-block></content-block>
+<h2>## History</h2>
+<content-block></content-block>
+<content-block>OCaml is the acronym for Objective Categorical Abstract Machine Language. </content-block>
+<content-block></content-block>
+<h2>## Syntax</h2>
+<content-block></content-block>
+<content-block>In OCaml we use the 'let' keyword to bind a expressions to names (variables). Shown below is an example of this:</content-block>
+<content-block></content-block>
+<content-block>```ocaml</content-block>
+<content-block>let x = 10</content-block>
+<content-block>```</content-block>
+
+<content-block></content-block>
+<content-block>```ocaml</content-block>
+<content-block>let x = 10</content-block>
+<content-block>```</content-block>
+<content-block></content-block>
+<content-block>```ocaml</content-block>
+<content-block>let x = 10</content-block>
+<content-block>```</content-block>
+<content-block></content-block>
+<content-block>```ocaml</content-block>
+<content-block>let x = 10</content-block>
+<content-block>```</content-block>
+
diff --git a/outputs/styles.css b/outputs/styles.css
@@ -0,0 +1,13 @@
+body {
+ font-family: Arial, sans-serif;
+ background-color: #f3f6f9;
+ margin: 0;
+}
+h1 {
+ color: #000000;
+}
+
+content-block {
+ background-color: #f6f9fB;
+ display: block;
+}