Skip to content

Commit

Permalink
add parent section
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-it committed Sep 6, 2024
1 parent c21cbd6 commit 2d375f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
.hash = "122014e78d7c69d93595993b3231f3141368e22634b332b0b91a2fb73a8570f147a5",
},
.superhtml = .{
.url = "git+https://github.com/kristoff-it/superhtml#2f9752ab220b0cdde99994d6e20e2c5768585ca3",
.hash = "12202ea116df868225aacf87182bd9bb7ebd6815230399ffbb22afbc061c4a21ee3a",
.url = "git+https://github.com/kristoff-it/superhtml#3edb67236291d45ba97a79cdac3b91692487a352",
.hash = "1220879d0db55e043907b1af7623d93c6be80f27e3af75e35c85fa85e3823f52c922",
},
.ziggy = .{
.url = "git+https://github.com/kristoff-it/ziggy#c66f47bc632c66668d61fa06eda112b41d6e5130",
Expand Down
30 changes: 30 additions & 0 deletions src/context/Page.zig
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,36 @@ pub const Builtins = struct {
}
};

pub const parentSection = struct {
pub const signature: Signature = .{ .ret = .Page };
pub const description =
\\Returns the parent section of a page.
\\
\\It's always an error to call this function on the site's main
\\index page as it doesn't have a parent section.
;
pub const examples =
\\$page.parentSection()
;
pub fn call(
self: *const Page,
gpa: Allocator,
args: []const Value,
) !Value {
_ = gpa;
if (args.len != 0) return .{ .err = "expected 0 arguments" };
const p = self._meta.parent_section_path orelse return .{
.err = "root index page has no parent path",
};
return context.pageFind(.{
.ref = .{
.path = p,
.site = self._meta.site,
},
});
}
};

pub const isSection = struct {
pub const signature: Signature = .{ .ret = .Bool };
pub const description =
Expand Down

0 comments on commit 2d375f0

Please sign in to comment.