Skip to content

Deploy #2153

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 14 commits into from
May 17, 2025
Merged

Deploy #2153

Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ jobs:
- name: Test
run: |
set -euo pipefail
IFS=$'\n\t'
# Check if the code is good
cargo build --all --locked
cargo clippy -- --deny warnings
cargo test --all --locked

- name: Build the Docker image
run: docker build -t website .
21 changes: 14 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 0 additions & 56 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE-APACHE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2018 The Rust Programming Language Team
Copyright (c) The Rust Project Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 2 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Copyright (c) The Rust Project Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Expand Down
31 changes: 5 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use cache::Cached;
use rocket::catch;
use rocket::get;
use rocket::tokio::sync::RwLock;
use rust_version::RustReleasePost;
use rust_version::RustVersion;
use serde::Serialize;
use teams::RustTeams;
Expand Down Expand Up @@ -156,20 +155,13 @@ fn robots_txt() -> Option<content::RawText<&'static str>> {
}

#[get("/")]
async fn index(
version_cache: &Cache<RustVersion>,
release_post_cache: &Cache<RustReleasePost>,
) -> Template {
render_index(ENGLISH.into(), version_cache, release_post_cache).await
async fn index(version_cache: &Cache<RustVersion>) -> Template {
render_index(ENGLISH.into(), version_cache).await
}

#[get("/<locale>", rank = 3)]
async fn index_locale(
locale: SupportedLocale,
version_cache: &Cache<RustVersion>,
release_post_cache: &Cache<RustReleasePost>,
) -> Template {
render_index(locale.0, version_cache, release_post_cache).await
async fn index_locale(locale: SupportedLocale, version_cache: &Cache<RustVersion>) -> Template {
render_index(locale.0, version_cache).await
}

#[get("/<category>")]
Expand Down Expand Up @@ -328,26 +320,15 @@ fn concat_app_js(files: Vec<&str>) -> String {
String::from(&js_path[1..])
}

async fn render_index(
lang: String,
version_cache: &Cache<RustVersion>,
release_post_cache: &Cache<RustReleasePost>,
) -> Template {
async fn render_index(lang: String, version_cache: &Cache<RustVersion>) -> Template {
#[derive(Serialize)]
struct IndexData {
rust_version: String,
rust_release_post: String,
}

let page = "index";
let release_post = rust_version::rust_release_post(release_post_cache).await;
let data = IndexData {
rust_version: rust_version::rust_version(version_cache).await,
rust_release_post: if !release_post.is_empty() {
format!("https://blog.rust-lang.org/{}", release_post)
} else {
String::new()
},
};
let context = Context::new(page, "", true, data, lang);
Template::render(page, context)
Expand Down Expand Up @@ -438,14 +419,12 @@ async fn rocket() -> _ {
});

let rust_version = RustVersion::fetch().await.unwrap_or_default();
let rust_release_post = RustReleasePost::fetch().await.unwrap_or_default();
let teams = RustTeams::fetch().await.unwrap_or_default();

rocket::build()
.attach(templating)
.attach(headers::InjectHeaders)
.manage(Arc::new(RwLock::new(rust_version)))
.manage(Arc::new(RwLock::new(rust_release_post)))
.manage(Arc::new(RwLock::new(teams)))
.mount(
"/",
Expand Down
31 changes: 0 additions & 31 deletions src/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use std::time::Instant;
use crate::cache::{Cache, Cached};

static MANIFEST_URL: &str = "https://static.rust-lang.org/dist/channel-rust-stable.toml";
static RELEASES_FEED_URL: &str = "https://blog.rust-lang.org/releases.json";

enum FetchTarget {
Manifest,
ReleasesFeed,
}

async fn fetch(target: FetchTarget) -> Result<reqwest::Response, Box<dyn Error + Send + Sync>> {
Expand All @@ -27,7 +25,6 @@ async fn fetch(target: FetchTarget) -> Result<reqwest::Response, Box<dyn Error +

let url = match target {
FetchTarget::Manifest => MANIFEST_URL,
FetchTarget::ReleasesFeed => RELEASES_FEED_URL,
};

Ok(client.get(url).send().await?)
Expand Down Expand Up @@ -58,34 +55,6 @@ impl Cached for RustVersion {
}
}

#[derive(Debug, Clone)]
pub struct RustReleasePost(pub String, pub Instant);

impl Default for RustReleasePost {
fn default() -> Self {
Self(Default::default(), Instant::now())
}
}

impl Cached for RustReleasePost {
fn get_timestamp(&self) -> Instant {
self.1
}
async fn fetch() -> Result<Self, Box<dyn Error + Send + Sync>> {
let releases = fetch(FetchTarget::ReleasesFeed)
.await?
.text()
.await?
.parse::<serde_json::Value>()?;
let url = releases["releases"][0]["url"].as_str().unwrap().to_string();
Ok(RustReleasePost(url, Instant::now()))
}
}

pub async fn rust_version(version_cache: &Cache<RustVersion>) -> String {
RustVersion::get(version_cache).await.0
}

pub async fn rust_release_post(release_post_cache: &Cache<RustReleasePost>) -> String {
RustReleasePost::get(release_post_cache).await.0
}
7 changes: 6 additions & 1 deletion src/teams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub struct PageData {
subteams: Vec<Team>,
wgs: Vec<Team>,
project_groups: Vec<Team>,
// Marker teams and other kinds of groups that have a website entry
other_teams: Vec<Team>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -112,6 +114,7 @@ impl Data {
let mut raw_subteams = Vec::new();
let mut wgs = Vec::new();
let mut project_groups = Vec::new();
let mut other_teams = Vec::new();

let superteams: HashMap<_, _> = self
.teams
Expand Down Expand Up @@ -142,12 +145,13 @@ impl Data {
TeamKind::Team => raw_subteams.push(team),
TeamKind::WorkingGroup => wgs.push(team),
TeamKind::ProjectGroup => project_groups.push(team),
_ => {}
TeamKind::MarkerTeam | TeamKind::Unknown => other_teams.push(team),
});

raw_subteams.sort_by_key(|team| Reverse(team.website_data.as_ref().unwrap().weight));
wgs.sort_by_key(|team| Reverse(team.website_data.as_ref().unwrap().weight));
project_groups.sort_by_key(|team| Reverse(team.website_data.as_ref().unwrap().weight));
other_teams.sort_by_key(|team| Reverse(team.website_data.as_ref().unwrap().weight));

// Lay out subteams according to their hierarchy.
// Superteams come first and subteams come after, recursively.
Expand Down Expand Up @@ -181,6 +185,7 @@ impl Data {
subteams,
wgs,
project_groups,
other_teams,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/components/footer.html.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<footer>
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
<div class="flex flex-column flex-row-ns pv0-l">
<div class="flex flex-column flex-row-l pv0-l">
<div class="flex flex-column mw8 w-100 measure-wide-l pv2 pv5-m pv2-ns ph4-m ph4-l" id="get-help">
<h4>{{fluent "footer-get-help"}}</h4>
<ul>
Expand Down
7 changes: 7 additions & 0 deletions templates/governance/group.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
{{/each}}
</section>
{{/if}}
{{#if data.other_teams}}
<section class="green">
{{#each data.other_teams as |team|}}
{{> governance/group-team}}
{{/each}}
</section>
{{/if}}

{{/inline}}
{{~> (lookup this "parent")~}}
2 changes: 1 addition & 1 deletion templates/index.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{fluent "get-started"}}
</a>
<p class="tc f3 f2-l mt3">
<a href="{{data.rust_release_post}}" class="download-link">{{#fluent "homepage-version"}}{{#fluentparam "number"}}{{data.rust_version}}{{/fluentparam}}{{/fluent}}</a>
<a href="https://blog.rust-lang.org/releases/latest" class="download-link">{{#fluent "homepage-version"}}{{#fluentparam "number"}}{{data.rust_version}}{{/fluentparam}}{{/fluent}}</a>
</p>
</div>
</div>
Expand Down