3 use std::path::PathBuf;
5 use crate::externalfiles::ExternalHtml;
6 use crate::html::render::SlashChecker;
12 pub external_html: ExternalHtml,
18 pub css_class: &'a str,
19 pub root_path: &'a str,
20 pub static_root_path: Option<&'a str>,
21 pub description: &'a str,
22 pub keywords: &'a str,
23 pub resource_suffix: &'a str,
24 pub extra_scripts: &'a [&'a str],
25 pub static_extra_scripts: &'a [&'a str],
28 pub fn render<T: fmt::Display, S: fmt::Display>(
29 dst: &mut dyn io::Write,
34 css_file_extension: bool,
36 generate_search_filter: bool,
38 let static_root_path = page.static_root_path.unwrap_or(page.root_path);
43 <meta charset=\"utf-8\">\
44 <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
45 <meta name=\"generator\" content=\"rustdoc\">\
46 <meta name=\"description\" content=\"{description}\">\
47 <meta name=\"keywords\" content=\"{keywords}\">\
48 <title>{title}</title>\
49 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
50 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \
51 id=\"mainThemeStyle\">\
53 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}dark{suffix}.css\">\
54 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}light{suffix}.css\" \
56 <script src=\"{static_root_path}storage{suffix}.js\"></script>\
57 <noscript><link rel=\"stylesheet\" href=\"{static_root_path}noscript{suffix}.css\"></noscript>\
61 <style type=\"text/css\">\
62 #crate-search{{background-image:url(\"{static_root_path}down-arrow{suffix}.svg\");}}\
65 <body class=\"rustdoc {css_class}\">\
67 <div class=\"warning\">\
68 This old browser is unsupported and will most likely display funky \
73 <nav class=\"sidebar\">\
74 <div class=\"sidebar-menu\">☰</div>\
78 <div class=\"theme-picker\">\
79 <button id=\"theme-picker\" aria-label=\"Pick another theme!\">\
80 <img src=\"{static_root_path}brush{suffix}.svg\" \
82 alt=\"Pick another theme!\">\
84 <div id=\"theme-choices\"></div>\
86 <script src=\"{static_root_path}theme{suffix}.js\"></script>\
88 <form class=\"search-form js-only\">\
89 <div class=\"search-container\">\
91 <input class=\"search-input\" name=\"search\" \
92 autocomplete=\"off\" \
93 spellcheck=\"false\" \
94 placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \
97 <a id=\"settings-menu\" href=\"{root_path}settings.html\">\
98 <img src=\"{static_root_path}wheel{suffix}.svg\" \
100 alt=\"Change settings\">\
105 <section id=\"main\" class=\"content\">{content}</section>\
106 <section id=\"search\" class=\"content hidden\"></section>\
107 <section class=\"footer\"></section>\
108 <aside id=\"help\" class=\"hidden\">\
110 <h1 class=\"hidden\">Help</h1>\
111 <div class=\"shortcuts\">\
112 <h2>Keyboard Shortcuts</h2>\
114 <dt><kbd>?</kbd></dt>\
115 <dd>Show this help dialog</dd>\
116 <dt><kbd>S</kbd></dt>\
117 <dd>Focus the search field</dd>\
118 <dt><kbd>↑</kbd></dt>\
119 <dd>Move up in search results</dd>\
120 <dt><kbd>↓</kbd></dt>\
121 <dd>Move down in search results</dd>\
122 <dt><kbd>↹</kbd></dt>\
124 <dt><kbd>⏎</kbd></dt>\
125 <dd>Go to active search result</dd>\
126 <dt><kbd>+</kbd></dt>\
127 <dd>Expand all sections</dd>\
128 <dt><kbd>-</kbd></dt>\
129 <dd>Collapse all sections</dd>\
132 <div class=\"infos\">\
133 <h2>Search Tricks</h2>\
135 Prefix searches with a type followed by a colon (e.g., \
136 <code>fn:</code>) to restrict the search to a given type.\
139 Accepted types are: <code>fn</code>, <code>mod</code>, \
140 <code>struct</code>, <code>enum</code>, \
141 <code>trait</code>, <code>type</code>, <code>macro</code>, \
142 and <code>const</code>.\
145 Search functions by type signature (e.g., \
146 <code>vec -> usize</code> or <code>* -> vec</code>)\
149 Search multiple things at once by splitting your query with comma (e.g., \
150 <code>str,u8</code> or <code>String,struct:Vec,test</code>)\
157 window.rootPath = \"{root_path}\";\
158 window.currentCrate = \"{krate}\";\
160 <script src=\"{root_path}aliases{suffix}.js\"></script>\
161 <script src=\"{static_root_path}main{suffix}.js\"></script>\
162 {static_extra_scripts}\
164 <script defer src=\"{root_path}search-index{suffix}.js\"></script>\
167 css_extension = if css_file_extension {
168 format!("<link rel=\"stylesheet\" \
170 href=\"{static_root_path}theme{suffix}.css\">",
171 static_root_path = static_root_path,
172 suffix=page.resource_suffix)
177 static_root_path = static_root_path,
178 root_path = page.root_path,
179 css_class = page.css_class,
181 let p = format!("{}{}", page.root_path, layout.krate);
182 let p = SlashChecker(&p);
183 if layout.logo.is_empty() {
184 format!("<a href='{path}index.html'>\
185 <div class='logo-container'>\
186 <img src='{static_root_path}rust-logo{suffix}.png' alt='logo'></div></a>",
188 static_root_path=static_root_path,
189 suffix=page.resource_suffix)
191 format!("<a href='{}index.html'>\
192 <div class='logo-container'><img src='{}' alt='logo'></div></a>",
198 description = page.description,
199 keywords = page.keywords,
200 favicon = if layout.favicon.is_empty() {
201 format!(r#"<link rel="shortcut icon" href="{static_root_path}favicon{suffix}.ico">"#,
202 static_root_path=static_root_path,
203 suffix=page.resource_suffix)
205 format!(r#"<link rel="shortcut icon" href="{}">"#, layout.favicon)
207 in_header = layout.external_html.in_header,
208 before_content = layout.external_html.before_content,
209 after_content = layout.external_html.after_content,
211 krate = layout.krate,
212 themes = themes.iter()
213 .filter_map(|t| t.file_stem())
214 .filter_map(|t| t.to_str())
215 .map(|t| format!(r#"<link rel="stylesheet" type="text/css" href="{}{}{}.css">"#,
218 page.resource_suffix))
219 .collect::<String>(),
220 suffix=page.resource_suffix,
221 static_extra_scripts=page.static_extra_scripts.iter().map(|e| {
222 format!("<script src=\"{static_root_path}{extra_script}.js\"></script>",
223 static_root_path=static_root_path,
225 }).collect::<String>(),
226 extra_scripts=page.extra_scripts.iter().map(|e| {
227 format!("<script src=\"{root_path}{extra_script}.js\"></script>",
228 root_path=page.root_path,
230 }).collect::<String>(),
231 filter_crates=if generate_search_filter {
232 "<select id=\"crate-search\">\
233 <option value=\"All crates\">All crates</option>\
241 pub fn redirect(dst: &mut dyn io::Write, url: &str) -> io::Result<()> {
242 // <script> triggers a redirect before refresh, so this is fine.
247 <meta http-equiv="refresh" content="0;URL={url}">
250 <p>Redirecting to <a href="{url}">{url}</a>...</p>
251 <script>location.replace("{url}" + location.search + location.hash);</script>