Skip to content

Commit

Permalink
more join conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-it committed Oct 23, 2024
1 parent 734ff04 commit b058d86
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/context/Page.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const render = @import("../render.zig");
const Signature = @import("doctypes.zig").Signature;
const DateTime = @import("DateTime.zig");
const context = @import("../context.zig");
const join = @import("../root.zig").join;
const Allocator = std.mem.Allocator;
const Value = context.Value;
const Optional = context.Optional;
Expand Down Expand Up @@ -698,9 +699,7 @@ pub const Builtins = struct {
false => p[0 .. p.len - ".smd".len],
};

// TODO: support host url overrides

const result = try std.fs.path.join(gpa, &.{
const result = try join(gpa, &.{
"/",
self._meta.site._meta.url_path_prefix,
path,
Expand Down
3 changes: 2 additions & 1 deletion src/context/Site.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Allocator = std.mem.Allocator;
const scripty = @import("scripty");
const utils = @import("utils.zig");
const context = @import("../context.zig");
const join = @import("../root.zig").join;
const Signature = @import("doctypes.zig").Signature;
const Value = context.Value;
const Bool = context.Bool;
Expand Down Expand Up @@ -131,7 +132,7 @@ pub const Builtins = struct {
};
if (args.len != 0) return bad_arg;

const url = std.fs.path.join(gpa, &.{
const url = join(gpa, &.{
"/",
p._meta.url_path_prefix,
"/",
Expand Down
3 changes: 2 additions & 1 deletion src/exes/layout.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const options = @import("options");
const ziggy = @import("ziggy");
const superhtml = @import("superhtml");
const cache = @import("layout/cache.zig");
const join = @import("../root.zig").join;
const zine = @import("zine");
const context = zine.context;
const DepWriter = @import("layout/DepWriter.zig");
Expand Down Expand Up @@ -229,7 +230,7 @@ pub fn main() !void {
error.WantSnippet => @panic("TODO: looad snippet"),
error.WantTemplate => {
const template_name = super_vm.wantedTemplateName();
const template_path = try std.fs.path.join(arena, &.{
const template_path = try join(arena, &.{
build_root_path,
templates_dir_path,
template_name,
Expand Down
39 changes: 20 additions & 19 deletions src/exes/layout/cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const std = @import("std");
const supermd = @import("supermd");
const ziggy = @import("ziggy");
const zine = @import("zine");
const join = zine.join;
const context = zine.context;
const Allocator = std.mem.Allocator;
const DepWriter = @import("DepWriter.zig");
Expand Down Expand Up @@ -156,7 +157,7 @@ pub const pages = struct {
index_in_section: ?usize,
is_root_page: bool,
) error{ OutOfMemory, PageLoad }!*context.Page {
const full_path = try std.fs.path.join(gpa, &.{
const full_path = try join(gpa, &.{
site._meta.content_dir_path,
md_rel_path,
});
Expand Down Expand Up @@ -187,7 +188,7 @@ const page_finder = struct {

fn init(build_root_path: []const u8) error{OutOfMemory}!void {
_ = build_root_path;
page_finder.page_index_dir_path = try std.fs.path.join(
page_finder.page_index_dir_path = try join(
gpa,
&.{
// build_root_path,
Expand All @@ -204,7 +205,7 @@ const page_finder = struct {
// - foo/bar.smd
// - foo/bar/index.smd

var md_path = try std.fs.path.join(gpa, &.{
var md_path = try join(gpa, &.{
ref.site._meta.content_dir_path,
ref.path,
"index.smd",
Expand Down Expand Up @@ -258,7 +259,7 @@ const page_finder = struct {
.simple => "",
.multi => |m| m.code,
};
const index_path = try std.fs.path.join(gpa, &.{
const index_path = try join(gpa, &.{
page_index_dir_path,
prefix,
page._meta.parent_section_path.?,
Expand Down Expand Up @@ -319,7 +320,7 @@ const page_finder = struct {
.simple => "",
.multi => |m| m.code,
};
const index_path = try std.fs.path.join(gpa, &.{
const index_path = try join(gpa, &.{
page_index_dir_path,
prefix,
path[0 .. path.len - "index.smd".len],
Expand Down Expand Up @@ -385,11 +386,11 @@ const asset_finder = struct {
build_root_path: []const u8,
_assets_dir_path: []const u8,
) error{OutOfMemory}!void {
asset_finder.assets_dir_path = try std.fs.path.join(gpa, &.{
asset_finder.assets_dir_path = try join(gpa, &.{
build_root_path,
_assets_dir_path,
});
asset_finder.build_index_dir_path = try std.fs.path.join(
asset_finder.build_index_dir_path = try join(
gpa,
&.{ index_dir_path, "a" },
);
Expand All @@ -409,7 +410,7 @@ const asset_finder = struct {
const entry_name = std.fmt.bufPrint(&buf, "{x}", .{
hash,
}) catch unreachable;
const full_path = try std.fs.path.join(gpa, &.{
const full_path = try join(gpa, &.{
asset_finder.build_index_dir_path,
entry_name,
});
Expand Down Expand Up @@ -468,7 +469,7 @@ const asset_finder = struct {
});
};

const full_path = try std.fs.path.join(gpa, &.{
const full_path = try join(gpa, &.{
base_path,
ref,
});
Expand Down Expand Up @@ -524,7 +525,7 @@ const asset_collector = struct {
else => "",
};

const install_path = try std.fs.path.join(gpa, &.{
const install_path = try join(gpa, &.{
asset_collector.output_path_prefix,
maybe_page_rel_path,
install_rel_path,
Expand Down Expand Up @@ -553,19 +554,19 @@ const asset_collector = struct {
gpa,
&.{},
);
break :blk std.fs.path.join(gpa, &.{
break :blk join(gpa, &.{
page_link.string.value,
ref,
});
},
// Links to site assets are absolute
.site => try std.fs.path.join(gpa, &.{
.site => try join(gpa, &.{
"/",
asset_collector.url_path_prefix,
ref,
}),
// Links to build assets are absolute
.build => |bip| try std.fs.path.join(gpa, &.{
.build => |bip| try join(gpa, &.{
"/",
asset_collector.url_path_prefix,
bip.?,
Expand Down Expand Up @@ -606,7 +607,7 @@ fn loadPage(
});
var time = std.time.Timer.start() catch unreachable;

const md_path = try std.fs.path.join(gpa, &.{
const md_path = try join(gpa, &.{
site._meta.content_dir_path,
md_rel_path,
});
Expand Down Expand Up @@ -669,7 +670,7 @@ fn loadPage(
hash.update(path_to_hash);
}

const ps_index_file_path = try std.fs.path.join(gpa, &.{
const ps_index_file_path = try join(gpa, &.{
index_dir_path,
"ps",
try std.fmt.allocPrint(gpa, "{x}", .{hash.final()}),
Expand Down Expand Up @@ -699,7 +700,7 @@ fn loadPage(
const iis: ?usize = index_in_section orelse blk: {
const ps_path = psp orelse break :blk null;

const ps_file_path = try std.fs.path.join(gpa, &.{
const ps_file_path = try join(gpa, &.{
index_dir_path,
"s",

Expand Down Expand Up @@ -759,7 +760,7 @@ fn loadPage(
};

if (page.translation_key) |tk| {
const tk_index_path = try std.fs.path.join(gpa, &.{ index_dir_path, "tk", tk });
const tk_index_path = try join(gpa, &.{ index_dir_path, "tk", tk });
const tk_index = try std.fs.cwd().readFileAlloc(
gpa,
tk_index_path,
Expand Down Expand Up @@ -989,7 +990,7 @@ fn loadPage(
);

const end = md_rel_path.len - "index.smd".len;
break :sub try std.fs.path.join(gpa, &.{
break :sub try join(gpa, &.{
md_rel_path[0..end],
p.ref,
});
Expand All @@ -1005,7 +1006,7 @@ fn loadPage(
"the homepage has no siblings",
);

break :sibl try std.fs.path.join(gpa, &.{
break :sibl try join(gpa, &.{
ps_base,
p.ref,
});
Expand Down
3 changes: 2 additions & 1 deletion src/exes/markdown-renderer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const scripty = @import("scripty");
const ziggy = @import("ziggy");
const zine = @import("zine");
const supermd = @import("supermd");
const join = @import("../root.zig").join;
const context = zine.context;
const hl = zine.highlight;
const highlightCode = hl.highlightCode;
Expand Down Expand Up @@ -89,7 +90,7 @@ pub fn render(
.url => {},
.page => |link| {
const asset_path =
try std.fs.path.join(arena, &.{
try join(arena, &.{
md_asset_dir_path,
link,
});
Expand Down

0 comments on commit b058d86

Please sign in to comment.