-
Notifications
You must be signed in to change notification settings - Fork 209
Extract vendored css from style.css into a separate file vendored.css… #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,11 @@ pub(crate) fn rewrite_lol( | |
|
||
let templates = templates.templates.load(); | ||
let tera_head = templates.render("rustdoc/head.html", &ctx).unwrap(); | ||
let tera_vendored_css = templates.render("rustdoc/vendored.html", &ctx).unwrap(); | ||
let tera_body = templates.render("rustdoc/body.html", &ctx).unwrap(); | ||
let tera_rustdoc_header = templates.render("rustdoc/header.html", &ctx).unwrap(); | ||
|
||
// Append `style.css` stylesheet after all head elements. | ||
let head_handler = |head: &mut Element| { | ||
head.append(&tera_head, ContentType::Html); | ||
|
||
|
@@ -62,17 +64,34 @@ pub(crate) fn rewrite_lol( | |
Ok(()) | ||
}; | ||
|
||
let (head_selector, body_selector) = ("head".parse().unwrap(), "body".parse().unwrap()); | ||
let head = ( | ||
&head_selector, | ||
ElementContentHandlers::default().element(head_handler), | ||
); | ||
let body = ( | ||
&body_selector, | ||
ElementContentHandlers::default().element(body_handler), | ||
// Append `vendored.css` before the first stylesheet (rustdoc's first stylesheet is `normalize.css`). | ||
let first_stylesheet_handler = |head: &mut Element| { | ||
head.before(&tera_vendored_css, ContentType::Html); | ||
|
||
Ok(()) | ||
}; | ||
|
||
let (head_selector, body_selector, first_stylesheet_selector) = ( | ||
"head".parse().unwrap(), | ||
"body".parse().unwrap(), | ||
"link[type='text/css'][href*='normalize']".parse().unwrap(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I consider this a hack because we are assuming that the first stylesheet included by rustdoc is normalize.css which might not be the case in the future (But I gotta say, having css style selectors is pretty nice :)). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't depend on it being first, though, does it? The reason it needs to come before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well, it just needs to be positioned before |
||
); | ||
let element_content_handlers = vec![ | ||
( | ||
&head_selector, | ||
ElementContentHandlers::default().element(head_handler), | ||
), | ||
( | ||
&body_selector, | ||
ElementContentHandlers::default().element(body_handler), | ||
), | ||
( | ||
&first_stylesheet_selector, | ||
ElementContentHandlers::default().element(first_stylesheet_handler), | ||
), | ||
]; | ||
let settings = Settings { | ||
element_content_handlers: vec![head, body], | ||
element_content_handlers, | ||
memory_settings: MemorySettings { | ||
max_allowed_memory_usage, | ||
..MemorySettings::default() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<link rel="stylesheet" href="/-/static/vendored.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import "fontawesome", "regular", "solid", "brands", "pure-min", | ||
"grids-responsive-min"; | ||
|
Uh oh!
There was an error while loading. Please reload this page.