rustdoc: clean up the layout for annotated version numbers
This should result in a layout for the actual standard library,
when built on CI, that looks like this:
_____
/ \ std
| R | 1.74.0-nightly
\_____/
(203c57dbe
2023-09-17)
Having the whole version as one string caused it to flex wrap,
because the sidebar isn't wide enough to fit the whole thing.
This commit is contained in:
parent
957c5db6be
commit
6d6fa792ff
6 changed files with 23 additions and 6 deletions
|
@ -18,6 +18,7 @@ pub(crate) struct Layout {
|
||||||
pub(crate) default_settings: FxHashMap<String, String>,
|
pub(crate) default_settings: FxHashMap<String, String>,
|
||||||
pub(crate) krate: String,
|
pub(crate) krate: String,
|
||||||
pub(crate) krate_version: String,
|
pub(crate) krate_version: String,
|
||||||
|
pub(crate) krate_version_extra: String,
|
||||||
/// The given user css file which allow to customize the generated
|
/// The given user css file which allow to customize the generated
|
||||||
/// documentation theme.
|
/// documentation theme.
|
||||||
pub(crate) css_file_extension: Option<PathBuf>,
|
pub(crate) css_file_extension: Option<PathBuf>,
|
||||||
|
|
|
@ -528,13 +528,17 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||||
if let Some(url) = playground_url {
|
if let Some(url) = playground_url {
|
||||||
playground = Some(markdown::Playground { crate_name: Some(krate.name(tcx)), url });
|
playground = Some(markdown::Playground { crate_name: Some(krate.name(tcx)), url });
|
||||||
}
|
}
|
||||||
|
let krate_version = cache.crate_version.as_deref().unwrap_or_default();
|
||||||
|
let (krate_version, krate_version_extra) =
|
||||||
|
krate_version.split_once(" ").unwrap_or((krate_version, ""));
|
||||||
let mut layout = layout::Layout {
|
let mut layout = layout::Layout {
|
||||||
logo: String::new(),
|
logo: String::new(),
|
||||||
favicon: String::new(),
|
favicon: String::new(),
|
||||||
external_html,
|
external_html,
|
||||||
default_settings,
|
default_settings,
|
||||||
krate: krate.name(tcx).to_string(),
|
krate: krate.name(tcx).to_string(),
|
||||||
krate_version: cache.crate_version.as_deref().unwrap_or_default().to_string(),
|
krate_version: krate_version.to_string(),
|
||||||
|
krate_version_extra: krate_version_extra.to_string(),
|
||||||
css_file_extension: extension_css,
|
css_file_extension: extension_css,
|
||||||
scrape_examples_extension: !call_locations.is_empty(),
|
scrape_examples_extension: !call_locations.is_empty(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -492,6 +492,7 @@ ul.block, .block li {
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-elems,
|
.sidebar-elems,
|
||||||
|
.sidebar > .version,
|
||||||
.sidebar > h2 {
|
.sidebar > h2 {
|
||||||
padding-left: 24px;
|
padding-left: 24px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,12 +51,13 @@ function setMobileTopbar() {
|
||||||
// but with the current code it's hard to get the right information in the right place.
|
// but with the current code it's hard to get the right information in the right place.
|
||||||
const mobileTopbar = document.querySelector(".mobile-topbar");
|
const mobileTopbar = document.querySelector(".mobile-topbar");
|
||||||
const locationTitle = document.querySelector(".sidebar h2.location");
|
const locationTitle = document.querySelector(".sidebar h2.location");
|
||||||
if (mobileLocationTitle) {
|
if (mobileTopbar) {
|
||||||
const mobileTitle = document.createElement("h2");
|
const mobileTitle = document.createElement("h2");
|
||||||
|
mobileTitle.className = "location";
|
||||||
if (hasClass(document.body, "crate")) {
|
if (hasClass(document.body, "crate")) {
|
||||||
mobileLocationTitle.innerText = `Crate ${window.currentCrate}`;
|
mobileTitle.innerText = `Crate ${window.currentCrate}`;
|
||||||
} else if (locationTitle) {
|
} else if (locationTitle) {
|
||||||
mobileLocationTitle.innerHTML = locationTitle.innerHTML;
|
mobileTitle.innerHTML = locationTitle.innerHTML;
|
||||||
}
|
}
|
||||||
mobileTopbar.appendChild(mobileTitle);
|
mobileTopbar.appendChild(mobileTitle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,8 +101,11 @@
|
||||||
{% if !layout.krate_version.is_empty() %}
|
{% if !layout.krate_version.is_empty() %}
|
||||||
<span class="version">{{+ layout.krate_version}}</span>
|
<span class="version">{{+ layout.krate_version}}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</h2>
|
</h2> {# #}
|
||||||
</div>
|
</div> {# #}
|
||||||
|
{% if !layout.krate_version_extra.is_empty() %}
|
||||||
|
<div class="version">{{+ layout.krate_version_extra}}</div> {# #}
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ sidebar|safe }}
|
{{ sidebar|safe }}
|
||||||
</nav> {# #}
|
</nav> {# #}
|
||||||
|
|
7
tests/rustdoc/crate-version-extra.rs
Normal file
7
tests/rustdoc/crate-version-extra.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// compile-flags: '--crate-version=1.3.37-nightly (203c57dbe 2023-09-17)'
|
||||||
|
|
||||||
|
#![crate_name="foo"]
|
||||||
|
|
||||||
|
// main version next to logo, extra version data below it
|
||||||
|
// @has 'foo/index.html' '//h2/span[@class="version"]' '1.3.37-nightly'
|
||||||
|
// @has 'foo/index.html' '//nav[@class="sidebar"]/div[@class="version"]' '(203c57dbe 2023-09-17)'
|
Loading…
Add table
Add a link
Reference in a new issue