Skip to content

Commit ff4bfe4

Browse files
Added hidden parameter to PageFrontMatter and SectionFrontMatter and filtered them out of Paginator
1 parent c65b9db commit ff4bfe4

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Diff for: components/content/src/front_matter/page.rs

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub struct PageFrontMatter {
3939
pub datetime_tuple: Option<(i32, u8, u8)>,
4040
/// Whether this page is a draft
4141
pub draft: bool,
42+
/// Whether this page is hidden
43+
pub hidden: Option<bool>,
4244
/// Prevent generation of a folder for current page
4345
/// Defaults to `true`
4446
#[serde(skip_serializing)]
@@ -155,6 +157,7 @@ impl Default for PageFrontMatter {
155157
datetime: None,
156158
datetime_tuple: None,
157159
draft: false,
160+
hidden: None,
158161
render: true,
159162
slug: None,
160163
path: None,

Diff for: components/content/src/front_matter/section.rs

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub struct SectionFrontMatter {
4747
/// to be used directly, like a posts section in a personal site
4848
#[serde(skip_serializing)]
4949
pub render: bool,
50+
/// Whether to render all of the pages in this section, but not list them by defaulting their `hidden` to `true`
51+
pub hidden: Option<bool>,
5052
/// Whether to redirect when landing on that section. Defaults to `None`.
5153
/// Useful for the same reason as `render` but when you don't want a 404 when
5254
/// landing on the root section page
@@ -107,6 +109,7 @@ impl Default for SectionFrontMatter {
107109
paginate_reversed: false,
108110
paginate_path: DEFAULT_PAGINATE_PATH.to_string(),
109111
render: true,
112+
hidden: None,
110113
redirect_to: None,
111114
insert_anchor_links: None,
112115
in_search_index: true,

Diff for: components/content/src/pagination.rs

+32
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,41 @@ impl<'a> Paginator<'a> {
130130

131131
for p in &*self.all_pages {
132132
let page = &library.pages[p];
133+
133134
if !page.meta.render {
134135
continue;
135136
}
137+
138+
// Check if any ancestor or page is hidden and allows any
139+
// `hidden = false` to override prior explicit or
140+
// inferred `hidden = true`
141+
let is_hidden = page
142+
.ancestors
143+
.iter()
144+
.map(|ancestor| {
145+
// Go through each ancestor in the library map,
146+
// find it based on relative anchestor path
147+
// and map the hidden (Option<bool>)
148+
library
149+
.sections
150+
.values()
151+
.find(|section| &section.file.relative == ancestor)?
152+
.meta
153+
.hidden
154+
})
155+
// Add page hidden meta to the chain, to fold into final value
156+
.chain([page.meta.hidden].into_iter())
157+
// Accumulate together as `accumulator || boolean` unless value explicitely
158+
// set by a section's frontmatter as `hidden = false`
159+
.fold(false, |accumulator, boolean| match (accumulator, boolean) {
160+
(_, Some(value)) => value,
161+
(value, None) => value,
162+
});
163+
164+
if is_hidden {
165+
continue;
166+
}
167+
136168
current_page.push(SerializingPage::new(page, Some(library), false));
137169

138170
if current_page.len() == self.paginate_by {

0 commit comments

Comments
 (0)