diff options
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Justfile | 5 | ||||
| -rw-r--r-- | build.zig | 23 | ||||
| -rw-r--r-- | flake.nix | 5 | ||||
| -rw-r--r-- | src/static/hello.txt | 1 | ||||
| -rw-r--r-- | util/website.zig | 37 |
6 files changed, 67 insertions, 6 deletions
@@ -1,3 +1,5 @@ /.direnv /.envrc +/html-out +/.zig-cache *.tar.gz diff --git a/Justfile b/Justfile deleted file mode 100644 index df17baa..0000000 --- a/Justfile +++ /dev/null @@ -1,5 +0,0 @@ -serve: - lighttpd -Df util/lighttpd.conf - -package: - tar -czvf etc.tar.gz src/* diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..7f8dec1 --- /dev/null +++ b/build.zig @@ -0,0 +1,23 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const generate_html = b.addExecutable(.{ + .name = "generate_html", + .root_module = b.createModule(.{ + .root_source_file = b.path("util/website.zig"), + .target = b.graph.host, + }), + }); + + const run_generate_html = b.addRunArtifact(generate_html); + run_generate_html.setCwd(b.path("")); // make sure we always run from buildroot + b.getInstallStep().dependOn(&run_generate_html.step); + + const bundle_html = b.addSystemCommand(&[_][]const u8{ "tar", "--exclude=pages.tar.gz", "-czvf", "html-out/pages.tar.gz", "html-out" }); + const run_bundle_html = b.step("bundle", "Creates a tarball of the HTML output"); + bundle_html.step.dependOn(b.getInstallStep()); + run_bundle_html.dependOn(&bundle_html.step); + + const publish_to_prod = b.step("publish", "Publish the website to production"); + _ = publish_to_prod; +} @@ -19,9 +19,12 @@ { devShells.default = pkgs.mkShellNoCC { nativeBuildInputs = with pkgs; [ - just + gnutar lighttpd + openssh vscode-langservers-extracted + zig + zls ]; }; diff --git a/src/static/hello.txt b/src/static/hello.txt new file mode 100644 index 0000000..4effa19 --- /dev/null +++ b/src/static/hello.txt @@ -0,0 +1 @@ +hello! diff --git a/util/website.zig b/util/website.zig new file mode 100644 index 0000000..837a51c --- /dev/null +++ b/util/website.zig @@ -0,0 +1,37 @@ +const std = @import("std"); + +pub fn main(init: std.process.Init) !void { + const sources_dir = try std.Io.Dir.cwd().createDirPathOpen(init.io, "src", .{}); + defer sources_dir.close(init.io); + const templates_dir = try sources_dir.createDirPathOpen(init.io, "templates", .{ .open_options = .{ .iterate = true } }); + defer templates_dir.close(init.io); + const pages_dir = try sources_dir.createDirPathOpen(init.io, "pages", .{ .open_options = .{ .iterate = true } }); + defer pages_dir.close(init.io); + const out_dir = try std.Io.Dir.cwd().createDirPathOpen(init.io, "html-out", .{}); + defer out_dir.close(init.io); + const static_dir = try sources_dir.createDirPathOpen(init.io, "static", .{ .open_options = .{ .iterate = true } }); + defer static_dir.close(init.io); + + try copyStaticFiles(init.io, init.gpa, static_dir, out_dir); +} + +fn copyStaticFiles(io: std.Io, ally: std.mem.Allocator, sources: std.Io.Dir, out: std.Io.Dir) !void { + var walker = try sources.walk(ally); + defer walker.deinit(); + while (try walker.next(io)) |entry| { + switch (entry.kind) { + .file, .sym_link => { + std.debug.print("Copying static file {s}...\n", .{entry.basename}); + try entry.dir.copyFile(entry.basename, out, entry.basename, io, .{}); + }, + + .directory => { + const new_out = try out.createDirPathOpen(io, entry.basename, .{ .open_options = .{ .iterate = true } }); + defer new_out.close(io); + try copyStaticFiles(io, ally, sources, out); + }, + + else => {}, + } + } +} |
