From c07f340592dcaf3abe1f7e79be8ba6eb4f4cfe11 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 16 Sep 2019 14:12:04 +0200 Subject: [PATCH 1/2] add global alert to notify users about upcoming breaking changes --- src/lib.rs | 9 +++++++++ src/web/page.rs | 20 ++++++++++++++++++++ templates/navigation.hbs | 1 + templates/navigation_global_alert.hbs | 10 ++++++++++ templates/navigation_rustdoc.hbs | 1 + 5 files changed, 41 insertions(+) create mode 100644 templates/navigation_global_alert.hbs diff --git a/src/lib.rs b/src/lib.rs index 0da58ca8c..d67c2541d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,15 @@ pub mod utils; mod docbuilder; mod web; +use web::page::GlobalAlert; + + +// Warning message shown in the navigation bar of every page. Set to `None` to hide it. +pub(crate) static GLOBAL_ALERT: Option = Some(GlobalAlert { + url: "https://blog.rust-lang.org/2019/09/18/upcoming-docsrs-changes.html", + text: "Upcoming docs.rs breaking changes!", +}); + /// Version string generated at build time contains last git /// commit hash and build date diff --git a/src/web/page.rs b/src/web/page.rs index 6ccdb263c..bd475d833 100644 --- a/src/web/page.rs +++ b/src/web/page.rs @@ -7,6 +7,21 @@ use iron::response::Response; use handlebars_iron::Template; +pub(crate) struct GlobalAlert { + pub(crate) url: &'static str, + pub(crate) text: &'static str, +} + +impl ToJson for GlobalAlert { + fn to_json(&self) -> Json { + let mut map = BTreeMap::new(); + map.insert("url".to_string(), self.url.to_json()); + map.insert("text".to_string(), self.text.to_json()); + Json::Object(map) + } +} + + pub struct Page { title: Option, content: T, @@ -89,6 +104,11 @@ impl ToJson for Page { tree.insert("title".to_owned(), title.to_json()); } + tree.insert("has_global_alert".to_owned(), ::GLOBAL_ALERT.is_some().to_json()); + if let Some(ref global_alert) = ::GLOBAL_ALERT { + tree.insert("global_alert".to_owned(), global_alert.to_json()); + } + tree.insert("content".to_owned(), self.content.to_json()); tree.insert("cratesfyi_version".to_owned(), ::BUILD_VERSION.to_json()); tree.insert("cratesfyi_version_safe".to_owned(), diff --git a/templates/navigation.hbs b/templates/navigation.hbs index c5cb174db..d68bc11c9 100644 --- a/templates/navigation.hbs +++ b/templates/navigation.hbs @@ -21,6 +21,7 @@
  • About Docs.rs
  • + {{> navigation_global_alert}} diff --git a/templates/navigation_global_alert.hbs b/templates/navigation_global_alert.hbs new file mode 100644 index 000000000..93f1ff1f3 --- /dev/null +++ b/templates/navigation_global_alert.hbs @@ -0,0 +1,10 @@ +{{#if ../has_global_alert}} +
  • + + + {{../global_alert.text}} + + +
  • +{{/if}} + diff --git a/templates/navigation_rustdoc.hbs b/templates/navigation_rustdoc.hbs index 60a767e51..c073b42b2 100644 --- a/templates/navigation_rustdoc.hbs +++ b/templates/navigation_rustdoc.hbs @@ -101,6 +101,7 @@ {{/with}} + {{> navigation_global_alert}} From b4e734e51daf820f82bdce46097b15464217caaa Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 16 Sep 2019 14:39:15 +0200 Subject: [PATCH 2/2] improve global alert configurability and turn it red --- src/lib.rs | 2 ++ src/web/page.rs | 4 ++++ templates/navigation_global_alert.hbs | 5 ++--- templates/style.scss | 10 ++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d67c2541d..0fb8d6aa2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,8 @@ use web::page::GlobalAlert; pub(crate) static GLOBAL_ALERT: Option = Some(GlobalAlert { url: "https://blog.rust-lang.org/2019/09/18/upcoming-docsrs-changes.html", text: "Upcoming docs.rs breaking changes!", + css_class: "error", + fa_icon: "warning", }); diff --git a/src/web/page.rs b/src/web/page.rs index bd475d833..d7d081355 100644 --- a/src/web/page.rs +++ b/src/web/page.rs @@ -10,6 +10,8 @@ use handlebars_iron::Template; pub(crate) struct GlobalAlert { pub(crate) url: &'static str, pub(crate) text: &'static str, + pub(crate) css_class: &'static str, + pub(crate) fa_icon: &'static str, } impl ToJson for GlobalAlert { @@ -17,6 +19,8 @@ impl ToJson for GlobalAlert { let mut map = BTreeMap::new(); map.insert("url".to_string(), self.url.to_json()); map.insert("text".to_string(), self.text.to_json()); + map.insert("css_class".to_string(), self.css_class.to_json()); + map.insert("fa_icon".to_string(), self.fa_icon.to_json()); Json::Object(map) } } diff --git a/templates/navigation_global_alert.hbs b/templates/navigation_global_alert.hbs index 93f1ff1f3..428bb02c3 100644 --- a/templates/navigation_global_alert.hbs +++ b/templates/navigation_global_alert.hbs @@ -1,9 +1,8 @@ {{#if ../has_global_alert}}
  • - - + + {{../global_alert.text}} -
  • {{/if}} diff --git a/templates/style.scss b/templates/style.scss index 3a97bef66..7698439d4 100644 --- a/templates/style.scss +++ b/templates/style.scss @@ -19,6 +19,7 @@ $color-lifetime-incode: #B76514; // orangish $color-comment-in-code: #8E908C; // light gray $color-background-code: #F5F5F5; // lighter gray $color-border: #ddd; // gray +$color-red: #d93d3d; // red $top-navbar-height: 32px; // height of the floating top navbar @@ -214,6 +215,15 @@ div.nav-container { color: darken($color-type, 10%); } + // used for global alerts + .error { + color: $color-red; + + &:hover { + color: darken($color-red, 10%); + } + } + div.rustdoc-navigation { span.title { display: none;