Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/bin/docs_rs_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ pub(crate) static GLOBAL_ALERT: Option<GlobalAlert> = Some(GlobalAlert {
fa_icon: "exclamation-triangle",
});
*/

pub(crate) fn get_alert() -> Option<(&'static str, usize)> {
Copy link
Copy Markdown
Member

@syphar syphar Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi:
I prepared parts of #3274 so we can include the alerts in that caching pipeline. When #3274 is merged etc I'm happy to update this PR to do it.

View changes since the review

Some((
"We are changing which targets are built by default on May 1st.<br>\
<a href=\"https://blog.rust-lang.org/2026/04/04/docsrs-only-default-targets/\">Learn more</a>",
1,
))
}
16 changes: 16 additions & 0 deletions crates/bin/docs_rs_web/templates/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(function() {
const alertCheckbox = document.getElementById("docsrs-alert-input");
alertCheckbox.onchange = () => {
// If the user clicks on the "close button", we save this info in their local storage.
window.localStorage.setItem("hide-alert-id", alertCheckbox.getAttribute("data-id"));
};

const info = window.localStorage.getItem("hide-alert-id");
if (info !== null) {
const alertId = alertCheckbox.getAttribute("data-id");
// If the user already "closed" the alert, we don't show it anymore.
if (alertId === info) {
alertCheckbox.checked = true;
}
}
})();
12 changes: 12 additions & 0 deletions crates/bin/docs_rs_web/templates/header/topbar_end.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,15 @@
</div>
</div>
</div>

{%- if let Some((alert, alert_id)) = crate::get_alert() -%}
Copy link
Copy Markdown
Member

@syphar syphar Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO: many people reach docs.rs via search, or crates.io

right now I can only see the alert on the homepage.

I would expect it to show on all pages?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's on all pages for me. Did you close it by any chance?

<input type="checkbox" id="docsrs-alert-input" data-id={{alert_id|safe}}>
<label id="docsrs-alert-hide" for="docsrs-alert-input" title="Close alert message">
{{- crate::icons::IconXmark.render_solid(false, false, "") -}}
</label>
<div id="docsrs-alert">
{{- crate::icons::IconCircleInfo.render_solid(false, false, "") -}}
<span class="alert-text">{{- alert|safe -}}</span>
</div>
<script type="text/javascript">{%- include "alert.js" -%}</script>
Copy link
Copy Markdown
Member

@syphar syphar Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should expose alert.js similar to menu.js as separate ( cacheable ) asset:

<script async src="/-/static/menu.js?{{ build_slug }}"></script>

View changes since the review

{%- endif -%}
50 changes: 50 additions & 0 deletions crates/bin/docs_rs_web/templates/style/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,53 @@ i.dependencies.normal {
visibility: hidden;
display: none;
}

#docsrs-alert-input {
display: none;
}
#docsrs-alert-hide {
z-index: 100001; // Must be one more than `#docsrs-alert`'s z-index.
right: 16px;
top: calc(#{$top-navbar-height} + 11px);
position: fixed;
cursor: pointer;
font-size: 1.3rem;
color: #ddd;
}
#docsrs-alert-hide:hover {
color: #fff;
}
#docsrs-alert {
position: fixed;
z-index: 100000;
right: 10px;
top: calc(#{$top-navbar-height} + 10px);
width: 40ch;
background: #3ea2ff;
border-radius: 6px;
font-family: $font-family-sans;
color: #fff;
display: flex;

> .fa {
padding: 0 10px;
align-content: center;
background: #64b4ff;
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
}

> .alert-text {
padding: 8px;
padding-right: 4ch;

a {
color: #fff;
text-decoration: underline;
}
}
}
#docsrs-alert-input:checked + label + #docsrs-alert,
#docsrs-alert-input:checked + label {
display: none;
}
Loading