diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gen.zig | 29 | ||||
| -rw-r--r-- | src/main.zig | 1 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/gen.zig b/src/gen.zig index 3e5fa9b..4b9735d 100644 --- a/src/gen.zig +++ b/src/gen.zig @@ -3,6 +3,33 @@ const std = @import("std"); const log = std.log.scoped(.gen); const Context = @import("main.zig").Context; const fs = @import("fs.zig"); +const exe = @import("exe.zig"); + +pub fn fixMtimes(ctx: *Context) !void { + ctx.progress_start("Fix mtimes"); + defer ctx.progress_end(); + + var counter: usize = 0; + for (ctx.pages.items) |p| { + ctx.progress_start(p); + defer ctx.progress_end(); + + const path = try fs.joinPathAndFilename(ctx.allocator(), &.{Context.params.PAGE_PATH}, &.{p}); + defer ctx.allocator().free(path); + + const mdpath = try fs.replaceExtension(ctx.allocator(), p, "md"); + defer ctx.allocator().free(mdpath); + + std.fs.cwd().access(mdpath, .{ .mode = .read_only }) catch { + // only set mtime from git if no markdown source is used + const ts = fs.getGitTime(path) catch continue; + try fs.setMtime(path, ts); + counter += 1; + }; + } + + log.info("Retimed {d} pages.", .{counter}); +} pub fn generate(ctx: *Context) !void { ctx.progress_start("generate"); @@ -111,7 +138,7 @@ 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.getGitTime(srcpath) catch fs.getMtime(srcpath)); + const mtime = try fs.getMtime(srcpath); const mtime_str = try fs.formatTimespec(allocator, mtime, "%F"); defer allocator.free(mtime_str); diff --git a/src/main.zig b/src/main.zig index f1d3cda..8e0b27e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -174,6 +174,7 @@ const Cli = struct { fn genCmd(ctx: *Context) !void { try index(ctx); + try gen.fixMtimes(ctx); try gen.generate(ctx); } |