File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ pub struct PageFrontMatter {
39
39
pub datetime_tuple : Option < ( i32 , u8 , u8 ) > ,
40
40
/// Whether this page is a draft
41
41
pub draft : bool ,
42
+ /// Whether this page is hidden
43
+ pub hidden : Option < bool > ,
42
44
/// Prevent generation of a folder for current page
43
45
/// Defaults to `true`
44
46
#[ serde( skip_serializing) ]
@@ -155,6 +157,7 @@ impl Default for PageFrontMatter {
155
157
datetime : None ,
156
158
datetime_tuple : None ,
157
159
draft : false ,
160
+ hidden : None ,
158
161
render : true ,
159
162
slug : None ,
160
163
path : None ,
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ pub struct SectionFrontMatter {
47
47
/// to be used directly, like a posts section in a personal site
48
48
#[ serde( skip_serializing) ]
49
49
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 > ,
50
52
/// Whether to redirect when landing on that section. Defaults to `None`.
51
53
/// Useful for the same reason as `render` but when you don't want a 404 when
52
54
/// landing on the root section page
@@ -107,6 +109,7 @@ impl Default for SectionFrontMatter {
107
109
paginate_reversed : false ,
108
110
paginate_path : DEFAULT_PAGINATE_PATH . to_string ( ) ,
109
111
render : true ,
112
+ hidden : None ,
110
113
redirect_to : None ,
111
114
insert_anchor_links : None ,
112
115
in_search_index : true ,
Original file line number Diff line number Diff line change @@ -130,9 +130,41 @@ impl<'a> Paginator<'a> {
130
130
131
131
for p in & * self . all_pages {
132
132
let page = & library. pages [ p] ;
133
+
133
134
if !page. meta . render {
134
135
continue ;
135
136
}
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
+
136
168
current_page. push ( SerializingPage :: new ( page, Some ( library) , false ) ) ;
137
169
138
170
if current_page. len ( ) == self . paginate_by {
You can’t perform that action at this time.
0 commit comments