From b290aa2217a7f03530f1231a60bea5d463a580f3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 22 Jan 2022 12:05:32 +0100 Subject: [PATCH] Fix footer display following last rustdoc changes on the sidebar --- build.rs | 1 + src/utils/rustc_version.rs | 12 ++++++-- src/web/statics.rs | 6 ++++ templates/style/rustdoc-2022-01-19.scss | 40 +++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 templates/style/rustdoc-2022-01-19.scss diff --git a/build.rs b/build.rs index 84600d985..cd440f864 100644 --- a/build.rs +++ b/build.rs @@ -78,6 +78,7 @@ fn compile_sass() -> Result<(), Box> { // Compile rustdoc.scss -> rustdoc.css compile_sass_file("rustdoc", "rustdoc", &[])?; compile_sass_file("rustdoc-2021-12-05", "rustdoc-2021-12-05", &[])?; + compile_sass_file("rustdoc-2022-01-19", "rustdoc-2022-01-19", &[])?; // Compile vendored.scss -> vendored.css compile_sass_file( diff --git a/src/utils/rustc_version.rs b/src/utils/rustc_version.rs index 4f128ae13..f05b550ae 100644 --- a/src/utils/rustc_version.rs +++ b/src/utils/rustc_version.rs @@ -43,8 +43,12 @@ fn parse_rustc_date>(version: S) -> Result> { /// generate this version of this crate. pub fn get_correct_docsrs_style_file(version: &str) -> Result { let date = parse_rustc_date(version)?; + // This is the date where https://github.com/rust-lang/rust/pull/92692 was merged. + if Utc.ymd(2022, 1, 19) < date { + Ok("rustdoc-2022-01-19.css".to_owned()) + } // This is the date where https://github.com/rust-lang/rust/pull/91356 was merged. - if Utc.ymd(2021, 12, 5) < date { + else if Utc.ymd(2021, 12, 5) < date { // If this is the new rustdoc layout, we need the newer docs.rs CSS file. Ok("rustdoc-2021-12-05.css".to_owned()) } else { @@ -72,8 +76,12 @@ fn test_get_correct_docsrs_style_file() { "rustdoc.css" ); assert_eq!( - get_correct_docsrs_style_file("docsrs 0.2.0 (ba9ae23 2022-05-26)").unwrap(), + get_correct_docsrs_style_file("docsrs 0.2.0 (ba9ae23 2022-01-02)").unwrap(), "rustdoc-2021-12-05.css" ); + assert_eq!( + get_correct_docsrs_style_file("docsrs 0.2.0 (ba9ae23 2022-05-26)").unwrap(), + "rustdoc-2022-01-19.css" + ); assert!(get_correct_docsrs_style_file("docsrs 0.2.0").is_err(),); } diff --git a/src/web/statics.rs b/src/web/statics.rs index 7f2522c51..b990659aa 100644 --- a/src/web/statics.rs +++ b/src/web/statics.rs @@ -16,6 +16,8 @@ const STYLE_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/style.css")); const RUSTDOC_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/rustdoc.css")); const RUSTDOC_2021_12_05_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/rustdoc-2021-12-05.css")); +const RUSTDOC_2022_01_19_CSS: &str = + include_str!(concat!(env!("OUT_DIR"), "/rustdoc-2022-01-19.css")); const STATIC_SEARCH_PATHS: &[&str] = &["static", "vendor"]; pub(crate) fn static_handler(req: &mut Request) -> IronResult { @@ -31,6 +33,10 @@ pub(crate) fn static_handler(req: &mut Request) -> IronResult { RUSTDOC_2021_12_05_CSS, ContentType("text/css".parse().unwrap()), ), + "rustdoc-2022-01-19.css" => serve_resource( + RUSTDOC_2022_01_19_CSS, + ContentType("text/css".parse().unwrap()), + ), file => serve_file(file)?, }) } diff --git a/templates/style/rustdoc-2022-01-19.scss b/templates/style/rustdoc-2022-01-19.scss new file mode 100644 index 000000000..d60d8778f --- /dev/null +++ b/templates/style/rustdoc-2022-01-19.scss @@ -0,0 +1,40 @@ +// FIXME: Use modules +@import "rustdoc-common"; + +// This file is needed to overload the previous docs.rs style. It is added into crates generated +// using rustdoc after https://github.com/rust-lang/rust/pull/92692 has been merged. + +#rustdoc_body_wrapper { + padding: 0; + + .sidebar { + margin-top: 0; + top: $top-navbar-height; + height: calc(100vh - $top-navbar-height); + /* Since we use `overflow-wrap: anywhere;`, we never have the need for a X scrollbar... */ + overflow-x: hidden; + + .sidebar-menu { + top: $top-navbar-height; + margin-bottom: $footer-height; + } + } + + main { + padding-bottom: 50px; + } +} + +div.container-rustdoc { + > .docs-rs-footer { + bottom: 0; + right: 0; + left: 0; + } +} + +div.rustdoc { + #sidebar-toggle { + top: 0; + } +}