Skip to content

Commit 4e175f6

Browse files
committed
Add missing redirects and remove obsolete code for legacy redirects
1 parent cc87dd1 commit 4e175f6

File tree

2 files changed

+8
-66
lines changed

2 files changed

+8
-66
lines changed

src/redirect.rs

Lines changed: 7 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::i18n::SUPPORTED_LOCALES;
2-
use crate::render::RenderCtx;
1+
use crate::render::{RenderCtx, render_redirect};
32

43
pub static PAGE_REDIRECTS: &[(&str, &str)] = &[
54
// Pre-2018 website pages
@@ -74,13 +73,6 @@ static EXTERNAL_REDIRECTS: &[(&str, &str)] = &[
7473
("sponsors", "https://foundation.rust-lang.org/members/"),
7574
];
7675

77-
// Translations present on www.rust-lang.org before the 2018 redesign. If an equivalent translation
78-
// is present in the current codebase it will be migrated automatically.
79-
static PRE_2018_LOCALES: &[&str] = &[
80-
"de-DE", "en-US", "es-ES", "fr-FR", "id-ID", "it-IT", "ja-JP", "ko-KR", "pl-PL", "pt-BR",
81-
"ru-RU", "sv-SE", "vi-VN",
82-
];
83-
8476
pub fn create_redirects(ctx: &RenderCtx) -> anyhow::Result<()> {
8577
// Static file redirects, no need to support languages
8678
// We cannot really make non-HTML redirects easily, so we just duplicate the file contents
@@ -89,63 +81,13 @@ pub fn create_redirects(ctx: &RenderCtx) -> anyhow::Result<()> {
8981
ctx.copy_asset_file(dst, src)?;
9082
}
9183

92-
// if let Some((_, dest)) = STATIC_FILES_REDIRECTS.iter().find(|(src, _)| src == &path) {
93-
// return Some(Redirect::permanent(*dest));
94-
// }
95-
//
96-
// let (locale, path) = if let Some((first, rest)) = path.split_once('/') {
97-
// if SUPPORTED_LOCALES.contains(&first) {
98-
// (Locale::Present(first), rest)
99-
// // After the 2018 website redesign some of the locales were removed and some were
100-
// // renamed (removing the country code). This handles both cases, either calculating the
101-
// // renamed locale or marking the locale as "specified but missing", which triggers a
102-
// // temporary redirect instead of a permanent redirect.
103-
// } else if PRE_2018_LOCALES.contains(&first) {
104-
// if let Some(locale) = convert_locale_from_pre_2018(first) {
105-
// (Locale::Present(locale), rest)
106-
// } else {
107-
// (Locale::SpecifiedButMissing, rest)
108-
// }
109-
// } else {
110-
// (Locale::NotSpecified, path.as_str())
111-
// }
112-
// } else if PRE_2018_LOCALES.contains(&path.as_str()) {
113-
// // If the whole path is a pre-2018 locale handle it as a localized index page.
114-
// if let Some(locale) = convert_locale_from_pre_2018(&path) {
115-
// (Locale::Present(locale), "")
116-
// } else {
117-
// (Locale::SpecifiedButMissing, "")
118-
// }
119-
// } else {
120-
// (Locale::NotSpecified, path.as_str())
121-
// };
122-
//
123-
// if let Some((_, dest)) = EXTERNAL_REDIRECTS.iter().find(|(src, _)| *src == path) {
124-
// Some(Redirect::permanent(*dest))
125-
// } else if let Some((_, dest)) = PAGE_REDIRECTS.iter().find(|(src, _)| *src == path) {
126-
// let dest = format!("/{dest}");
127-
// match locale {
128-
// Locale::Present("en-US") | Locale::NotSpecified => Some(Redirect::permanent(dest)),
129-
// Locale::Present(locale) => Some(Redirect::permanent(format!("/{locale}{dest}"))),
130-
// Locale::SpecifiedButMissing => Some(Redirect::temporary(dest)),
131-
// }
132-
// } else {
133-
// None
134-
// }
135-
Ok(())
136-
}
84+
for (src, dst) in EXTERNAL_REDIRECTS {
85+
render_redirect(ctx, src, dst)?;
86+
}
13787

138-
fn convert_locale_from_pre_2018(pre_2018: &str) -> Option<&str> {
139-
if let Some(language) = pre_2018.split('-').next() {
140-
if SUPPORTED_LOCALES.contains(&language) {
141-
return Some(language);
142-
}
88+
for (src, dst) in PAGE_REDIRECTS {
89+
render_redirect(ctx, src, dst)?;
14390
}
144-
None
145-
}
14691

147-
enum Locale<'a> {
148-
Present(&'a str),
149-
SpecifiedButMissing,
150-
NotSpecified,
92+
Ok(())
15193
}

src/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pub fn render_redirect(render_ctx: &RenderCtx, from: &str, to: &str) -> anyhow::
259259
}
260260

261261
let url = if !to.starts_with("http") {
262-
format!("/{to}")
262+
format!("{}/{to}", render_ctx.base_url.get())
263263
} else {
264264
to.to_string()
265265
};

0 commit comments

Comments
 (0)