Skip to content

Commit

Permalink
Change redirect implementation (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky authored Jun 8, 2020
1 parent 9a07a5c commit a919848
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 71 deletions.
12 changes: 0 additions & 12 deletions blacksmith/redirect.html

This file was deleted.

60 changes: 1 addition & 59 deletions blacksmith/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
collections::BTreeMap,
fmt::Write,
io::{BufRead, BufReader},
path::Path,
time::SystemTime,
};

Expand Down Expand Up @@ -128,61 +127,6 @@ impl Blacksmith {
Ok(blacksmith)
}

fn generate_redirects(&self, ctx: &PreprocessorContext) {
if ctx.renderer != "html" {
return;
}

let dir = ctx.config.build.build_dir.as_path();

/// A list of pairs of file names and where to redirect to from their
/// page.
#[rustfmt::skip]
const REDIRECTS: &[(&str, &str)] = &[
("beta-backporting.html", "/release/beta-backporting.html"),
("bibliography.html", "https://rustc-dev-guide.rust-lang.org/appendix/bibliography.html"),
("channel-layout.html", "/infra/channel-layout.html"),
("debugging.html", "https://rustc-dev-guide.rust-lang.org/compiler-debugging.html"),
("feature_guide.html", "https://rustc-dev-guide.rust-lang.org/implementing_new_features.html"),
("fott.html", "/archive/fott.html"),
("infrastructure.html", "/infra/service-infrastructure.html"),
("other-installation-methods.html", "/infra/other-installation-methods.html"),
("platform-support.html", "/release/platform-support.html"),
("profile-queries.html", "/compiler/profile-queries.html"),
("release-notes.html", "/release/release-notes.html"),
("releases.html", "/archive/release-history.html"),
("rfc-merge-procedure.html", "/lang/rfc-merge-procedure.html"),
("rustc-bug-fix-procedure.html", "/compiler/bug-fix-procedure.html"),
("rustc-diagnostic-code.html", "/compiler/diagnostic-codes.html"),
("rustc-team-maintenance.html", "/infra/team-maintenance.html"),
("stabilization-guide.html", "https://rustc-dev-guide.rust-lang.org/stabilization_guide.html"),
("state-of-rust.html", "https://github.com/rust-lang/rust/projects/8"),
("test-suite.html", "https://rustc-dev-guide.rust-lang.org/tests/intro.html"),
("toolstate.html", "/infra/toolstate.html"),
("triage-procedure.html", "/release/triage-procedure.html"),
("x-py.html", "https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html"),
("compiler/bug-fix-procedure.html", "https://rustc-dev-guide.rust-lang.org/bug-fix-procedure.html"),
("compiler/diagnostic-codes.html", "https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-codes.html"),
("compiler/profile-queries.html", "https://rustc-dev-guide.rust-lang.org/queries/profiling.html"),
];

// Inititalise book directory if not built yet.
std::fs::create_dir_all(dir).unwrap();

log::info!("Generating {} redirect pages.", REDIRECTS.len());
for (filename, url) in REDIRECTS {
let template = include_str!("../redirect.html").replace("{{url}}", url);

log::trace!("Redirecting {} to {}.", filename, url);

if let Some(parent) = Path::new(filename).parent() {
std::fs::create_dir_all(dir.join(parent)).unwrap();
}

std::fs::write(dir.join(filename), template).unwrap();
}
}

/// Creates a list of hyperlinks to `rustup-init` based on what targets
/// rustup provided using the following URL schema. Where `target` is the
/// platforms target tuple (`x86_64-apple-darwin`) and `suffix` is a target
Expand Down Expand Up @@ -328,7 +272,7 @@ impl Preprocessor for Blacksmith {
"blacksmith"
}

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

self.generate_redirects(ctx);

Ok(book)
}

Expand Down
27 changes: 27 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,30 @@ command = "./build.bash"
additional-js = ["js/moment.min.js", "js/index.js"]
no-section-label=true
git-repository-url="https://github.com/rust-lang/rust-forge"

[output.html.redirect]
"beta-backporting.html" = "/release/beta-backporting.html"
"bibliography.html" = "https://rustc-dev-guide.rust-lang.org/appendix/bibliography.html"
"channel-layout.html" = "/infra/channel-layout.html"
"debugging.html" = "https://rustc-dev-guide.rust-lang.org/compiler-debugging.html"
"feature_guide.html" = "https://rustc-dev-guide.rust-lang.org/implementing_new_features.html"
"fott.html" = "/archive/fott.html"
"infrastructure.html" = "/infra/service-infrastructure.html"
"other-installation-methods.html" = "/infra/other-installation-methods.html"
"platform-support.html" = "/release/platform-support.html"
"profile-queries.html" = "/compiler/profile-queries.html"
"release-notes.html" = "/release/release-notes.html"
"releases.html" = "/archive/release-history.html"
"rfc-merge-procedure.html" = "/lang/rfc-merge-procedure.html"
"rustc-bug-fix-procedure.html" = "/compiler/bug-fix-procedure.html"
"rustc-diagnostic-code.html" = "/compiler/diagnostic-codes.html"
"rustc-team-maintenance.html" = "/infra/team-maintenance.html"
"stabilization-guide.html" = "https://rustc-dev-guide.rust-lang.org/stabilization_guide.html"
"state-of-rust.html" = "https://github.com/rust-lang/rust/projects/8"
"test-suite.html" = "https://rustc-dev-guide.rust-lang.org/tests/intro.html"
"toolstate.html" = "/infra/toolstate.html"
"triage-procedure.html" = "/release/triage-procedure.html"
"x-py.html" = "https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html"
"compiler/bug-fix-procedure.html" = "https://rustc-dev-guide.rust-lang.org/bug-fix-procedure.html"
"compiler/diagnostic-codes.html" = "https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-codes.html"
"compiler/profile-queries.html" = "https://rustc-dev-guide.rust-lang.org/queries/profiling.html"

0 comments on commit a919848

Please sign in to comment.