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}}