diff --git a/build.zig.zon b/build.zig.zon index 0108d53..e1f2842 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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", diff --git a/src/context/Page.zig b/src/context/Page.zig index 208a1ad..ec51ba8 100644 --- a/src/context/Page.zig +++ b/src/context/Page.zig @@ -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 =