Skip to content

Commit 299bba0

Browse files
authored
Merge pull request #2236
Add GitHub Sponsors link to person profile page
2 parents 98a5400 + 4c869a5 commit 299bba0

File tree

4 files changed

+46
-23
lines changed

4 files changed

+46
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/render.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::assets::AssetFiles;
22
use crate::fs::{copy_dir_all, ensure_directory};
33
use crate::i18n::{EXPLICIT_LOCALE_INFO, LocaleInfo, SUPPORTED_LOCALES};
44
use crate::rust_version::RustVersion;
5-
use crate::teams::{PageData, RustTeams};
5+
use crate::teams::{PageData, RustTeamData};
66
use crate::{BaseUrl, ENGLISH, LAYOUT};
77
use anyhow::Context;
88
use handlebars::Handlebars;
@@ -84,7 +84,7 @@ pub struct RenderCtx<'a> {
8484
pub fluent_loader: SimpleLoader,
8585
pub output_dir: PathBuf,
8686
pub rust_version: RustVersion,
87-
pub teams: RustTeams,
87+
pub teams: RustTeamData,
8888
pub assets: AssetFiles,
8989
pub base_url: BaseUrl,
9090
}

src/teams.rs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use handlebars::{
33
Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderErrorReason,
44
};
55
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC, utf8_percent_encode};
6-
use rust_team_data::v1::{BASE_URL, Team, TeamKind, TeamMember, Teams};
6+
use rust_team_data::v1::{BASE_URL, People, Person, Team, TeamKind, TeamMember, Teams};
77
use serde::Serialize;
88
use std::cmp::Reverse;
99
use std::collections::HashMap;
@@ -49,17 +49,20 @@ pub fn encode_zulip_stream(
4949
}
5050

5151
#[derive(Debug, Clone)]
52-
pub struct RustTeams {
52+
pub struct RustTeamData {
5353
pub teams: Vec<Team>,
5454
pub archived_teams: Vec<Team>,
55+
// GitHub username => person data
56+
pub people: HashMap<String, Person>,
5557
}
5658

57-
impl RustTeams {
59+
impl RustTeamData {
5860
#[cfg(test)]
5961
fn dummy(teams: Vec<Team>) -> Self {
60-
RustTeams {
62+
RustTeamData {
6163
teams,
6264
archived_teams: vec![],
65+
people: HashMap::new(),
6366
}
6467
}
6568

@@ -277,16 +280,21 @@ impl RustTeams {
277280

278281
fn add_team(
279282
people: &mut HashMap<String, PersonData>,
280-
ctx: &RustTeams,
283+
ctx: &RustTeamData,
281284
member: &TeamMember,
282285
team: &Team,
283286
mode: TeamMode,
284287
) {
288+
let person_team_data = ctx
289+
.people
290+
.get(&member.github)
291+
.unwrap_or_else(|| panic!("Person {} not found in people.json", member.github));
285292
let person = people
286293
.entry(member.github.clone())
287294
.or_insert_with(move || PersonData {
288295
name: member.name.clone(),
289296
github: member.github.clone(),
297+
github_sponsors: person_team_data.github_sponsors,
290298
active_teams: vec![],
291299
alumni_teams: vec![],
292300
});
@@ -463,15 +471,16 @@ impl PersonTeam {
463471
pub struct PersonData {
464472
name: String,
465473
pub github: String,
474+
github_sponsors: bool,
466475
active_teams: Vec<PersonTeam>,
467476
alumni_teams: Vec<PersonTeam>,
468477
}
469478

470-
pub fn load_rust_teams() -> anyhow::Result<RustTeams> {
479+
pub fn load_rust_teams() -> anyhow::Result<RustTeamData> {
471480
println!("Downloading Team API data");
472481

473482
// Parallelize the download to make website build faster
474-
let (teams, archived_teams) = std::thread::scope(|scope| {
483+
let (teams, archived_teams, people) = std::thread::scope(|scope| {
475484
let teams = scope.spawn(|| -> anyhow::Result<Teams> {
476485
let response = fetch(&format!("{BASE_URL}/teams.json"))?;
477486
Ok(serde_json::from_str(&response)?)
@@ -480,13 +489,22 @@ pub fn load_rust_teams() -> anyhow::Result<RustTeams> {
480489
let response = fetch(&format!("{BASE_URL}/archived-teams.json"))?;
481490
Ok(serde_json::from_str(&response)?)
482491
});
483-
(teams.join().unwrap(), archived_teams.join().unwrap())
492+
let people = scope.spawn(|| -> anyhow::Result<People> {
493+
let response = fetch(&format!("{BASE_URL}/people.json"))?;
494+
Ok(serde_json::from_str(&response)?)
495+
});
496+
(
497+
teams.join().unwrap(),
498+
archived_teams.join().unwrap(),
499+
people.join().unwrap(),
500+
)
484501
});
485-
let (teams, archived_teams) = (teams?, archived_teams?);
502+
let (teams, archived_teams, people) = (teams?, archived_teams?, people?);
486503

487-
Ok(RustTeams {
504+
Ok(RustTeamData {
488505
teams: teams.teams.into_values().collect(),
489506
archived_teams: archived_teams.teams.into_values().collect(),
507+
people: people.people.into_iter().collect(),
490508
})
491509
}
492510

@@ -517,7 +535,7 @@ impl fmt::Display for TeamNotFound {
517535

518536
#[cfg(test)]
519537
mod tests {
520-
use super::{RustTeams, TeamNotFound};
538+
use super::{RustTeamData, TeamNotFound};
521539
use rust_team_data::v1::{Team, TeamKind, TeamMember, TeamWebsite};
522540

523541
fn dummy_team(name: &str) -> Team {
@@ -569,7 +587,7 @@ mod tests {
569587
fn test_index_data() {
570588
let mut foo = dummy_team("foo");
571589
foo.kind = TeamKind::WorkingGroup;
572-
let data = RustTeams::dummy(vec![foo, dummy_team("bar")]);
590+
let data = RustTeamData::dummy(vec![foo, dummy_team("bar")]);
573591

574592
let res = data.index_data();
575593
assert_eq!(res.teams.len(), 1);
@@ -581,7 +599,7 @@ mod tests {
581599
fn test_index_subteams_are_hidden() {
582600
let mut foo = dummy_team("foo");
583601
foo.subteam_of = Some(String::new());
584-
let data = RustTeams::dummy(vec![foo]);
602+
let data = RustTeamData::dummy(vec![foo]);
585603

586604
assert_eq!(data.index_data().teams.len(), 0);
587605
}
@@ -606,7 +624,7 @@ mod tests {
606624
other_wg.subteam_of = Some("other".into());
607625
other_wg.kind = TeamKind::WorkingGroup;
608626

609-
let data = RustTeams::dummy(vec![
627+
let data = RustTeamData::dummy(vec![
610628
main,
611629
subteam,
612630
subteam2,
@@ -635,7 +653,7 @@ mod tests {
635653
let foo = dummy_team("foo");
636654
let mut bar = dummy_team("bar");
637655
bar.kind = TeamKind::WorkingGroup;
638-
let data = RustTeams::dummy(vec![foo, bar]);
656+
let data = RustTeamData::dummy(vec![foo, bar]);
639657

640658
assert!(
641659
data.clone()
@@ -663,7 +681,7 @@ mod tests {
663681
fn test_subteams_cant_be_loaded() {
664682
let mut foo = dummy_team("foo");
665683
foo.subteam_of = Some("bar".into());
666-
let data = RustTeams::dummy(vec![foo, dummy_team("bar")]);
684+
let data = RustTeamData::dummy(vec![foo, dummy_team("bar")]);
667685

668686
assert!(
669687
data.page_data("teams", "foo")

templates/governance/person.html.hbs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
{{#*inline "page"}}
2222
<section class="green" style="padding-bottom: 10px;">
23-
<div class="w-100 mw-none mw-8-m mw9-l center f1">
23+
<div class="w-100 mw-none mw-8-m mw9-l center f1 ph3 flex flex-column flex-row-l items-end-l justify-between">
2424
<div class="w-100 w-50-l mb3 flex flex-row items-start">
25-
<a class="mr4 w5 h5 flex-shrink-0" href="https://github.com/{{data.github}}">
25+
<a class="mr4 w4 h4 w5-l h5-l flex-shrink-0" href="https://github.com/{{data.github}}">
2626
<img class="w-100 h-100 bg-white br2"
2727
src="https://avatars.githubusercontent.com/{{data.github}}"
2828
alt="{{data.name}}">
@@ -34,12 +34,17 @@
3434
</div>
3535
</div>
3636
</div>
37+
<div class="f3">
38+
{{# if data.github_sponsors }}
39+
<a href="https://github.com/sponsors/{{data.github}}" class="button button-secondary mw6">Sponsor {{ data.name }} on GitHub</a>
40+
{{/if}}
41+
</div>
3742
</div>
3843
</section>
3944

4045
{{# if data.active_teams }}
4146
<section class="purple" style="padding-bottom: 10px;">
42-
<div class="w-100 mw-none mw-8-m mw9-l center">
47+
<div class="w-100 mw-none mw-8-m mw9-l center ph3">
4348
<header>
4449
<h2>{{ fluent "governance-person-team-member" }}</h2>
4550
<div class="highlight"></div>
@@ -53,7 +58,7 @@
5358

5459
{{# if data.alumni_teams }}
5560
<section class="red" style="padding-bottom: 10px;">
56-
<div class="w-100 mw-none mw-8-m mw9-l center">
61+
<div class="w-100 mw-none mw-8-m mw9-l center ph3">
5762
<header>
5863
<h2>{{ fluent "governance-person-team-alumni" }}</h2>
5964
<div class="highlight"></div>

0 commit comments

Comments
 (0)