File tree Expand file tree Collapse file tree 5 files changed +41
-0
lines changed Expand file tree Collapse file tree 5 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,15 @@ pub mod utils;
5353mod docbuilder;
5454mod web;
5555
56+ use web:: page:: GlobalAlert ;
57+
58+
59+ // Warning message shown in the navigation bar of every page. Set to `None` to hide it.
60+ pub ( crate ) static GLOBAL_ALERT : Option < GlobalAlert > = Some ( GlobalAlert {
61+ url : "https://blog.rust-lang.org/2019/09/18/upcoming-docsrs-changes.html" ,
62+ text : "Upcoming docs.rs breaking changes!" ,
63+ } ) ;
64+
5665
5766/// Version string generated at build time contains last git
5867/// commit hash and build date
Original file line number Diff line number Diff line change @@ -7,6 +7,21 @@ use iron::response::Response;
77use handlebars_iron:: Template ;
88
99
10+ pub ( crate ) struct GlobalAlert {
11+ pub ( crate ) url : & ' static str ,
12+ pub ( crate ) text : & ' static str ,
13+ }
14+
15+ impl ToJson for GlobalAlert {
16+ fn to_json ( & self ) -> Json {
17+ let mut map = BTreeMap :: new ( ) ;
18+ map. insert ( "url" . to_string ( ) , self . url . to_json ( ) ) ;
19+ map. insert ( "text" . to_string ( ) , self . text . to_json ( ) ) ;
20+ Json :: Object ( map)
21+ }
22+ }
23+
24+
1025pub struct Page < T : ToJson > {
1126 title : Option < String > ,
1227 content : T ,
@@ -89,6 +104,11 @@ impl<T: ToJson> ToJson for Page<T> {
89104 tree. insert ( "title" . to_owned ( ) , title. to_json ( ) ) ;
90105 }
91106
107+ tree. insert ( "has_global_alert" . to_owned ( ) , :: GLOBAL_ALERT . is_some ( ) . to_json ( ) ) ;
108+ if let Some ( ref global_alert) = :: GLOBAL_ALERT {
109+ tree. insert ( "global_alert" . to_owned ( ) , global_alert. to_json ( ) ) ;
110+ }
111+
92112 tree. insert ( "content" . to_owned ( ) , self . content . to_json ( ) ) ;
93113 tree. insert ( "cratesfyi_version" . to_owned ( ) , :: BUILD_VERSION . to_json ( ) ) ;
94114 tree. insert ( "cratesfyi_version_safe" . to_owned ( ) ,
Original file line number Diff line number Diff line change 2121 <li class =" pure-menu-item" ><a href =" /about" class =" pure-menu-link" >About Docs.rs</a ></li >
2222 </ul >
2323 </li >
24+ {{> navigation_global_alert }}
2425 </ul >
2526 </form >
2627 </div >
Original file line number Diff line number Diff line change 1+ {{ #if ../has_global_alert }}
2+ <li class =" pure-menu-item" >
3+ <a href =" {{ ../global_alert.url }} " class =" pure-menu-link warn" >
4+ <i class =" fa fa-fw fa-warning" ></i >
5+ {{ ../global_alert.text }}
6+ <i class =" fa fa-fw fa-warning" ></i >
7+ </a >
8+ </li >
9+ {{ /if }}
10+
Original file line number Diff line number Diff line change 101101 </ul >
102102 </li >
103103 {{ /with }}
104+ {{> navigation_global_alert }}
104105 </ul >
105106 </form >
106107 </div >
You can’t perform that action at this time.
0 commit comments