Skip to content

Commit

Permalink
Fix footer display following last rustdoc changes on the sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 22, 2022
1 parent 1dd2aee commit b290aa2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fn compile_sass() -> Result<(), Box<dyn Error>> {
// 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(
Expand Down
12 changes: 10 additions & 2 deletions src/utils/rustc_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ fn parse_rustc_date<S: AsRef<str>>(version: S) -> Result<Date<Utc>> {
/// generate this version of this crate.
pub fn get_correct_docsrs_style_file(version: &str) -> Result<String> {
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 {
Expand Down Expand Up @@ -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(),);
}
6 changes: 6 additions & 0 deletions src/web/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> {
Expand All @@ -31,6 +33,10 @@ pub(crate) fn static_handler(req: &mut Request) -> IronResult<Response> {
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)?,
})
}
Expand Down
40 changes: 40 additions & 0 deletions templates/style/rustdoc-2022-01-19.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit b290aa2

Please sign in to comment.