Skip to content

Let people choose team label in blog generation #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion crates/generate_blog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,23 @@ fn main() -> Result<(), Box<dyn Error>> {
team_prompt = team_prompt.with_autocomplete(TeamNames::from_teams(teams));
}

let team = team_prompt.prompt()?;
let mut team = team_prompt.prompt()?;

let url = if let Some(url) = team_data
.as_ref()
.and_then(|teams| find_team_url(teams, &team))
{
// At this point, a canonical team has been selected, and we have a URL for it.
// This should be the common "happy path".
// However, displaying the canonical team name in the blog heading is not ideal, usually
// users will want to modify it slightly, so give them the option.
let normalized = normalize_team_name(team);
let team_label = format!("the {normalized} team");
let team_label = Text::new("What text should be used after 'on behalf of'?")
.with_initial_value(&team_label)
.prompt()?;
team = team_label;

url
} else {
Text::new("At what URL can people find the team?")
Expand Down Expand Up @@ -179,6 +190,22 @@ being published - CI checks against the placeholder.
Ok(())
}

/// Normalizes team name to be human readable, e.g. `leadership-council` => `Leadership Council`.
fn normalize_team_name(name: String) -> String {
name.split("-")
.map(|part| {
// Capitalize the string
part.chars()
.next()
.into_iter()
.flat_map(|c| c.to_uppercase())
.chain(part.chars().skip(1))
.collect::<String>()
})
.collect::<Vec<_>>()
.join(" ")
}

fn load_teams() -> Result<Teams, String> {
let url = format!("{}/teams.json", rust_team_data::v1::BASE_URL);
let response = ureq::get(url).call().map_err(|e| e.to_string())?;
Expand Down