CSS and home page

This commit is contained in:
kamkow1
2025-06-09 17:26:25 +02:00
parent bec8cb7102
commit 23de19b63e
7 changed files with 115 additions and 16 deletions

BIN
assets/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

1
assets/simple.min.css vendored Normal file

File diff suppressed because one or more lines are too long

14
build.c
View File

@ -4,6 +4,8 @@
char *prog = NULL;
#define DEBUG 1
int main(int argc, char ** argv)
{
rebuild_self(argc, argv, "cc", "-o", "build", "build.c");
@ -13,14 +15,22 @@ int main(int argc, char ** argv)
if (strcmp(cmd, "make") == 0) {
RULE("./aboba", "./main.c", "./mongoose.o", "./gpp1") {
RULE("./mongoose.o", "./mongoose/mongoose.c") {
CMD("cc", "-c", "-o", "./mongoose.o", "./mongoose/mongoose.c");
#if DEBUG
CMD("cc", "-ggdb", "-c", "-o", "./mongoose.o", "./mongoose/mongoose.c");
#else
CMD("cc", "-c", "-o", "./mongoose.o", "./mongoose/mongoose.c");
#endif
}
RULE("./gpp1", "./gpp/gpp.c") {
CMD("cc", "-DHAVE_STRDUP", "-DHAVE_FNMATCH_H", "-o", "gpp1", "gpp/gpp.c");
}
CMD("cc", "-o", "./aboba", "./main.c", "./mongoose.o");
#if DEBUG
CMD("cc", "-ggdb", "-o", "./aboba", "./main.c", "./mongoose.o");
#else
CMD("cc", "-o", "./aboba", "./main.c", "./mongoose.o");
#endif
}
} else if (strcmp(cmd, "clean") == 0) {
remove1("./build");

45
main.c
View File

@ -1,3 +1,4 @@
#include <libgen.h>
#define GEBS_NO_PREFIX
#define GEBS_IMPLEMENTATION
#include "gebs/gebs.h"
@ -18,7 +19,10 @@ void event_handler(struct mg_connection *conn, int ev, void *ev_data)
{
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *msg = (struct mg_http_message *)ev_data;
Route_Handler handler = hmget(route_hashtable, msg->uri.buf);
char key[MG_PATH_MAX] = {0};
strncpy(key, msg->uri.buf, msg->uri.len);
Route_Handler handler = shget(route_hashtable, key);
handler(conn, msg);
}
}
@ -50,7 +54,36 @@ void handle_page_not_found(struct mg_connection *conn, struct mg_http_message *m
String_Builder out = {0};
defer { sb_free(&out); }
bool ok = gpp1("./tmpls/404.t", &env, &out);
bool ok = gpp1("./tmpls/page-missing.t", &env, &out);
sb_finish(&out);
if (!ok) {
mg_http_reply(conn, 500, "Content-Type: text/html\r\n", "Internal server error ;(");
} else {
mg_http_reply(conn, 200, "Content-Type: text/html\r\n", out.items);
}
}
void handle_simple_css(struct mg_connection *conn, struct mg_http_message *msg)
{
struct mg_http_serve_opts opts = { 0 };
mg_http_serve_file(conn, msg, "./assets/simple.min.css", &opts);
}
void handle_favicon(struct mg_connection *conn, struct mg_http_message *msg)
{
struct mg_http_serve_opts opts = { 0 };
mg_http_serve_file(conn, msg, "./assets/favicon.ico", &opts);
}
void handle_home(struct mg_connection *conn, struct mg_http_message *msg)
{
NString_List env = {0};
defer { list_free(&env); }
String_Builder out = {0};
defer { sb_free(&out); }
bool ok = gpp1("./tmpls/index.t", &env, &out);
sb_finish(&out);
if (!ok) {
@ -62,7 +95,11 @@ void handle_page_not_found(struct mg_connection *conn, struct mg_http_message *m
static void init_route_hashtable(void)
{
hmdefault(route_hashtable, &handle_page_not_found);
shdefault(route_hashtable, &handle_page_not_found);
shput(route_hashtable, "/page-missing", &handle_page_not_found);
shput(route_hashtable, "/simple.min.css", &handle_simple_css);
shput(route_hashtable, "/favicon.ico", &handle_favicon);
shput(route_hashtable, "/", &handle_home);
}
int main(int argc, char ** argv)
@ -80,7 +117,7 @@ int main(int argc, char ** argv)
}
mg_mgr_free(&mgr);
hmfree(route_hashtable);
shfree(route_hashtable);
return 0;
}

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>404 - Page not found</title>
</head>
<body>
The page you were looking for doesn't exist. <br />
URL: <#URL>
</body>
</html>

45
tmpls/index.t Normal file
View File

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>Kamil's personal website</title>
<link rel="stylesheet" href="/simple.min.css" />
</head>
<body>
<h1>Kamil's personal website</h1>
<section>
<h2>Personal projects</h2>
<a href="https://gitlab.com/kamkow1">Gitlab</a><br />
<a href="https://github.com/kamkow1">Github (mostly old unused stuff)</a><br />
<h3>My favourites</h3>
<ul>
<li>
<a href="https://gitlab.com/kamkow1/gebs">gebs - good enough build system</a>
</li>
<li>
<a href="https://github.com/kamkow1/gt">gt - green threads library for x86 64</a>
</li>
<li>
<a href="https://gitlab.com/kamkow1/clij">clij - concatenative language in Java</a>
</li>
<li>
<a href="https://gitlab.com/kamkow1/cindex">cindex - C source code indexer and search engine</a>
</li>
<li>
<a href="https://gitlab.com/kamkow1/z80emu">Zilog z80 chip emulator</a>
</li>
<li>
<a href="https://gitlab.com/kamkow1/yup">Yup - toy compiler in Go</a>
</li>
<li>
<a href="https://github.com/kamkow1/sal">Sal - silly ahh language</a>
</li>
<li>
<a href="https://gitlab.com/kamkow1/knur">knur - heavily modified xv6 kernel</a>
</li>
</ul>
</section>
<footer>
<a href="/">HOME</a>
</footer>
</body>
</html>

16
tmpls/page-missing.t Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>404 - Page not found</title>
<link rel="stylesheet" href="/simple.min.css" />
</head>
<body>
<h1>The page you were looking for doesn't exist!</h1>
<p>
URL was: <#URL><br />
</p>
<footer>
<a href="/">HOME</a>
</footer>
</body>
</html>