Tweak breadcrumbs list

This commit is contained in:
Michael Howell 2024-09-10 22:03:54 -07:00
parent e31a719cce
commit cc3ffe4c91
9 changed files with 39 additions and 34 deletions

View File

@ -194,6 +194,11 @@ h1, h2, h3, h4 {
display: flex;
align-items: end;
}
.rustdoc-breadcrumbs a {
padding: 4px 0;
margin: -4px 0;
z-index: 1;
}
/* The only headings that get underlines are:
Markdown-generated headings within the top-doc
Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc)

View File

@ -1,6 +1,6 @@
// Local js definitions:
/* global addClass, getSettingValue, hasClass, searchState, updateLocalStorage */
/* global onEach, onEachLazy, removeClass, getVar */
/* global onEachLazy, removeClass, getVar */
"use strict";
@ -1826,14 +1826,11 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
return;
}
but.onclick = () => {
const parent = but.parentElement;
const path = [];
onEach(parent.childNodes, child => {
if (child.tagName === "A") {
path.push(child.textContent);
}
onEachLazy(document.querySelectorAll(".rustdoc-breadcrumbs a"), a => {
path.push(a.textContent);
});
path.push(document.querySelector("title").textContent.split(" ")[0]);
copyContentToClipboard(path.join("::"));
copyButtonAnimation(but);

View File

@ -1,8 +1,11 @@
<div class="main-heading"> {# #}
{% if !path_components.is_empty() %}
<span class="rustdoc-breadcrumbs">
{% for component in path_components %}
<a href="{{component.path|safe}}index.html">{{component.name}}</a>::<wbr>
{% for (i, component) in path_components.iter().enumerate() %}
{% if i != 0 %}
::<wbr>
{% endif %}
<a href="{{component.path|safe}}index.html">{{component.name}}</a>
{% endfor %}
</span>
{% endif %}
@ -15,7 +18,7 @@
Copy item path {# #}
</button> {# #}
</h1> {# #}
<rustdoc-toolbar></rustdoc-toolbar>
<rustdoc-toolbar></rustdoc-toolbar> {# #}
<span class="sub-heading">
{% if !stability_since_raw.is_empty() %}
{{ stability_since_raw|safe +}}
@ -26,5 +29,5 @@
<a class="src" href="{{href|safe}}">source</a> {#+ #}
{% else %}
{% endmatch %}
</span>
</span> {# #}
</div> {# #}

View File

@ -16,5 +16,5 @@ assert-css: ("#main-content", {"display": "none"})
// Now we can check that the feature is working as expected!
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo&go_to_first=true"
// Waiting for the page to load...
wait-for-text: (".main-heading .rustdoc-breadcrumbs", "test_docs::")
wait-for-text: (".main-heading .rustdoc-breadcrumbs", "test_docs")
wait-for-text: (".main-heading h1", "Struct FooCopy item path")

View File

@ -12,5 +12,5 @@ assert-attribute-false: (".impl-items .toggle", {"open": ""})
// Click the "Trait" part of "impl Trait" and verify it navigates.
click: "#impl-Trait-for-Foo h3 a:first-of-type"
assert-text: (".main-heading .rustdoc-breadcrumbs", "lib2::")
assert-text: (".main-heading .rustdoc-breadcrumbs", "lib2")
assert-text: (".main-heading h1", "Trait TraitCopy item path")

View File

@ -3,17 +3,17 @@
//@ has 'empty_mod_private/index.html' '//a[@href="foo/index.html"]' 'foo'
//@ hasraw 'empty_mod_private/sidebar-items.js' 'foo'
//@ matches 'empty_mod_private/foo/index.html' '//h1' 'Module foo'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private'
mod foo {}
//@ has 'empty_mod_private/index.html' '//a[@href="bar/index.html"]' 'bar'
//@ hasraw 'empty_mod_private/sidebar-items.js' 'bar'
//@ matches 'empty_mod_private/bar/index.html' '//h1' 'Module bar'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private'
mod bar {
//@ has 'empty_mod_private/bar/index.html' '//a[@href="baz/index.html"]' 'baz'
//@ hasraw 'empty_mod_private/bar/sidebar-items.js' 'baz'
//@ matches 'empty_mod_private/bar/baz/index.html' '//h1' 'Module baz'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::bar::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::bar'
mod baz {}
}

View File

@ -1,17 +1,17 @@
//@ has 'empty_mod_public/index.html' '//a[@href="foo/index.html"]' 'foo'
//@ hasraw 'empty_mod_public/sidebar-items.js' 'foo'
//@ matches 'empty_mod_public/foo/index.html' '//h1' 'Module foo'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public'
pub mod foo {}
//@ has 'empty_mod_public/index.html' '//a[@href="bar/index.html"]' 'bar'
//@ hasraw 'empty_mod_public/sidebar-items.js' 'bar'
//@ matches 'empty_mod_public/bar/index.html' '//h1' 'Module bar'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public'
pub mod bar {
//@ has 'empty_mod_public/bar/index.html' '//a[@href="baz/index.html"]' 'baz'
//@ hasraw 'empty_mod_public/bar/sidebar-items.js' 'baz'
//@ matches 'empty_mod_public/bar/baz/index.html' '//h1' 'Module baz'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::bar::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::bar'
pub mod baz {}
}

View File

@ -11,18 +11,18 @@
//@ has - '//a/[@href="struct.StepBy.html"]' "StepBy"
//@ has foo/iter/struct.DeprecatedStepBy.html
//@ has - '//h1' "Struct DeprecatedStepBy"
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter'
//@ has foo/iter/struct.StepBy.html
//@ has - '//h1' "Struct StepBy"
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter'
//@ has bar/iter/index.html
//@ has - '//a/[@href="struct.DeprecatedStepBy.html"]' "DeprecatedStepBy"
//@ has - '//a/[@href="struct.StepBy.html"]' "StepBy"
//@ has bar/iter/struct.DeprecatedStepBy.html
//@ has - '//h1' "Struct DeprecatedStepBy"
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter'
//@ has bar/iter/struct.StepBy.html
//@ has - '//h1' "Struct StepBy"
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter'
pub use foo::iter;

View File

@ -6,7 +6,7 @@
//@ count 'foo/index.html' '//h2[@class="location"]' 0
//@ matches 'foo/foo_mod/index.html' '//h1' 'Module foo_mod'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
//@ matches - '//h2[@class="location"]' 'Module foo_mod'
pub mod foo_mod {
pub struct __Thing {}
@ -14,36 +14,36 @@ pub struct __Thing {}
extern "C" {
//@ matches 'foo/fn.foo_ffn.html' '//h1' 'Function foo_ffn'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
pub fn foo_ffn();
}
//@ matches 'foo/fn.foo_fn.html' '//h1' 'Function foo_fn'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
pub fn foo_fn() {}
//@ matches 'foo/trait.FooTrait.html' '//h1' 'Trait FooTrait'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
//@ matches - '//h2[@class="location"]' 'FooTrait'
pub trait FooTrait {}
//@ matches 'foo/struct.FooStruct.html' '//h1' 'Struct FooStruct'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
//@ matches - '//h2[@class="location"]' 'FooStruct'
pub struct FooStruct;
//@ matches 'foo/enum.FooEnum.html' '//h1' 'Enum FooEnum'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
//@ matches - '//h2[@class="location"]' 'FooEnum'
pub enum FooEnum {}
//@ matches 'foo/type.FooType.html' '//h1' 'Type Alias FooType'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
//@ matches - '//h2[@class="location"]' 'FooType'
pub type FooType = FooStruct;
//@ matches 'foo/macro.foo_macro.html' '//h1' 'Macro foo_macro'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
#[macro_export]
macro_rules! foo_macro {
() => {};
@ -55,15 +55,15 @@ macro_rules! foo_macro {
mod bool {}
//@ matches 'foo/static.FOO_STATIC.html' '//h1' 'Static FOO_STATIC'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
pub static FOO_STATIC: FooStruct = FooStruct;
extern "C" {
//@ matches 'foo/static.FOO_FSTATIC.html' '//h1' 'Static FOO_FSTATIC'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
pub static FOO_FSTATIC: FooStruct;
}
//@ matches 'foo/constant.FOO_CONSTANT.html' '//h1' 'Constant FOO_CONSTANT'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::'
//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo'
pub const FOO_CONSTANT: FooStruct = FooStruct;