From cc114d87fe8fc2553e8c8bf687f657d567126f2c Mon Sep 17 00:00:00 2001 From: jxnshi Date: Mon, 31 Mar 2025 11:11:00 +0200 Subject: [PATCH] Add writings nav --- public/style.css | 9 +++++++++ src/main.zig | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/public/style.css b/public/style.css index ffb6ded..926611a 100644 --- a/public/style.css +++ b/public/style.css @@ -185,6 +185,15 @@ a:hover { box-shadow: 10px 10px black; } +#writings-nav { + display: flex; + gap: 20px; +} + +#writings-nav > a { + font-size: 32px; +} + /* Gitweb */ .page_header { display: flex; diff --git a/src/main.zig b/src/main.zig index e262286..8b0000a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,6 +2,25 @@ const std = @import("std"); const markdownToHtml = @import("md_to_html.zig").markdownToHtml; +const writings_nav_buttons_paths = .{ + .{ "writings/books/le-monde-de-ponpon/chapter-1", null, "/writings/books/le-monde-de-ponpon/chapter-2" }, + .{ "writings/books/le-monde-de-ponpon/chapter-2", "/writings/books/le-monde-de-ponpon/chapter-1", "/writings/books/le-monde-de-ponpon/chapter-3" }, + .{ "writings/books/le-monde-de-ponpon/chapter-3", "/writings/books/le-monde-de-ponpon/chapter-2", null }, +}; + +fn writingNavButtonPath(comptime kind: enum { prev, next }, path: []const u8) ?[]const u8 { + inline for (writings_nav_buttons_paths) |nav_buttons_paths| { + if (std.mem.eql(u8, nav_buttons_paths[0], path)) { + switch (kind) { + .prev => return nav_buttons_paths[1], + .next => return nav_buttons_paths[2], + } + } + } + + return null; +} + fn parentDirPath(path: []const u8) ?[]const u8 { for (0..path.len) |idx| { const i = path.len - idx - 1; @@ -172,6 +191,18 @@ fn handleClient(parent_allocator: std.mem.Allocator, connection: std.net.Server. try markdownToHtml(temp_buffer_writer.any(), md_file_reader.any()); + try temp_buffer_writer.writeAll("
"); + + if (writingNavButtonPath(.prev, route)) |path| { + try temp_buffer_writer.print("Previous", .{path}); + } + + if (writingNavButtonPath(.next, route)) |path| { + try temp_buffer_writer.print("Next", .{path}); + } + + try temp_buffer_writer.writeAll("
"); + break :no_index_file; } } -- 2.49.0