From 1ca7ae3859b2c0397e4b28f77c04a4b816f69ae1 Mon Sep 17 00:00:00 2001
From: Runxi Yu <me@runxiyu.org>
Date: Thu, 13 Mar 2025 08:52:03 +0800
Subject: [PATCH] Begin to use hare-htmpl

---
 NOTES.md |  1 +
 main.ha  | 14 ++++++++------

diff --git a/NOTES.md b/NOTES.md
index c60d0f5c37cdba794778a011bc7dc30337ae4dc0..0c6cbcd31139bafba0e1a913609debf597aa3411 100644
--- a/NOTES.md
+++ b/NOTES.md
@@ -4,3 +4,4 @@ You will need the following dependencies:
 
 - [hare](https://git.sr.ht/~sircmpwn/hare)
 - [hare-http](https://git.sr.ht/~sircmpwn/hare-http)
+- [hare-htmpl](https://forge.runxiyu.org/hare/:/repos/hare-htmpl/) ([backup](https://git.sr.ht/~runxiyu/hare-htmpl))
diff --git a/main.ha b/main.ha
index a77eec6096a989f0f2fc8e57069301194898c0b0..aa0364f5b5548f0ef73a6625ae8e481ff6c51f60 100644
--- a/main.ha
+++ b/main.ha
@@ -3,6 +3,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
 // Adapted from template by Willow Barraco <contact@willowbarraco.fr>
 
 use getopt;
+use htmpl;
 use log;
 use net;
 use net::ip;
@@ -17,7 +18,7 @@ use strings;
 
 const usage: [_]getopt::help = [
 	"HTTP server",
-	('a', "address", "listened address (ex: 127.0.0.1:8080)")
+	('a', "address", "listened address")
 ];
 
 export fn main() void = {
@@ -63,9 +64,10 @@ 		};
 	};
 };
 
-export fn handlereq(conn: io::handle, request: *http::request) (void | io::error)  = {
-	fmt::fprint(conn, "HTTP/1.1 200 OK\r\n")?;
-	fmt::fprint(conn, "Content-Type: text/plain\r\n\r\n")?;
-
-	fmt::fprintln(conn, "Hi there!")?;
+export fn handlereq(conn: io::handle, request: *http::request) (void | io::error | nomem)  = {
+	htmpl::write(conn, "HTTP/1.1 200 OK\r\n")?;
+	htmpl::write(conn, "Content-Type: text/html\r\n\r\n")?;
+	htmpl::write(conn, "<!DOCTYPE html><html><body><h1>")?;
+	htmpl::write_escape_html(conn, "Hey there <3")?;
+	htmpl::write(conn, "</h1></body></html>")?;
 };

-- 
2.48.1