size: 1 KiB
| 1 | const std = @import("std"); |
| 2 | const mem = std.mem; |
| 3 | const Io = std.Io; |
| 4 | const fmt = std.fmt; |
| 5 | |
| 6 | const html = @import("html.zig"); |
| 7 | const feed = @import("feed.zig"); |
| 8 | |
| 9 | // Remember to close with base_end() |
| 10 | pub fn base_start(arena: mem.Allocator, writer: *Io.Writer, args: struct { |
| 11 | site_name: []const u8 = "loa", |
| 12 | title: ?[]const u8 = null, |
| 13 | opengraph: struct { |
| 14 | title: []const u8, |
| 15 | description: []const u8, |
| 16 | }, |
| 17 | }) !void { |
| 18 | try writer.print( |
| 19 | \\<!doctype html> |
| 20 | \\<html lang="en"> |
| 21 | \\ <head> |
| 22 | \\ <meta charset="utf-8" /> |
| 23 | \\ <title>{0s}</title> |
| 24 | \\ <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 25 | \\ |
| 26 | \\ <meta property="og:site_name" content="{1s}" /> |
| 27 | \\ <meta property="og:title" content="{2s}" /> |
| 28 | \\ <meta property="og:description" content="{3s}" /> |
| 29 | \\ |
| 30 | \\ <link href="/{4s}" type="application/atom+xml" rel="alternate" title="Sitewide Atom feed" /> |
| 31 | \\ |
| 32 | \\ <link rel="stylesheet" href="/_loa/style.css"> |
| 33 | \\ <script src="/_loa/script.js"></script> |
| 34 | \\ </head> |
| 35 | \\ <body> |
| 36 | \\ <main> |
| 37 | \\ |
| 38 | , .{ |
| 39 | if (args.title) |title| |
| 40 | try html.escapeAlloc( |
| 41 | arena, |
| 42 | try fmt.allocPrint(arena, "{s} | {s}", .{ title, args.site_name }), |
| 43 | ) |
| 44 | else |
| 45 | args.site_name, |
| 46 | args.site_name, |
| 47 | try html.escapeAlloc(arena, args.opengraph.title), |
| 48 | try html.escapeAlloc(arena, args.opengraph.description), |
| 49 | feed.feed_path, |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | pub fn base_end(writer: *Io.Writer) !void { |
| 54 | try writer.print( |
| 55 | \\ </main> |
| 56 | \\ <footer> |
| 57 | \\ <div><a href="/{s}">rss feed</a></div> |
| 58 | \\ <div>made with <a href="https://khoe.thac.loan/_/loa/" target="_blank">loa</a></div> |
| 59 | \\ </footer> |
| 60 | \\ </body> |
| 61 | \\</html> |
| 62 | \\ |
| 63 | , .{feed.feed_path}); |
| 64 | } |