Skip to content

Commit 829770a

Browse files
committed
Fix rustdoc styles for very old docs
Previously this used the selector `link[type='text/css'][href*='normalize']` to inject the vendored HTML. Unfortunately, this selector did not exist in very old versions of rustdoc. Instead, this now adds the `vendored.css` stylesheet at the start of the `<head>` tag.
1 parent 8fecbb4 commit 829770a

File tree

3 files changed

+2
-19
lines changed

3 files changed

+2
-19
lines changed

src/utils/html.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub(crate) fn rewrite_lol(
1919

2020
let templates = templates.templates.load();
2121
let tera_head = templates.render("rustdoc/head.html", &ctx).unwrap();
22-
let tera_vendored_css = templates.render("rustdoc/vendored.html", &ctx).unwrap();
2322
let tera_body = templates.render("rustdoc/body.html", &ctx).unwrap();
2423
let tera_rustdoc_header = templates.render("rustdoc/header.html", &ctx).unwrap();
2524

@@ -64,18 +63,7 @@ pub(crate) fn rewrite_lol(
6463
Ok(())
6564
};
6665

67-
// Append `vendored.css` before the first stylesheet (rustdoc's first stylesheet is `normalize.css`).
68-
let first_stylesheet_handler = |head: &mut Element| {
69-
head.before(&tera_vendored_css, ContentType::Html);
70-
71-
Ok(())
72-
};
73-
74-
let (head_selector, body_selector, first_stylesheet_selector) = (
75-
"head".parse().unwrap(),
76-
"body".parse().unwrap(),
77-
"link[type='text/css'][href*='normalize']".parse().unwrap(),
78-
);
66+
let (head_selector, body_selector) = ("head".parse().unwrap(), "body".parse().unwrap());
7967
let element_content_handlers = vec![
8068
(
8169
&head_selector,
@@ -85,10 +73,6 @@ pub(crate) fn rewrite_lol(
8573
&body_selector,
8674
ElementContentHandlers::default().element(body_handler),
8775
),
88-
(
89-
&first_stylesheet_selector,
90-
ElementContentHandlers::default().element(first_stylesheet_handler),
91-
),
9276
];
9377
let settings = Settings {
9478
element_content_handlers,

templates/rustdoc/head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{%- import "macros.html" as macros -%}
22
<link rel="stylesheet" href="/-/static/style.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
3+
<link rel="stylesheet" href="/-/static/vendored.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
34

45
<link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs">

templates/rustdoc/vendored.html

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

0 commit comments

Comments
 (0)