Skip to content

Commit 27dcd99

Browse files
Nemo157Joshua Nelson
authored and
Joshua Nelson
committed
Use a minimal stylesheet for the navbar on rustdoc pages
1 parent a6ec019 commit 27dcd99

File tree

7 files changed

+83
-71
lines changed

7 files changed

+83
-71
lines changed

Diff for: build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ fn compile_sass_file(
5656
}
5757
}
5858

59-
// Compile base.scss
6059
let mut context = Context::new_file(format!("{}/{}.scss", STYLE_DIR, name))?;
6160
context.set_options(Options {
6261
output_style: OutputStyle::Compressed,
@@ -76,6 +75,9 @@ fn compile_sass() -> Result<(), Box<dyn Error>> {
7675
// Compile base.scss -> style.css
7776
compile_sass_file("base", "style", &[])?;
7877

78+
// Compile rustdoc.scss -> rustdoc.css
79+
compile_sass_file("rustdoc", "rustdoc", &[])?;
80+
7981
// Compile vendored.scss -> vendored.css
8082
compile_sass_file(
8183
"vendored",

Diff for: src/web/statics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::{ffi::OsStr, fs, path::Path};
1212

1313
const VENDORED_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/vendored.css"));
1414
const STYLE_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/style.css"));
15+
const RUSTDOC_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/rustdoc.css"));
1516
const STATIC_SEARCH_PATHS: &[&str] = &["vendor/pure-css/css", "static"];
1617

1718
pub(crate) fn static_handler(req: &mut Request) -> IronResult<Response> {
@@ -21,6 +22,7 @@ pub(crate) fn static_handler(req: &mut Request) -> IronResult<Response> {
2122
Ok(match file {
2223
"vendored.css" => serve_resource(VENDORED_CSS, ContentType("text/css".parse().unwrap()))?,
2324
"style.css" => serve_resource(STYLE_CSS, ContentType("text/css".parse().unwrap()))?,
25+
"rustdoc.css" => serve_resource(RUSTDOC_CSS, ContentType("text/css".parse().unwrap()))?,
2426
file => serve_file(req, file)?,
2527
})
2628
}

Diff for: templates/rustdoc/head.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{%- import "macros.html" as macros -%}
2-
<link rel="stylesheet" href="/-/static/style.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
2+
<link rel="stylesheet" href="/-/static/rustdoc.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" />
33

44
<link rel="search" href="/-/static/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs" />
55

Diff for: templates/style/_fa.scss

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.fa-svg-fw {
2+
width: 1.25em;
3+
text-align: center;
4+
display: inline-block;
5+
}
6+
7+
.fa-svg svg {
8+
width: 1em;
9+
height: 1em;
10+
fill: currentColor;
11+
/* pull icon about one stroke width into the descenders */
12+
margin-bottom: -0.1em;
13+
}
14+

Diff for: templates/style/_navbar.scss

+41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// FIXME: Use modules
22
@import "vars", "utils";
33

4+
.pure-g [class*="pure-u"] {
5+
font-family: $font-family-sans;
6+
color: var(--color-standard);
7+
}
8+
49
div.nav-container {
510
// Nothing is supposed to be over or hovering the top navbar. Maybe add a few others '('? :)
611
z-index: 999;
@@ -12,6 +17,7 @@ div.nav-container {
1217
top: 0;
1318
position: fixed;
1419
color: var(--color-navbar-standard);
20+
font-family: $font-family-sans;
1521

1622
li {
1723
border-left: 1px solid var(--color-border);
@@ -184,3 +190,38 @@ div.nav-container {
184190
}
185191
}
186192
}
193+
194+
#nav-search {
195+
color: var(--color-navbar-standard);
196+
}
197+
198+
body {
199+
// Since top navbar is fixed, we need to add padding to the body content.
200+
padding-top: $top-navbar-height !important;
201+
202+
// The scroll padding on the <body> is necessary for Chrome
203+
// browsers for now (see
204+
// https://css-tricks.com/fixed-headers-on-page-links-and-overlapping-content-oh-my/
205+
// for an explanation)
206+
scroll-padding-top: $top-navbar-height;
207+
}
208+
209+
html {
210+
// Offset anchor jump targets down by this much, so they don't
211+
// overlap the top navigation bar (not supported on Desktop/Mobile
212+
// Safari yet):
213+
scroll-padding-top: $top-navbar-height;
214+
}
215+
216+
.menu-item-divided {
217+
border-bottom: 1px solid var(--color-border);
218+
}
219+
220+
.pure-menu-list > li.pure-menu-heading {
221+
color: var(--color-standard);
222+
}
223+
224+
i.dependencies.normal {
225+
visibility: hidden;
226+
display: none;
227+
}

Diff for: templates/style/base.scss

+4-68
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// FIXME: Use modules
2-
@import "vars", "rustdoc", "utils", "navbar", "themes";
2+
@import "vars", "utils", "navbar", "themes", "fa";
33

44
html,
55
input,
@@ -25,21 +25,17 @@ body {
2525
padding: 0;
2626
margin: 0;
2727

28-
input, :not(#rustdoc_body_wrapper) > #search {
28+
input, #search {
2929
background-color: var(--color-background-input);
3030
color: var(--input-color);
3131
}
3232

33-
#nav-search {
34-
color: var(--color-navbar-standard);
35-
}
36-
37-
:not(#rustdoc_body_wrapper) > #search {
33+
#search {
3834
box-shadow: 0 0 0 1px var(--color-border), 0 0 0 1px var(--color-border);
3935
transition: box-shadow 150ms ease-in-out;
4036
}
4137

42-
:not(#rustdoc_body_wrapper) > #search:focus {
38+
#search:focus {
4339
box-shadow: var(--input-box-shadow-focus);
4440
}
4541

@@ -49,34 +45,9 @@ body {
4945
text-align: center;
5046
font: 16px/1.4 $font-family-sans;
5147

52-
// Since top navbar is fixed, we need to add padding to the body content.
53-
padding-top: $top-navbar-height;
54-
55-
// The scroll padding on the <body> is necessary for Chrome
56-
// browsers for now (see
57-
// https://css-tricks.com/fixed-headers-on-page-links-and-overlapping-content-oh-my/
58-
// for an explanation)
59-
scroll-padding-top: $top-navbar-height;
6048
background-color: var(--color-background);
6149
color: var(--color-standard);
6250

63-
// this is a super nasty override for help dialog in rustdocs
64-
// see #52 for details
65-
&.blur {
66-
> :not(#help) {
67-
filter: none;
68-
-webkit-filter: none;
69-
}
70-
71-
> div.nav-container > *,
72-
> div.cratesfyi-package-container > *,
73-
> div.rustdoc > :not(#help) {
74-
filter: blur(8px);
75-
-webkit-filter: blur(8px);
76-
opacity: 0.7;
77-
}
78-
}
79-
8051
> h1 {
8152
color: var(--color-standard);
8253
}
@@ -99,13 +70,6 @@ body {
9970
}
10071
}
10172

102-
html {
103-
// Offset anchor jump targets down by this much, so they don't
104-
// overlap the top navigation bar (not supported on Desktop/Mobile
105-
// Safari yet):
106-
scroll-padding-top: $top-navbar-height;
107-
}
108-
10973
pre {
11074
font-size: 0.9rem;
11175
overflow: auto;
@@ -330,10 +294,6 @@ div.package-sheet-container {
330294
}
331295
}
332296

333-
.pure-menu-list > li.pure-menu-heading {
334-
color: var(--color-standard);
335-
}
336-
337297
div.package-page-container {
338298
div.package-menu {
339299
padding: 0 10px;
@@ -620,10 +580,6 @@ div.search-page-search-form {
620580
}
621581
}
622582

623-
.menu-item-divided {
624-
border-bottom: 1px solid var(--color-border);
625-
}
626-
627583
.rust-navigation-item {
628584
background: url(/rust-logo.png) no-repeat;
629585
background-position: 15px 45%;
@@ -679,28 +635,8 @@ div.search-page-search-form {
679635
cursor: pointer;
680636
}
681637

682-
i.dependencies.normal {
683-
visibility: hidden;
684-
display: none;
685-
}
686-
687638
/* Don't put a newline after code fragments in headers */
688639
h3 > code,
689640
h4 > code {
690641
display: inline-block;
691642
}
692-
693-
.fa-svg-fw {
694-
width: 1.25em;
695-
text-align: center;
696-
display: inline-block;
697-
}
698-
699-
.fa-svg svg {
700-
width: 1em;
701-
height: 1em;
702-
fill: currentColor;
703-
/* pull icon about one stroke width into the descenders */
704-
margin-bottom: -0.1em;
705-
}
706-

Diff for: templates/style/_rustdoc.scss renamed to templates/style/rustdoc.scss

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// FIXME: Use modules
2-
@import "vars";
2+
@import "vars", "navbar", "themes", "fa";
33

44
// Force the navbar to be left-aligned on rustdoc pages
55
body.rustdoc-page > .nav-container > .container {
@@ -10,6 +10,23 @@ div.container-rustdoc {
1010
text-align: left;
1111
}
1212

13+
// this is a super nasty override for help dialog in rustdocs
14+
// see #52 for details
15+
body.blur {
16+
> :not(#help) {
17+
filter: none;
18+
-webkit-filter: none;
19+
}
20+
21+
> div.nav-container > *,
22+
> div.cratesfyi-package-container > *,
23+
> div.rustdoc > :not(#help) {
24+
filter: blur(8px);
25+
-webkit-filter: blur(8px);
26+
opacity: 0.7;
27+
}
28+
}
29+
1330
// rustdoc overrides
1431
div.rustdoc {
1532
font-family: $font-family-serif;

0 commit comments

Comments
 (0)