diff options
Diffstat (limited to '')
| -rw-r--r-- | src/exe.zig | 16 | ||||
| -rw-r--r-- | src/fs.zig | 14 | ||||
| -rw-r--r-- | src/gen.zig | 26 | ||||
| -rw-r--r-- | src/main.zig | 18 |
4 files changed, 37 insertions, 37 deletions
diff --git a/src/exe.zig b/src/exe.zig index d5bc239..06e7a4d 100644 --- a/src/exe.zig +++ b/src/exe.zig @@ -4,7 +4,7 @@ const log = std.log.scoped(.exe); const Context = @import("main.zig").Context; const fs = @import("fs.zig"); -pub fn run_pandoc(ctx: *Context) !void { +pub fn runPandoc(ctx: *Context) !void { ctx.progress_start("Processing markdown files"); defer ctx.progress_end(); @@ -21,7 +21,7 @@ pub fn run_pandoc(ctx: *Context) !void { // https://github.com/ziglang/zig/issues/18810 try pool.spawn(struct { fn worker(worker_ctx: *Context, worker_page: *const []const u8) void { - pandoc_worker(worker_ctx, worker_page.*) catch |err| std.log.err("pandoc worker failed with: {}", .{err}); + pandocWorker(worker_ctx, worker_page.*) catch |err| std.log.err("pandoc worker failed with: {}", .{err}); } }.worker, .{ ctx, page }); } @@ -29,10 +29,10 @@ pub fn run_pandoc(ctx: *Context) !void { log.info("Processed {d} markdown files.", .{ctx.markdown.items.len}); } -fn pandoc_worker(ctx: *Context, page: []const u8) !void { +fn pandocWorker(ctx: *Context, page: []const u8) !void { const source_path = try std.fs.path.join(ctx.allocator(), &.{ Context.params.PAGE_PATH, page }); defer ctx.allocator().free(source_path); - const target_path = try fs.replace_extension(ctx.allocator(), source_path, "htm"); + const target_path = try fs.replaceExtension(ctx.allocator(), source_path, "htm"); defer ctx.allocator().free(target_path); const f = try fs.FileSwapper.createAt(ctx.allocator(), target_path); @@ -46,8 +46,8 @@ fn pandoc_worker(ctx: *Context, page: []const u8) !void { ); // get mtime of the source document - const mtime = try fs.get_mtime(ctx.allocator(), source_path); - const mtime_str = try fs.format_mtime(ctx.allocator(), mtime, "%s"); + const mtime = try fs.getMtime(ctx.allocator(), source_path); + const mtime_str = try fs.formatMtime(ctx.allocator(), mtime, "%s"); defer ctx.allocator().free(mtime_str); // make pandoc runs reproducable @@ -55,7 +55,7 @@ fn pandoc_worker(ctx: *Context, page: []const u8) !void { defer env_map.deinit(); try env_map.put("SOURCE_DATE_EPOCH", mtime_str); - try capture_stdout(ctx, &.{ + try captureStdout(ctx, &.{ Context.params.PANDOC, "--from", "markdown+wikilinks_title_after_pipe+autolink_bare_uris", @@ -70,7 +70,7 @@ fn pandoc_worker(ctx: *Context, page: []const u8) !void { }, &env_map, f.writer().any()); } -pub fn capture_stdout(ctx: *Context, argv: []const []const u8, env_map: ?*std.process.EnvMap, buf: std.io.AnyWriter) !void { +pub fn captureStdout(ctx: *Context, argv: []const []const u8, env_map: ?*std.process.EnvMap, buf: std.io.AnyWriter) !void { const command = try std.mem.join(ctx.allocator(), " ", argv); defer ctx.allocator().free(command); const label = try std.fmt.allocPrint(ctx.allocator(), "running {s}", .{command}); diff --git a/src/fs.zig b/src/fs.zig index 7a8717a..d29ee05 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -65,10 +65,10 @@ pub const FileSwapper = struct { } }; -pub fn replace_extension(alloc: std.mem.Allocator, p: []const u8, new: []const u8) ![]const u8 { +pub fn replaceExtension(alloc: std.mem.Allocator, p: []const u8, new: []const u8) ![]const u8 { const dirname = std.fs.path.dirname(p) orelse "."; - const basename = try strip_extension(std.fs.path.basename(p)); - return try join_path_and_filename( + const basename = try stripExtension(std.fs.path.basename(p)); + return try joinPathAndFilename( alloc, &.{dirname}, &.{ basename, ".", new }, @@ -76,14 +76,14 @@ pub fn replace_extension(alloc: std.mem.Allocator, p: []const u8, new: []const u } // also trims off base paths -pub fn strip_extension(path: []const u8) ![]const u8 { +pub fn stripExtension(path: []const u8) ![]const u8 { const ext = std.fs.path.extension(path); const ext_idx = std.mem.indexOfPosLinear(u8, path, 0, ext); std.debug.assert(ext_idx != null); return path[0..ext_idx.?]; } -pub fn join_path_and_filename(alloc: std.mem.Allocator, paths: []const []const u8, filename_parts: []const []const u8) ![]const u8 { +pub fn joinPathAndFilename(alloc: std.mem.Allocator, paths: []const []const u8, filename_parts: []const []const u8) ![]const u8 { const filename = try std.mem.concat(alloc, u8, filename_parts); defer alloc.free(filename); @@ -100,7 +100,7 @@ pub fn join_path_and_filename(alloc: std.mem.Allocator, paths: []const []const u return try std.fs.path.join(alloc, paths2); } -pub fn get_mtime(alloc: std.mem.Allocator, path: []const u8) !std.os.linux.timespec { +pub fn getMtime(alloc: std.mem.Allocator, path: []const u8) !std.os.linux.timespec { const attr = try alloc.create(std.os.linux.Stat); defer alloc.destroy(attr); @@ -115,7 +115,7 @@ pub fn get_mtime(alloc: std.mem.Allocator, path: []const u8) !std.os.linux.times } // use libc strftime to format time string -pub fn format_mtime(alloc: std.mem.Allocator, mtime: std.os.linux.timespec, fmt: [*c]const u8) ![]const u8 { +pub fn formatMtime(alloc: std.mem.Allocator, mtime: std.os.linux.timespec, fmt: [*c]const u8) ![]const u8 { const mtime_str = try alloc.alloc(u8, std.os.linux.PATH_MAX); var tm: c.struct_tm = undefined; _ = c.localtime_r(&mtime.sec, &tm); diff --git a/src/gen.zig b/src/gen.zig index 6d2f124..0504d39 100644 --- a/src/gen.zig +++ b/src/gen.zig @@ -22,7 +22,7 @@ fn genIndexHtml(ctx: *Context) !void { ctx.progress_start("index.html"); defer ctx.progress_end(); - const srcpathIndex = try fs.join_path_and_filename(ctx.allocator(), &.{Context.params.PAGE_PATH}, &.{"index.htm"}); + const srcpathIndex = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.PAGE_PATH}, &.{"index.htm"}); defer ctx.allocator().free(srcpathIndex); const f = try fs.FileSwapper.createAt(ctx.allocator(), srcpathIndex); @@ -48,8 +48,8 @@ fn genIndexHtml(ctx: *Context) !void { for (ctx.pages.items) |p| { if (std.mem.startsWith(u8, p, "meta.")) continue; - const dstname = try fs.strip_extension(p); - const dstpath = try fs.join_path_and_filename(ctx.allocator(), &.{Context.params.SITE_PATH}, &.{ dstname, ".html" }); + const dstname = try fs.stripExtension(p); + const dstpath = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.SITE_PATH}, &.{ dstname, ".html" }); defer ctx.allocator().free(dstpath); try f.writer().print( @@ -79,10 +79,10 @@ fn genSite(ctx: *Context) !void { continue; } - const dstname = try fs.strip_extension(p); - const srcpath = try fs.join_path_and_filename(ctx.allocator(), &.{Context.params.PAGE_PATH}, &.{ dstname, ".htm" }); + const dstname = try fs.stripExtension(p); + const srcpath = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.PAGE_PATH}, &.{ dstname, ".htm" }); defer ctx.allocator().free(srcpath); - const dstpath = try fs.join_path_and_filename(ctx.allocator(), &.{Context.params.SITE_PATH}, &.{ dstname, ".html" }); + const dstpath = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.SITE_PATH}, &.{ dstname, ".html" }); defer ctx.allocator().free(dstpath); const rel_dstpath = try std.fs.path.relative(ctx.allocator(), Context.params.SITE_PATH, dstpath); defer ctx.allocator().free(rel_dstpath); @@ -90,7 +90,7 @@ fn genSite(ctx: *Context) !void { log.debug("generating {s} at {s}", .{ p, rel_dstpath }); if (std.fs.path.dirname(rel_dstpath)) |d| { - const dstdir = try fs.join_path_and_filename(ctx.allocator(), &.{Context.params.SITE_PATH}, &.{d}); + const dstdir = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.SITE_PATH}, &.{d}); defer ctx.allocator().free(dstdir); try std.fs.cwd().makePath(dstdir); @@ -109,8 +109,8 @@ fn genSite(ctx: *Context) !void { // build a single html file fn build(allocator: std.mem.Allocator, w: std.io.AnyWriter, page_name: []const u8, srcpath: []const u8) !void { - const mtime = try fs.get_mtime(allocator, srcpath); - const mtime_str = try fs.format_mtime(allocator, mtime, "%F"); + const mtime = try fs.getMtime(allocator, srcpath); + const mtime_str = try fs.formatMtime(allocator, mtime, "%F"); defer allocator.free(mtime_str); // HEAD @@ -208,9 +208,9 @@ fn meta(ctx: *Context, p: []const u8) !void { if (std.mem.startsWith(u8, p, "meta.tilde.")) { const dot = std.mem.indexOfPosLinear(u8, p, 11, "."); const dstname = p[11..dot.?]; - const srcpath = try fs.join_path_and_filename(ctx.allocator(), &.{Context.params.PAGE_PATH}, &.{p}); + const srcpath = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.PAGE_PATH}, &.{p}); defer ctx.allocator().free(srcpath); - const dstpath = try fs.join_path_and_filename(ctx.allocator(), &.{Context.params.LINK_PATH}, &.{ "~", dstname }); + const dstpath = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.LINK_PATH}, &.{ "~", dstname }); defer ctx.allocator().free(dstpath); const link = blk: { @@ -333,8 +333,8 @@ const Page = struct { const endofref = std.mem.lastIndexOf(u8, refname, "#") orelse refname.len; const basename = try std.mem.replaceOwned(u8, arena.allocator(), refname[0..endofref], " ", "_"); - const html = try fs.join_path_and_filename(arena.allocator(), &.{Context.params.SITE_PATH}, &.{ basename, ".html" }); - const htm = try fs.join_path_and_filename(arena.allocator(), &.{Context.params.PAGE_PATH}, &.{ basename, ".htm" }); + const html = try fs.joinPathAndFilename(arena.allocator(), &.{Context.params.SITE_PATH}, &.{ basename, ".html" }); + const htm = try fs.joinPathAndFilename(arena.allocator(), &.{Context.params.PAGE_PATH}, &.{ basename, ".htm" }); try std.fs.cwd().access(htm, .{ .mode = .read_only }); diff --git a/src/main.zig b/src/main.zig index faa37aa..f64bfad 100644 --- a/src/main.zig +++ b/src/main.zig @@ -146,24 +146,24 @@ const Cli = struct { var argv = std.process.args(); const more = argv.skip(); // skip arg0 - if (!more) return &Cli.help_cmd; + if (!more) return &Cli.helpCmd; - const next_arg = argv.next() orelse return &Cli.help_cmd; + const next_arg = argv.next() orelse return &Cli.helpCmd; if (std.mem.eql(u8, next_arg, "gen")) { - return &Cli.gen_cmd; + return &Cli.genCmd; } else if (std.mem.eql(u8, next_arg, "md")) { - return &Cli.gen_md_cmd; + return &Cli.genMdCmd; } else { - return &Cli.help_cmd; + return &Cli.helpCmd; } } - fn help_cmd(_: *Context) void { + fn helpCmd(_: *Context) void { std.debug.print("usage: rbl [gen|md]\n\n", .{}); } - fn gen_cmd(ctx: *Context) void { + fn genCmd(ctx: *Context) void { index(ctx) catch { log.err("Failed to index pages.", .{}); std.os.linux.exit(1); @@ -175,13 +175,13 @@ const Cli = struct { }; } - fn gen_md_cmd(ctx: *Context) void { + fn genMdCmd(ctx: *Context) void { index(ctx) catch { log.err("Failed to index pages.", .{}); std.os.linux.exit(1); }; - exe.run_pandoc(ctx) catch { + exe.runPandoc(ctx) catch { log.err("Failed to process markdown files.", .{}); std.os.linux.exit(1); }; |