Transfer time.

This commit is contained in:
mskorczak 2024-10-22 20:56:05 +01:00
parent a2d683ec75
commit 5741794f28
6 changed files with 74 additions and 32 deletions

View file

@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "jungle_zig",
.name = "aoc_zig",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = b.path("src/root.zig"),
@ -30,7 +30,7 @@ pub fn build(b: *std.Build) void {
b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "jungle_zig",
.name = "aoc_zig",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,

View file

@ -1,5 +1,5 @@
.{
.name = "jungle_zig",
.name = "aoc_zig",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

View file

@ -19,7 +19,7 @@ const Allocator = std.mem.Allocator;
// r.sendBody("404 - File not found") catch return;
//}
pub const JungleRouter = struct {
pub const WebRouter = struct {
const Self = @This();
allocator: Allocator,
@ -83,9 +83,10 @@ pub fn main() !void {
.not_found = not_found,
});
defer router.deinit();
var jungle_router = JungleRouter.init(allocator);
try router.handle_func("/", &jungle_router, &JungleRouter.index);
try router.handle_func("/home", &jungle_router, &JungleRouter.home);
var web_router = WebRouter.init(allocator);
try router.handle_func("/home", &web_router, &WebRouter.home);
try router.handle_func("/index", &web_router, &WebRouter.index);
try router.handle_func("/", &web_router, &WebRouter.index);
var listener = zap.HttpListener.init(.{ .port = 3000, .on_request = router.on_request_handler(), .log = true, .max_clients = 100000, .public_folder = "src/public" });
try listener.listen();

View file

@ -2,27 +2,50 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, inital-scale=1">
<meta http-equiv="X-UR-Compatible" content='ie=edge'>
<title>mskor</title>
<meta name="keywords" content="mskor, rust, c, c++, developer, software engineer, back-end, full-stack, portfolio, blog">
<title>Newcastle AOC</title>
<meta name="keywords" content="newcastle, apartheid, campus, university, demands">
<link rel="stylesheet" id="css" href="style.css">
<script src="https://unpkg.com/htmx.org@1.9.2" integrity="sha384-L6OqL9pRWyyFU3+/bjdSri+iIphTN/bvYyM37tICVyOJkWZLpP2vGn6VUEXgzg6h" crossorigin="anonymous"></script>
</head>
<header>
<h1>mskor</h1>
<hr>
<nav>
<a href="" hx-get="/home" hx-target="#content" hx-swap="innerHTML" hx-trigger="load">home</a>
<a href="" hx-get="/git" hx-target="#content" hx-swap="innerHTML">git</a>
<a href="" hx-get="/blog" hx-target="#content" hx-swap="innerHTML">blog</a>
<a href="" hx-get="/resume" hx-target="#content" hx-swap="innerHTML">resume</a>
<a href="" hx-get="/contact" hx-target="#content" hx-swap="innerHTML">contact</a>
</nav>
<hr>
</header>
<body>
<div id="header">
<a href="/index">
<img src="logo.png" id="logo">
<h1>Newcastle Apartheid Off Campus</h1>
</a>
<nav>
<a href="/demands">Demands</a>
<a href="/facts">Facts</a>
<a href="/resources">Resources</a>
<a href="/join_us">Join us!</a>
<a href="/faqs">FAQs</a>
</nav>
</div>
<div id="content">
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{
.thread_safe = true,
}){};
const allocator = gpa.allocator();
var router = zap.Router.init(allocator, .{
.not_found = not_found,
});
defer router.deinit();
var web_router = WebRouter.init(allocator);
try router.handle_func("/home", &web_router, &WebRouter.home);
try router.handle_func("/index", &web_router, &WebRouter.index);
try router.handle_func("/", &web_router, &WebRouter.index);
var listener = zap.HttpListener.init(.{ .port = 3000, .on_request = router.on_request_handler(), .log = true, .max_clients = 100000, .public_folder = "src/public" });
try listener.listen();
std.debug.print("Listening on 0.0.0.0:3000\n", .{});
zap.start(.{
.threads = 2,
.workers = 1, // 1 worker enables sharing state between threads
});
}
</div>
</body>

BIN
src/public/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 KiB

View file

@ -1,4 +1,4 @@
html {
body {
max-width:70%;
margin:40px auto;
font-size:18px;
@ -9,7 +9,7 @@ html {
a {
text-decoration:none;
color:MediumSeaGreen;
color:Black;
}
td {
@ -27,6 +27,24 @@ img {
height:100%;
}
#header {
position:relative;
padding:5px;
background-color:#123;
top:0px;
}
#header img {
float:left;
display:block;
width:25%;
height:25%;
top:0px;
object-fit:scale-down;
}
@media (prefers-color-scheme:dark) {
body {
background-color:#222;