diff --git a/src/lib.rs b/src/lib.rs index 0da58ca8c..0fb8d6aa2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,17 @@ 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!", + css_class: "error", + fa_icon: "warning", +}); + /// 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..d7d081355 100644 --- a/src/web/page.rs +++ b/src/web/page.rs @@ -7,6 +7,25 @@ use iron::response::Response; 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 { + 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()); + 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) + } +} + + pub struct Page { title: Option, content: T, @@ -89,6 +108,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..428bb02c3 --- /dev/null +++ b/templates/navigation_global_alert.hbs @@ -0,0 +1,9 @@ +{{#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}} 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;