From 52b4f046918e7ccbb114762f3f58302c59d9e2a2 Mon Sep 17 00:00:00 2001
From: Robert Günzler
Date: Sat, 24 May 2025 03:45:11 +0200
Subject: add webarchive links to like page
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Robert Günzler
---
src/inc/index.htm | 1 +
src/inc/like.htm | 22 ++++++++++++++++------
src/inc/like.md | 10 ++++++----
src/main.zig | 46 +++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 66 insertions(+), 13 deletions(-)
(limited to 'src')
diff --git a/src/inc/index.htm b/src/inc/index.htm
index fdd90d9..3778d31 100644
--- a/src/inc/index.htm
+++ b/src/inc/index.htm
@@ -1,4 +1,5 @@
diff --git a/src/inc/like.md b/src/inc/like.md
index f69feb7..1b88327 100644
--- a/src/inc/like.md
+++ b/src/inc/like.md
@@ -1,12 +1,14 @@
here's some stuff i like:
-- https://tailscale.com/blog/plan9-port
-- https://anniemueller.com/posts/in-praise-of-creating-crap
-- https://www.math.uwaterloo.ca/tsp/korea/index.html
+- https://tailscale.com/blog/plan9-port [^[?]^](https://web.archive.org/web/20250403135024/https://tailscale.com/blog/plan9-port)
+- https://anniemueller.com/posts/in-praise-of-creating-crap [^[?]^](https://web.archive.org/web/20250524011520/https://anniemueller.com/posts/in-praise-of-creating-crap)
+- https://www.math.uwaterloo.ca/tsp/korea/index.html [^[?]^](https://web.archive.org/web/20250524011652/https://www.math.uwaterloo.ca/tsp/korea/index.html)
> It’s not that user experience designers are trying to kill curiosity. They’re
> trying to help. But help, at scale, becomes architecture. And architecture
> shapes cognition. The interfaces we use become metaphors for how we think the
> world works. If your phone always gives you the answer, you stop asking
> better questions.
-{style="float:right"}
+> [^[?]^]()
+
+
diff --git a/src/main.zig b/src/main.zig
index 64b76d9..e6ed977 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -364,14 +364,54 @@ fn genSite(ctx: *Context) !void {
}
}
+const FileSwapper = struct {
+ allocator: std.mem.Allocator,
+ target_path: []const u8,
+ tmp_path: []const u8,
+ tmp: std.fs.File,
+
+ fn createAt(allocator: std.mem.Allocator, path: []const u8) !FileSwapper {
+ const target_dir = std.fs.path.dirname(path) orelse ".";
+ const target_name = std.fs.path.basename(path);
+
+ const tmp_name = try std.fmt.allocPrint(allocator, ".{s}", .{target_name});
+ defer allocator.free(tmp_name);
+
+ const tmp_path = try std.fs.path.join(allocator, &.{ target_dir, tmp_name });
+
+ const f = try std.fs.cwd().createFile(tmp_path, .{});
+
+ return .{
+ .allocator = allocator,
+ .target_path = path,
+ .tmp_path = tmp_path,
+ .tmp = f,
+ };
+ }
+
+ fn writer(self: FileSwapper) std.fs.File.Writer {
+ return self.tmp.writer();
+ }
+
+ fn close(self: FileSwapper) void {
+ defer self.allocator.free(self.tmp_path);
+ defer self.tmp.close();
+
+ self.tmp.sync() catch @panic("sync tmp file");
+
+ std.debug.print("??? {s} => {s}\n", .{ self.tmp_path, self.target_path });
+ std.fs.rename(std.fs.cwd(), self.tmp_path, std.fs.cwd(), self.target_path) catch @panic("rename tmp file");
+ }
+};
+
fn genIndexHtml(ctx: *Context) !void {
const srcpathIndex = try joinIn(ctx.allocator, &.{PAGE_PATH}, &.{"index.htm"});
defer ctx.allocator.free(srcpathIndex);
- const f = try std.fs.cwd().createFile(srcpathIndex, .{});
+ const f = try FileSwapper.createAt(ctx.allocator, srcpathIndex);
defer f.close();
- try f.writeAll(
+ try f.writer().writeAll(
\\
\\
);
@@ -404,7 +444,7 @@ fn genIndexHtml(ctx: *Context) !void {
});
}
- try f.writeAll(
+ try f.writer().writeAll(
\\
\\
);
--
cgit 1.4.1