@@ -37,7 +37,6 @@ impl Preprocessor for GoalPreprocessor {
37
37
38
38
pub struct GoalPreprocessorWithContext < ' c > {
39
39
team_asks : & ' static Regex ,
40
- goal_list : & ' static Regex ,
41
40
goal_count : & ' static Regex ,
42
41
username : & ' static Regex ,
43
42
ctx : & ' c PreprocessorContext ,
@@ -116,7 +115,6 @@ impl<'c> GoalPreprocessorWithContext<'c> {
116
115
Ok ( GoalPreprocessorWithContext {
117
116
ctx,
118
117
team_asks : & re:: TEAM_ASKS ,
119
- goal_list : & re:: GOAL_LIST ,
120
118
goal_count : & re:: GOAL_COUNT ,
121
119
username : & re:: USERNAME ,
122
120
links,
@@ -163,7 +161,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
163
161
164
162
let count = goals
165
163
. iter ( )
166
- . filter ( |g| g. metadata . status != Status :: NotAccepted )
164
+ . filter ( |g| g. metadata . status . is_not_not_accepted ( ) )
167
165
. count ( ) ;
168
166
169
167
chapter. content = self
@@ -175,54 +173,54 @@ impl<'c> GoalPreprocessorWithContext<'c> {
175
173
}
176
174
177
175
fn replace_goal_lists ( & mut self , chapter : & mut Chapter ) -> anyhow:: Result < ( ) > {
178
- let Some ( m) = self . goal_list . captures ( & chapter. content ) else {
179
- return Ok ( ( ) ) ;
180
- } ;
181
- let range = m. get ( 0 ) . unwrap ( ) . range ( ) ;
182
- let statuses = m[ 1 ]
183
- . split ( ',' )
184
- . map ( |s| s. trim ( ) )
185
- . map ( Status :: try_from)
186
- . collect :: < anyhow:: Result < Vec < Status > > > ( ) ?;
187
-
188
- let Some ( chapter_path) = & chapter. path else {
189
- anyhow:: bail!( "found `<!-- GOALS -->` but chapter has no path" )
190
- } ;
191
-
192
- // Extract out the list of goals with the given status.
193
- let goals = self . goal_documents ( chapter_path) ?;
194
- let mut goals_with_status: Vec < & GoalDocument > = statuses
195
- . iter ( )
196
- . flat_map ( |& status| goals. iter ( ) . filter ( move |g| g. metadata . status == status) )
197
- . collect ( ) ;
198
-
199
- goals_with_status. sort_by_key ( |g| & g. metadata . title ) ;
200
-
201
- // Format the list of goals and replace the `<!-- -->` comment with that.
202
- let output = goal:: format_goal_table ( & goals_with_status) ?;
203
- chapter. content . replace_range ( range, & output) ;
204
-
205
- // Populate with children if this is not README
206
- if chapter_path. file_stem ( ) != Some ( "README" . as_ref ( ) ) {
207
- let mut parent_names = chapter. parent_names . clone ( ) ;
208
- parent_names. push ( chapter. name . clone ( ) ) ;
209
- for ( goal, index) in goals_with_status. iter ( ) . zip ( 0 ..) {
210
- let content = std:: fs:: read_to_string ( & goal. path )
211
- . with_context ( || format ! ( "reading `{}`" , goal. path. display( ) ) ) ?;
212
- let path = goal. path . strip_prefix ( & self . ctx . config . book . src ) . unwrap ( ) ;
213
- let mut new_chapter =
214
- Chapter :: new ( & goal. metadata . title , content, path, parent_names. clone ( ) ) ;
215
-
216
- if let Some ( mut number) = chapter. number . clone ( ) {
217
- number. 0 . push ( index + 1 ) ;
218
- new_chapter. number = Some ( number) ;
176
+ self . replace_goal_lists_helper ( chapter, & re:: FLAGSHIP_GOAL_LIST , |status| status. is_flagship && status. is_not_not_accepted ( ) ) ?;
177
+ self . replace_goal_lists_helper ( chapter, & re:: OTHER_GOAL_LIST , |status| !status. is_flagship && status. is_not_not_accepted ( ) ) ?;
178
+ self . replace_goal_lists_helper ( chapter, & re:: GOAL_LIST , |status| status. is_not_not_accepted ( ) ) ?;
179
+ self . replace_goal_lists_helper ( chapter, & re:: GOAL_NOT_ACCEPTED_LIST , |status| !status. is_not_not_accepted ( ) ) ?;
180
+ Ok ( ( ) )
181
+ }
182
+
183
+ fn replace_goal_lists_helper ( & mut self , chapter : & mut Chapter , regex : & Regex , filter : impl Fn ( Status ) -> bool ) -> anyhow:: Result < ( ) > {
184
+ loop {
185
+ let Some ( m) = regex. find ( & chapter. content ) else {
186
+ return Ok ( ( ) ) ;
187
+ } ;
188
+ let range = m. range ( ) ;
189
+
190
+ let Some ( chapter_path) = & chapter. path else {
191
+ anyhow:: bail!( "found `{regex}` but chapter has no path" )
192
+ } ;
193
+
194
+ // Extract out the list of goals with the given status.
195
+ let goals = self . goal_documents ( chapter_path) ?;
196
+ let mut goals_with_status: Vec < & GoalDocument > = goals. iter ( ) . filter ( |g| filter ( g. metadata . status ) ) . collect ( ) ;
197
+
198
+ goals_with_status. sort_by_key ( |g| & g. metadata . title ) ;
199
+
200
+ // Format the list of goals and replace the `<!-- -->` comment with that.
201
+ let output = goal:: format_goal_table ( & goals_with_status) ?;
202
+ chapter. content . replace_range ( range, & output) ;
203
+
204
+ // Populate with children if this is not README
205
+ if chapter_path. file_stem ( ) != Some ( "README" . as_ref ( ) ) {
206
+ let mut parent_names = chapter. parent_names . clone ( ) ;
207
+ parent_names. push ( chapter. name . clone ( ) ) ;
208
+ for ( goal, index) in goals_with_status. iter ( ) . zip ( 0 ..) {
209
+ let content = std:: fs:: read_to_string ( & goal. path )
210
+ . with_context ( || format ! ( "reading `{}`" , goal. path. display( ) ) ) ?;
211
+ let path = goal. path . strip_prefix ( & self . ctx . config . book . src ) . unwrap ( ) ;
212
+ let mut new_chapter =
213
+ Chapter :: new ( & goal. metadata . title , content, path, parent_names. clone ( ) ) ;
214
+
215
+ if let Some ( mut number) = chapter. number . clone ( ) {
216
+ number. 0 . push ( index + 1 ) ;
217
+ new_chapter. number = Some ( number) ;
218
+ }
219
+
220
+ chapter. sub_items . push ( BookItem :: Chapter ( new_chapter) ) ;
219
221
}
220
-
221
- chapter. sub_items . push ( BookItem :: Chapter ( new_chapter) ) ;
222
222
}
223
223
}
224
-
225
- self . replace_goal_lists ( chapter)
226
224
}
227
225
228
226
/// Look for `<!-- TEAM ASKS -->` in the chapter content and replace it with the team asks.
@@ -239,7 +237,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
239
237
let goals = self . goal_documents ( path) ?;
240
238
let asks_of_any_team: Vec < & TeamAsk > = goals
241
239
. iter ( )
242
- . filter ( |g| g. metadata . status != Status :: NotAccepted )
240
+ . filter ( |g| g. metadata . status . is_not_not_accepted ( ) )
243
241
. flat_map ( |g| & g. team_asks )
244
242
. collect ( ) ;
245
243
let format_team_asks = format_team_asks ( & asks_of_any_team) ?;
0 commit comments