]> jxnshi.xyz Git - jxnshi.xyz.git/commitdiff
Add writings nav
authorjxnshi <jxnshi@cock.li>
Mon, 31 Mar 2025 09:11:00 +0000 (11:11 +0200)
committerjxnshi <jxnshi@cock.li>
Mon, 31 Mar 2025 09:11:00 +0000 (11:11 +0200)
public/style.css
src/main.zig

index ffb6ded276ce1294a864db48b333067f156a513b..926611ad581293d7344ae669443d6e4f694c8973 100644 (file)
@@ -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;
index e262286d01a0f0675d060d8390784c55d4de0456..8b0000a3b5e502c033f6b28c1370e2c3a34cad82 100644 (file)
@@ -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("<div id=\"writings-nav\">");
+
+                    if (writingNavButtonPath(.prev, route)) |path| {
+                        try temp_buffer_writer.print("<a href=\"{s}\">Previous</a>", .{path});
+                    }
+
+                    if (writingNavButtonPath(.next, route)) |path| {
+                        try temp_buffer_writer.print("<a href=\"{s}\">Next</a>", .{path});
+                    }
+
+                    try temp_buffer_writer.writeAll("</div>");
+
                     break :no_index_file;
                 }
             }