Skip to content

Commit

Permalink
Indicate current documentation target
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 30, 2023
1 parent d48d903 commit c5fa27a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ struct RustdocPage {
is_prerelease: bool,
krate: CrateDetails,
metadata: MetaData,
current_target: String,
}

impl RustdocPage {
Expand Down Expand Up @@ -624,10 +625,13 @@ pub(crate) async fn rustdoc_html_server_handler(
};

// Find the path of the latest version for the `Go to latest` and `Permalink` links
let mut current_target = String::new();
let target_redirect = if latest_release.build_status {
let target = if target.is_empty() {
current_target = krate.metadata.default_target.clone();
&krate.metadata.default_target
} else {
current_target = target.to_owned();
target
};
format!("/target-redirect/{target}/{inner_path}")
Expand Down Expand Up @@ -680,6 +684,7 @@ pub(crate) async fn rustdoc_html_server_handler(
is_prerelease,
metadata,
krate,
current_target,
}
.into_response(
&blob.content,
Expand Down
7 changes: 6 additions & 1 deletion templates/rustdoc/topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,14 @@
{%- set target_url = "/crate/" ~ metadata.name ~ "/" ~ metadata.version_or_latest ~ "/target-redirect/" ~ target ~ "/" ~ inner_path -%}
{%- set target_no_follow = "nofollow" -%}
{%- endif -%}
{%- if current_target is defined and current_target == target -%}
{%- set current = " current" -%}
{%- else -%}
{%- set current = "" -%}
{%- endif -%}

<li class="pure-menu-item">
<a href="{{ target_url | safe }}" class="pure-menu-link" data-fragment="retain" rel="{{ target_no_follow }}">
<a href="{{ target_url | safe }}" class="pure-menu-link{{ current | safe }}" data-fragment="retain" rel="{{ target_no_follow }}">
{{- target -}}
</a>
</li>
Expand Down
10 changes: 10 additions & 0 deletions templates/style/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,16 @@ div.nav-container {
li a {
overflow-x: hidden;
text-overflow: ellipsis;

&.current {
font-weight: bold;

&::before {
content: "";
position: absolute;
margin-left: -10px;
}
}
}
}
}
Expand Down

0 comments on commit c5fa27a

Please sign in to comment.