Skip to content

Commit a919848

Browse files
authored
Change redirect implementation (#370)
1 parent 9a07a5c commit a919848

File tree

3 files changed

+28
-71
lines changed

3 files changed

+28
-71
lines changed

blacksmith/redirect.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

blacksmith/src/lib.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
collections::BTreeMap,
55
fmt::Write,
66
io::{BufRead, BufReader},
7-
path::Path,
87
time::SystemTime,
98
};
109

@@ -128,61 +127,6 @@ impl Blacksmith {
128127
Ok(blacksmith)
129128
}
130129

131-
fn generate_redirects(&self, ctx: &PreprocessorContext) {
132-
if ctx.renderer != "html" {
133-
return;
134-
}
135-
136-
let dir = ctx.config.build.build_dir.as_path();
137-
138-
/// A list of pairs of file names and where to redirect to from their
139-
/// page.
140-
#[rustfmt::skip]
141-
const REDIRECTS: &[(&str, &str)] = &[
142-
("beta-backporting.html", "/release/beta-backporting.html"),
143-
("bibliography.html", "https://rustc-dev-guide.rust-lang.org/appendix/bibliography.html"),
144-
("channel-layout.html", "/infra/channel-layout.html"),
145-
("debugging.html", "https://rustc-dev-guide.rust-lang.org/compiler-debugging.html"),
146-
("feature_guide.html", "https://rustc-dev-guide.rust-lang.org/implementing_new_features.html"),
147-
("fott.html", "/archive/fott.html"),
148-
("infrastructure.html", "/infra/service-infrastructure.html"),
149-
("other-installation-methods.html", "/infra/other-installation-methods.html"),
150-
("platform-support.html", "/release/platform-support.html"),
151-
("profile-queries.html", "/compiler/profile-queries.html"),
152-
("release-notes.html", "/release/release-notes.html"),
153-
("releases.html", "/archive/release-history.html"),
154-
("rfc-merge-procedure.html", "/lang/rfc-merge-procedure.html"),
155-
("rustc-bug-fix-procedure.html", "/compiler/bug-fix-procedure.html"),
156-
("rustc-diagnostic-code.html", "/compiler/diagnostic-codes.html"),
157-
("rustc-team-maintenance.html", "/infra/team-maintenance.html"),
158-
("stabilization-guide.html", "https://rustc-dev-guide.rust-lang.org/stabilization_guide.html"),
159-
("state-of-rust.html", "https://github.com/rust-lang/rust/projects/8"),
160-
("test-suite.html", "https://rustc-dev-guide.rust-lang.org/tests/intro.html"),
161-
("toolstate.html", "/infra/toolstate.html"),
162-
("triage-procedure.html", "/release/triage-procedure.html"),
163-
("x-py.html", "https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html"),
164-
("compiler/bug-fix-procedure.html", "https://rustc-dev-guide.rust-lang.org/bug-fix-procedure.html"),
165-
("compiler/diagnostic-codes.html", "https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-codes.html"),
166-
("compiler/profile-queries.html", "https://rustc-dev-guide.rust-lang.org/queries/profiling.html"),
167-
];
168-
169-
// Inititalise book directory if not built yet.
170-
std::fs::create_dir_all(dir).unwrap();
171-
172-
log::info!("Generating {} redirect pages.", REDIRECTS.len());
173-
for (filename, url) in REDIRECTS {
174-
let template = include_str!("../redirect.html").replace("{{url}}", url);
175-
176-
log::trace!("Redirecting {} to {}.", filename, url);
177-
178-
if let Some(parent) = Path::new(filename).parent() {
179-
std::fs::create_dir_all(dir.join(parent)).unwrap();
180-
}
181-
182-
std::fs::write(dir.join(filename), template).unwrap();
183-
}
184-
}
185-
186130
/// Creates a list of hyperlinks to `rustup-init` based on what targets
187131
/// rustup provided using the following URL schema. Where `target` is the
188132
/// platforms target tuple (`x86_64-apple-darwin`) and `suffix` is a target
@@ -328,7 +272,7 @@ impl Preprocessor for Blacksmith {
328272
"blacksmith"
329273
}
330274

331-
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
275+
fn run(&self, _: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
332276
fn recursive_replace(book_item: &mut BookItem, old: &str, new: &str) {
333277
let chapter = match book_item {
334278
BookItem::Chapter(chapter) => chapter,
@@ -357,8 +301,6 @@ impl Preprocessor for Blacksmith {
357301
recursive_replace(item, "{{#source_code_table}}", &source_code_table);
358302
}
359303

360-
self.generate_redirects(ctx);
361-
362304
Ok(book)
363305
}
364306

book.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,30 @@ command = "./build.bash"
1313
additional-js = ["js/moment.min.js", "js/index.js"]
1414
no-section-label=true
1515
git-repository-url="https://github.com/rust-lang/rust-forge"
16+
17+
[output.html.redirect]
18+
"beta-backporting.html" = "/release/beta-backporting.html"
19+
"bibliography.html" = "https://rustc-dev-guide.rust-lang.org/appendix/bibliography.html"
20+
"channel-layout.html" = "/infra/channel-layout.html"
21+
"debugging.html" = "https://rustc-dev-guide.rust-lang.org/compiler-debugging.html"
22+
"feature_guide.html" = "https://rustc-dev-guide.rust-lang.org/implementing_new_features.html"
23+
"fott.html" = "/archive/fott.html"
24+
"infrastructure.html" = "/infra/service-infrastructure.html"
25+
"other-installation-methods.html" = "/infra/other-installation-methods.html"
26+
"platform-support.html" = "/release/platform-support.html"
27+
"profile-queries.html" = "/compiler/profile-queries.html"
28+
"release-notes.html" = "/release/release-notes.html"
29+
"releases.html" = "/archive/release-history.html"
30+
"rfc-merge-procedure.html" = "/lang/rfc-merge-procedure.html"
31+
"rustc-bug-fix-procedure.html" = "/compiler/bug-fix-procedure.html"
32+
"rustc-diagnostic-code.html" = "/compiler/diagnostic-codes.html"
33+
"rustc-team-maintenance.html" = "/infra/team-maintenance.html"
34+
"stabilization-guide.html" = "https://rustc-dev-guide.rust-lang.org/stabilization_guide.html"
35+
"state-of-rust.html" = "https://github.com/rust-lang/rust/projects/8"
36+
"test-suite.html" = "https://rustc-dev-guide.rust-lang.org/tests/intro.html"
37+
"toolstate.html" = "/infra/toolstate.html"
38+
"triage-procedure.html" = "/release/triage-procedure.html"
39+
"x-py.html" = "https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html"
40+
"compiler/bug-fix-procedure.html" = "https://rustc-dev-guide.rust-lang.org/bug-fix-procedure.html"
41+
"compiler/diagnostic-codes.html" = "https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-codes.html"
42+
"compiler/profile-queries.html" = "https://rustc-dev-guide.rust-lang.org/queries/profiling.html"

0 commit comments

Comments
 (0)