Skip to content

Commit 9ef923e

Browse files
committed
Auto merge of #28297 - lifthrasiir:rustdoc-html-tweaks, r=alexcrichton
I have tested the result with w3m and I believe this is better than the current template. In detail: - `section.sidebar` -> `nav.sidebar`, also added an unordered list. - `div#help` -> `aside#help`, also added a hidden heading. - The current crate is now emphasized in the sidebar. Fixes #16310.
2 parents 55da0e0 + e98fa0e commit 9ef923e

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/librustdoc/html/layout.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ r##"<!DOCTYPE html>
6262
6363
{before_content}
6464
65-
<section class="sidebar">
65+
<nav class="sidebar">
6666
{logo}
6767
{sidebar}
68-
</section>
68+
</nav>
6969
7070
<nav class="sub">
7171
<form class="search-form js-only">
@@ -83,10 +83,12 @@ r##"<!DOCTYPE html>
8383
8484
<section class="footer"></section>
8585
86-
<div id="help" class="hidden">
86+
<aside id="help" class="hidden">
8787
<div>
88+
<h1 class="hidden">Help</h1>
89+
8890
<div class="shortcuts">
89-
<h1>Keyboard Shortcuts</h1>
91+
<h2>Keyboard Shortcuts</h2>
9092
9193
<dl>
9294
<dt>?</dt>
@@ -103,7 +105,7 @@ r##"<!DOCTYPE html>
103105
</div>
104106
105107
<div class="infos">
106-
<h1>Search Tricks</h1>
108+
<h2>Search Tricks</h2>
107109
108110
<p>
109111
Prefix searches with a type followed by a colon (e.g.
@@ -123,7 +125,7 @@ r##"<!DOCTYPE html>
123125
</p>
124126
</div>
125127
</div>
126-
</div>
128+
</aside>
127129
128130
{after_content}
129131

src/librustdoc/html/static/main.css

+10-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ h3.impl, h3.method, h4.method, h3.type, h4.type {
104104
h3.impl, h3.method, h3.type {
105105
margin-top: 15px;
106106
}
107-
h1, h2, h3, h4, section.sidebar, a.source, .search-input, .content table :not(code)>a, .collapse-toggle {
107+
h1, h2, h3, h4, .sidebar, a.source, .search-input, .content table :not(code)>a, .collapse-toggle {
108108
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
109109
}
110110

@@ -189,11 +189,16 @@ nav.sub {
189189
padding: 0 10px;
190190
margin-bottom: 14px;
191191
}
192-
.block h2 {
192+
.block h2, .block h3 {
193193
margin-top: 0;
194194
margin-bottom: 8px;
195195
text-align: center;
196196
}
197+
.block ul, .block li {
198+
margin: 0;
199+
padding: 0;
200+
list-style: none;
201+
}
197202

198203
.block a {
199204
display: block;
@@ -381,7 +386,7 @@ nav.main .separator {
381386
nav.sum { text-align: right; }
382387
nav.sub form { display: inline; }
383388

384-
nav, .content {
389+
nav.sub, .content {
385390
margin-left: 230px;
386391
}
387392

@@ -407,6 +412,7 @@ a {
407412
.content span.method, .content a.method, .block a.current.method { color: #8c6067; }
408413
.content span.tymethod, .content a.tymethod, .block a.current.tymethod { color: #8c6067; }
409414
.content .fnname { color: #8c6067; }
415+
.block a.current.crate { font-weight: 500; }
410416

411417
.search-input {
412418
width: 100%;
@@ -489,7 +495,7 @@ body.blur > :not(#help) {
489495
}
490496
#help dd { margin: 5px 33px; }
491497
#help .infos { padding-left: 0; }
492-
#help h1 { margin-top: 0; }
498+
#help h1, #help h2 { margin-top: 0; }
493499
#help > div div {
494500
width: 50%;
495501
float: left;

src/librustdoc/html/static/main.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,8 @@
773773
if (rootPath === '../') {
774774
var sidebar = $('.sidebar');
775775
var div = $('<div>').attr('class', 'block crate');
776-
div.append($('<h2>').text('Crates'));
776+
div.append($('<h3>').text('Crates'));
777+
var ul = $('<ul>').appendTo(div);
777778

778779
var crates = [];
779780
for (var crate in rawSearchIndex) {
@@ -788,9 +789,10 @@
788789
}
789790
if (rawSearchIndex[crates[i]].items[0]) {
790791
var desc = rawSearchIndex[crates[i]].items[0][3];
791-
div.append($('<a>', {'href': '../' + crates[i] + '/index.html',
792+
var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
792793
'title': plainSummaryLine(desc),
793-
'class': klass}).text(crates[i]));
794+
'class': klass}).text(crates[i]);
795+
ul.append($('<li>').append(link));
794796
}
795797
}
796798
sidebar.append(div);
@@ -809,7 +811,8 @@
809811
if (!filtered) { return; }
810812

811813
var div = $('<div>').attr('class', 'block ' + shortty);
812-
div.append($('<h2>').text(longty));
814+
div.append($('<h3>').text(longty));
815+
var ul = $('<ul>').appendTo(div);
813816

814817
for (var i = 0; i < filtered.length; ++i) {
815818
var item = filtered[i];
@@ -826,9 +829,10 @@
826829
} else {
827830
path = shortty + '.' + name + '.html';
828831
}
829-
div.append($('<a>', {'href': current.relpath + path,
832+
var link = $('<a>', {'href': current.relpath + path,
830833
'title': desc,
831-
'class': klass}).text(name));
834+
'class': klass}).text(name);
835+
ul.append($('<li>').append(link));
832836
}
833837
sidebar.append(div);
834838
}

0 commit comments

Comments
 (0)