Skip to content

Commit 69781ef

Browse files
authored
Merge pull request #2143 from rust-lang/senekor/pwtqlzszkquu
Use the /releases/latest redirect of the blog
2 parents 58cd17b + 602e5dc commit 69781ef

File tree

3 files changed

+6
-58
lines changed

3 files changed

+6
-58
lines changed

src/main.rs

+5-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use cache::Cached;
1212
use rocket::catch;
1313
use rocket::get;
1414
use rocket::tokio::sync::RwLock;
15-
use rust_version::RustReleasePost;
1615
use rust_version::RustVersion;
1716
use serde::Serialize;
1817
use teams::RustTeams;
@@ -156,20 +155,13 @@ fn robots_txt() -> Option<content::RawText<&'static str>> {
156155
}
157156

158157
#[get("/")]
159-
async fn index(
160-
version_cache: &Cache<RustVersion>,
161-
release_post_cache: &Cache<RustReleasePost>,
162-
) -> Template {
163-
render_index(ENGLISH.into(), version_cache, release_post_cache).await
158+
async fn index(version_cache: &Cache<RustVersion>) -> Template {
159+
render_index(ENGLISH.into(), version_cache).await
164160
}
165161

166162
#[get("/<locale>", rank = 3)]
167-
async fn index_locale(
168-
locale: SupportedLocale,
169-
version_cache: &Cache<RustVersion>,
170-
release_post_cache: &Cache<RustReleasePost>,
171-
) -> Template {
172-
render_index(locale.0, version_cache, release_post_cache).await
163+
async fn index_locale(locale: SupportedLocale, version_cache: &Cache<RustVersion>) -> Template {
164+
render_index(locale.0, version_cache).await
173165
}
174166

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

331-
async fn render_index(
332-
lang: String,
333-
version_cache: &Cache<RustVersion>,
334-
release_post_cache: &Cache<RustReleasePost>,
335-
) -> Template {
323+
async fn render_index(lang: String, version_cache: &Cache<RustVersion>) -> Template {
336324
#[derive(Serialize)]
337325
struct IndexData {
338326
rust_version: String,
339-
rust_release_post: String,
340327
}
341328

342329
let page = "index";
343-
let release_post = rust_version::rust_release_post(release_post_cache).await;
344330
let data = IndexData {
345331
rust_version: rust_version::rust_version(version_cache).await,
346-
rust_release_post: if !release_post.is_empty() {
347-
format!("https://blog.rust-lang.org/{}", release_post)
348-
} else {
349-
String::new()
350-
},
351332
};
352333
let context = Context::new(page, "", true, data, lang);
353334
Template::render(page, context)
@@ -438,14 +419,12 @@ async fn rocket() -> _ {
438419
});
439420

440421
let rust_version = RustVersion::fetch().await.unwrap_or_default();
441-
let rust_release_post = RustReleasePost::fetch().await.unwrap_or_default();
442422
let teams = RustTeams::fetch().await.unwrap_or_default();
443423

444424
rocket::build()
445425
.attach(templating)
446426
.attach(headers::InjectHeaders)
447427
.manage(Arc::new(RwLock::new(rust_version)))
448-
.manage(Arc::new(RwLock::new(rust_release_post)))
449428
.manage(Arc::new(RwLock::new(teams)))
450429
.mount(
451430
"/",

src/rust_version.rs

-31
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ use std::time::Instant;
55
use crate::cache::{Cache, Cached};
66

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

109
enum FetchTarget {
1110
Manifest,
12-
ReleasesFeed,
1311
}
1412

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

2826
let url = match target {
2927
FetchTarget::Manifest => MANIFEST_URL,
30-
FetchTarget::ReleasesFeed => RELEASES_FEED_URL,
3128
};
3229

3330
Ok(client.get(url).send().await?)
@@ -58,34 +55,6 @@ impl Cached for RustVersion {
5855
}
5956
}
6057

61-
#[derive(Debug, Clone)]
62-
pub struct RustReleasePost(pub String, pub Instant);
63-
64-
impl Default for RustReleasePost {
65-
fn default() -> Self {
66-
Self(Default::default(), Instant::now())
67-
}
68-
}
69-
70-
impl Cached for RustReleasePost {
71-
fn get_timestamp(&self) -> Instant {
72-
self.1
73-
}
74-
async fn fetch() -> Result<Self, Box<dyn Error + Send + Sync>> {
75-
let releases = fetch(FetchTarget::ReleasesFeed)
76-
.await?
77-
.text()
78-
.await?
79-
.parse::<serde_json::Value>()?;
80-
let url = releases["releases"][0]["url"].as_str().unwrap().to_string();
81-
Ok(RustReleasePost(url, Instant::now()))
82-
}
83-
}
84-
8558
pub async fn rust_version(version_cache: &Cache<RustVersion>) -> String {
8659
RustVersion::get(version_cache).await.0
8760
}
88-
89-
pub async fn rust_release_post(release_post_cache: &Cache<RustReleasePost>) -> String {
90-
RustReleasePost::get(release_post_cache).await.0
91-
}

templates/index.html.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{fluent "get-started"}}
1313
</a>
1414
<p class="tc f3 f2-l mt3">
15-
<a href="{{data.rust_release_post}}" class="download-link">{{#fluent "homepage-version"}}{{#fluentparam "number"}}{{data.rust_version}}{{/fluentparam}}{{/fluent}}</a>
15+
<a href="https://blog.rust-lang.org/releases/latest" class="download-link">{{#fluent "homepage-version"}}{{#fluentparam "number"}}{{data.rust_version}}{{/fluentparam}}{{/fluent}}</a>
1616
</p>
1717
</div>
1818
</div>

0 commit comments

Comments
 (0)