@@ -92,12 +92,23 @@ fn main() -> Result<(), Box<dyn Error>> {
92
92
team_prompt = team_prompt. with_autocomplete ( TeamNames :: from_teams ( teams) ) ;
93
93
}
94
94
95
- let team = team_prompt. prompt ( ) ?;
95
+ let mut team = team_prompt. prompt ( ) ?;
96
96
97
97
let url = if let Some ( url) = team_data
98
98
. as_ref ( )
99
99
. and_then ( |teams| find_team_url ( teams, & team) )
100
100
{
101
+ // At this point, a canonical team has been selected, and we have a URL for it.
102
+ // This should be the common "happy path".
103
+ // However, displaying the canonical team name in the blog heading is not ideal, usually
104
+ // users will want to modify it slightly, so give them the option.
105
+ let normalized = normalize_team_name ( team) ;
106
+ let team_label = format ! ( "the {normalized} team" ) ;
107
+ let team_label = Text :: new ( "What text should be used after 'on behalf of'?" )
108
+ . with_initial_value ( & team_label)
109
+ . prompt ( ) ?;
110
+ team = team_label;
111
+
101
112
url
102
113
} else {
103
114
Text :: new ( "At what URL can people find the team?" )
@@ -179,6 +190,22 @@ being published - CI checks against the placeholder.
179
190
Ok ( ( ) )
180
191
}
181
192
193
+ /// Normalizes team name to be human readable, e.g. `leadership-council` => `Leadership Council`.
194
+ fn normalize_team_name ( name : String ) -> String {
195
+ name. split ( "-" )
196
+ . map ( |part| {
197
+ // Capitalize the string
198
+ part. chars ( )
199
+ . next ( )
200
+ . into_iter ( )
201
+ . flat_map ( |c| c. to_uppercase ( ) )
202
+ . chain ( part. chars ( ) . skip ( 1 ) )
203
+ . collect :: < String > ( )
204
+ } )
205
+ . collect :: < Vec < _ > > ( )
206
+ . join ( " " )
207
+ }
208
+
182
209
fn load_teams ( ) -> Result < Teams , String > {
183
210
let url = format ! ( "{}/teams.json" , rust_team_data:: v1:: BASE_URL ) ;
184
211
let response = ureq:: get ( url) . call ( ) . map_err ( |e| e. to_string ( ) ) ?;
0 commit comments