From 602e5dc19076aeb4453fe9dbe631d54c346ca8d7 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Wed, 16 Apr 2025 18:28:07 +0200 Subject: [PATCH] Use the /releases/latest redirect of the blog --- src/main.rs | 31 +++++-------------------------- src/rust_version.rs | 31 ------------------------------- templates/index.html.hbs | 2 +- 3 files changed, 6 insertions(+), 58 deletions(-) diff --git a/src/main.rs b/src/main.rs index b087a03d1..eaa8285ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -156,20 +155,13 @@ fn robots_txt() -> Option> { } #[get("/")] -async fn index( - version_cache: &Cache, - release_post_cache: &Cache, -) -> Template { - render_index(ENGLISH.into(), version_cache, release_post_cache).await +async fn index(version_cache: &Cache) -> Template { + render_index(ENGLISH.into(), version_cache).await } #[get("/", rank = 3)] -async fn index_locale( - locale: SupportedLocale, - version_cache: &Cache, - release_post_cache: &Cache, -) -> Template { - render_index(locale.0, version_cache, release_post_cache).await +async fn index_locale(locale: SupportedLocale, version_cache: &Cache) -> Template { + render_index(locale.0, version_cache).await } #[get("/")] @@ -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, - release_post_cache: &Cache, -) -> Template { +async fn render_index(lang: String, version_cache: &Cache) -> 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) @@ -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( "/", diff --git a/src/rust_version.rs b/src/rust_version.rs index b84f64686..e1ce547cf 100644 --- a/src/rust_version.rs +++ b/src/rust_version.rs @@ -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> { @@ -27,7 +25,6 @@ async fn fetch(target: FetchTarget) -> Result MANIFEST_URL, - FetchTarget::ReleasesFeed => RELEASES_FEED_URL, }; Ok(client.get(url).send().await?) @@ -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> { - let releases = fetch(FetchTarget::ReleasesFeed) - .await? - .text() - .await? - .parse::()?; - let url = releases["releases"][0]["url"].as_str().unwrap().to_string(); - Ok(RustReleasePost(url, Instant::now())) - } -} - pub async fn rust_version(version_cache: &Cache) -> String { RustVersion::get(version_cache).await.0 } - -pub async fn rust_release_post(release_post_cache: &Cache) -> String { - RustReleasePost::get(release_post_cache).await.0 -} diff --git a/templates/index.html.hbs b/templates/index.html.hbs index b47f4efa7..d2978d238 100644 --- a/templates/index.html.hbs +++ b/templates/index.html.hbs @@ -12,7 +12,7 @@ {{fluent "get-started"}}

- {{#fluent "homepage-version"}}{{#fluentparam "number"}}{{data.rust_version}}{{/fluentparam}}{{/fluent}} + {{#fluent "homepage-version"}}{{#fluentparam "number"}}{{data.rust_version}}{{/fluentparam}}{{/fluent}}