Skip to content

Commit 44e361e

Browse files
authored
Merge pull request #962 from pietroalbini/more-sponsors
Improve the Sponsors page and add 1Password to it
2 parents 03c6daa + 3526236 commit 44e361e

File tree

14 files changed

+130
-36
lines changed

14 files changed

+130
-36
lines changed

locales/en-US/sponsors.ftl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ sponsors-description = The Rust project receives support through the donation of
66
77
sponsors-caveat = Many companies and individuals make significant contributions of time and human resources; we intend to find a way to publicly acknowledge that in the near future.
88
9+
sponsors-1password-alt = 1Password
10+
sponsors-1password = 1Password is providing a free 1Password Teams subscription to the Rust Team, used to store and share secrets between team members.
11+
912
sponsors-microsoft-alt = Microsoft Azure
1013
sponsors-microsoft = Microsoft Azure is sponsoring builders for Rust’s CI infrastructure, notably the extremely resource intensive rust-lang/rust repository.
1114
1215
sponsors-aws-alt = Amazon Web Services
1316
sponsors-aws = Amazon Web Services (AWS) is providing hosting for release artifacts (compilers, libraries, tools, and source code), serving those artifacts to users through CloudFront, preventing regressions with Crater on EC2, and managing other Rust-related infrastructure hosted on AWS.
1417
1518
sponsors-mozilla-alt = Mozilla
16-
sponsors-mozilla = Mozilla is providing the Rust project with Heroku services for crates.io, Zoom.us services for team video calls, Mailgun services for emails, 1password for secret sharing, and Discourse for the Users and Internals forums.
19+
sponsors-mozilla = Mozilla is providing the Rust project with Heroku services for crates.io, Zoom.us services for team video calls, Mailgun services for emails, and Discourse for the Users and Internals forums.
1720
1821
sponsors-support = Supporting Rust
1922
sponsors-sponsor = Interested in sponsoring work on Rust? A Rust conference? We’d love to hear from you.

src/data/sponsors.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
3+
# Content of the /sponsors page.
4+
#
5+
# The name of the sponsor is defined here and left untranslated in the page.
6+
# The other parts of the page are derived from the sponsor's ID:
7+
# - The logo is located in static/images/sponsor-logos/<id>.svg
8+
# - The alt of the image is the Fluent translation "sponsors-<id>-alt"
9+
# - The description paragraph is the Fluent translation "sponsors-<id>"
10+
11+
- id: 1password
12+
name: 1Password
13+
14+
- id: aws
15+
name: AWS
16+
17+
- id: microsoft
18+
name: Microsoft Azure
19+
20+
- id: mozilla
21+
name: Mozilla

src/headers.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rocket::fairing::{Fairing, Info, Kind};
2-
use rocket::http::Header;
2+
use rocket::http::{ContentType, Header};
33
use rocket::{Request, Response};
44

55
static HEADERS: &[(&str, &str)] = &[
@@ -13,6 +13,8 @@ static HEADERS: &[(&str, &str)] = &[
1313
];
1414

1515
static HEADER_CSP_NORMAL: &str = "default-src 'self'; frame-ancestors 'self'; img-src 'self' avatars.githubusercontent.com; frame-src 'self' player.vimeo.com";
16+
static HEADER_CSP_SVG: &str =
17+
"default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'none'";
1618
static HEADER_CSP_PONTOON: &str = "default-src 'self' pontoon.rust-lang.org pontoon.mozilla.org; frame-ancestors 'self' pontoon.rust-lang.org; img-src 'self' avatars.githubusercontent.com pontoon.rust-lang.org pontoon.mozilla.org; frame-src 'self' pontoon.rust-lang.org player.vimeo.com";
1719

1820
pub(crate) struct InjectHeaders;
@@ -29,7 +31,11 @@ impl Fairing for InjectHeaders {
2931
for (key, value) in HEADERS {
3032
response.set_header(Header::new(*key, *value));
3133
}
32-
let csp = if *super::PONTOON_ENABLED {
34+
let csp = if response.content_type() == Some(ContentType::SVG) {
35+
// SVGs adhere to Content Security Policy, and they often include inline styles.
36+
// This uses a custom CSP when the Content-Type is SVG.
37+
HEADER_CSP_SVG
38+
} else if *super::PONTOON_ENABLED {
3339
HEADER_CSP_PONTOON
3440
} else {
3541
HEADER_CSP_NORMAL

src/main.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ mod i18n;
3030
mod production;
3131
mod redirect;
3232
mod rust_version;
33+
mod sponsors;
3334
mod teams;
3435

3536
use production::User;
@@ -228,6 +229,16 @@ fn production_locale(locale: SupportedLocale) -> Template {
228229
render_production(locale.0)
229230
}
230231

232+
#[get("/sponsors")]
233+
fn sponsors() -> Template {
234+
render_sponsors(ENGLISH.into())
235+
}
236+
237+
#[get("/<locale>/sponsors", rank = 10)]
238+
fn sponsors_locale(locale: SupportedLocale) -> Template {
239+
render_sponsors(locale.0)
240+
}
241+
231242
#[get("/<category>/<subject>", rank = 4)]
232243
fn subject(category: Category, subject: String) -> Template {
233244
render_subject(category, subject, ENGLISH.into())
@@ -395,6 +406,20 @@ fn render_production(lang: String) -> Template {
395406
Template::render(page, &context)
396407
}
397408

409+
fn render_sponsors(lang: String) -> Template {
410+
println!("foo");
411+
let page = "sponsors/index".to_string();
412+
let context = Context::new(
413+
page.clone(),
414+
"sponsors-page-title",
415+
false,
416+
sponsors::render_data(&lang),
417+
lang,
418+
);
419+
420+
Template::render(page, &context)
421+
}
422+
398423
fn render_governance(lang: String) -> Result<Template, Status> {
399424
match teams::index_data() {
400425
Ok(data) => {
@@ -468,6 +493,7 @@ fn main() {
468493
governance,
469494
team,
470495
production,
496+
sponsors,
471497
subject,
472498
files,
473499
favicon,
@@ -478,6 +504,7 @@ fn main() {
478504
governance_locale,
479505
team_locale,
480506
production_locale,
507+
sponsors_locale,
481508
subject_locale,
482509
components_locale,
483510
redirect,

src/sponsors.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use crate::i18n::I18NHelper;
2+
use rand::seq::SliceRandom;
3+
use std::error::Error;
4+
5+
static SPONSORS_YML_PATH: &str = "src/data/sponsors.yml";
6+
7+
lazy_static! {
8+
static ref SPONSORS: Vec<Sponsor> = load_sponsors(SPONSORS_YML_PATH).unwrap();
9+
}
10+
11+
#[derive(Deserialize)]
12+
struct Sponsor {
13+
id: String,
14+
name: String,
15+
}
16+
17+
fn load_sponsors(path: &str) -> Result<Vec<Sponsor>, Box<dyn Error>> {
18+
Ok(serde_yaml::from_str(&std::fs::read_to_string(path)?)?)
19+
}
20+
21+
#[derive(Serialize)]
22+
pub(crate) struct RenderSponsor {
23+
name: &'static str,
24+
is_not_first: bool,
25+
logo_path: String,
26+
logo_alt_i18n: String,
27+
description_i18n: String,
28+
}
29+
30+
pub(crate) fn render_data(lang: &str) -> Vec<RenderSponsor> {
31+
let i18n = I18NHelper::new();
32+
33+
let mut sponsors = SPONSORS
34+
.iter()
35+
.map(|s| RenderSponsor {
36+
name: &s.name,
37+
is_not_first: true, // Will be changed later
38+
logo_path: format!("/static/images/sponsor-logos/{}.svg", s.id),
39+
logo_alt_i18n: i18n.lookup(lang, &format!("sponsors-{}-alt", s.id), None),
40+
description_i18n: i18n.lookup(lang, &format!("sponsors-{}", s.id), None),
41+
})
42+
.collect::<Vec<_>>();
43+
44+
sponsors.shuffle(&mut rand::thread_rng());
45+
46+
sponsors
47+
.iter_mut()
48+
.enumerate()
49+
.for_each(|(i, s)| s.is_not_first = i != 0);
50+
51+
sponsors
52+
}

src/styles/app.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,8 @@ blockquote::before {
746746
#pb4 {
747747
padding-bottom: 3.8em;
748748
}
749+
750+
.max-height-5rem {
751+
/* Tachyons is missing this class */
752+
max-height: 5rem;
753+
}

static/images/sponsor-logos/1password.svg

Lines changed: 1 addition & 0 deletions
Loading

static/images/sponsor-logos/aws.png

-38.6 KB
Binary file not shown.

static/images/sponsor-logos/aws.svg

Lines changed: 1 addition & 0 deletions
Loading
-26.6 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Loading
-14.4 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Loading

templates/sponsors/index.hbs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,22 @@
1717
{{fluent "sponsors-caveat"}}
1818
</p>
1919

20+
{{#each data as |sponsor|}}
21+
{{#if sponsor.is_not_first}}
22+
<hr size="1" noshade class="mv4">
23+
{{/if}}
2024
<div class="flex-none flex-l mt5-l">
21-
<div class="w-100 w-30-l tc">
22-
<img alt="{{fluent "sponsors-microsoft-alt"}}" src="/static/images/sponsor-logos/microsoft.png" />
25+
<div class="mv3 mv0-ns w-100 w-30-l tc flex items-center justify-center">
26+
<img class="ph5 max-height-5rem" alt="{{sponsor.logo_alt_i18n}}" src="{{sponsor.logo_path}}" />
2327
</div>
2428
<div class="w-100 w-70-l">
25-
<h3>Microsoft Azure</h3>
29+
<h3>{{sponsor.name}}</h3>
2630
<p>
27-
{{fluent "sponsors-microsoft"}}
31+
{{sponsor.description_i18n}}
2832
</p>
2933
</div>
3034
</div>
31-
32-
<hr noshade size="1"/>
33-
34-
<div class="flex-none flex-l mt5-l">
35-
<div class="w-100 w-30-l tc">
36-
<img alt="{{fluent "sponsors-aws-alt"}}" src="/static/images/sponsor-logos/aws.png" />
37-
</div>
38-
<div class="w-100 w-70-l">
39-
<h3>AWS</h3>
40-
<p>
41-
{{fluent "sponsors-aws"}}
42-
</p>
43-
</div>
44-
</div>
45-
46-
<hr noshade size="1"/>
47-
48-
<div class="flex-none flex-l mt5-l">
49-
<div class="w-100 w-30-l tc">
50-
<img alt="{{fluent "sponsors-mozilla-alt"}}" src="/static/images/sponsor-logos/mozilla.png" />
51-
</div>
52-
<div class="w-100 w-70-l">
53-
<h3>Mozilla</h3>
54-
<p>
55-
{{fluent "sponsors-mozilla"}}
56-
</p>
57-
</div>
58-
</div>
59-
35+
{{/each}}
6036
</div>
6137
</section>
6238

0 commit comments

Comments
 (0)