]>
git.proxmox.com Git - rustc.git/blob - src/librustdoc/html/layout.rs
1 use std
::path
::PathBuf
;
3 use crate::externalfiles
::ExternalHtml
;
4 use crate::html
::escape
::Escape
;
5 use crate::html
::render
::ensure_trailing_slash
;
6 use crate::html
::format
::{Buffer, Print}
;
12 pub external_html
: ExternalHtml
,
14 /// The given user css file which allow to customize the generated
15 /// documentation theme.
16 pub css_file_extension
: Option
<PathBuf
>,
17 /// If false, the `select` element to have search filtering by crates on rendered docs
18 /// won't be generated.
19 pub generate_search_filter
: bool
,
24 pub css_class
: &'a
str,
25 pub root_path
: &'a
str,
26 pub static_root_path
: Option
<&'a
str>,
27 pub description
: &'a
str,
28 pub keywords
: &'a
str,
29 pub resource_suffix
: &'a
str,
30 pub extra_scripts
: &'a
[&'a
str],
31 pub static_extra_scripts
: &'a
[&'a
str],
34 pub fn render
<T
: Print
, S
: Print
>(
41 let static_root_path
= page
.static_root_path
.unwrap_or(page
.root_path
);
42 format
!("<!DOCTYPE html>\
45 <meta charset=\"utf-8\">\
46 <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
47 <meta name=\"generator\" content=\"rustdoc\">\
48 <meta name=\"description\" content=\"{description}\">\
49 <meta name=\"keywords\" content=\"{keywords}\">\
50 <title>{title}</title>\
51 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
52 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \
53 id=\"mainThemeStyle\">\
55 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}dark{suffix}.css\">\
56 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}light{suffix}.css\" \
58 <script src=\"{static_root_path}storage{suffix}.js\"></script>\
59 <noscript><link rel=\"stylesheet\" href=\"{static_root_path}noscript{suffix}.css\"></noscript>\
63 <style type=\"text/css\">\
64 #crate-search{{background-image:url(\"{static_root_path}down-arrow{suffix}.svg\");}}\
67 <body class=\"rustdoc {css_class}\">\
69 <div class=\"warning\">\
70 This old browser is unsupported and will most likely display funky \
75 <nav class=\"sidebar\">\
76 <div class=\"sidebar-menu\">☰</div>\
80 <div class=\"theme-picker\">\
81 <button id=\"theme-picker\" aria-label=\"Pick another theme!\">\
82 <img src=\"{static_root_path}brush{suffix}.svg\" \
84 alt=\"Pick another theme!\">\
86 <div id=\"theme-choices\"></div>\
88 <script src=\"{static_root_path}theme{suffix}.js\"></script>\
90 <form class=\"search-form\">\
91 <div class=\"search-container\">\
93 <input class=\"search-input\" name=\"search\" \
95 autocomplete=\"off\" \
96 spellcheck=\"false\" \
97 placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \
100 <a id=\"settings-menu\" href=\"{root_path}settings.html\">\
101 <img src=\"{static_root_path}wheel{suffix}.svg\" \
103 alt=\"Change settings\">\
108 <section id=\"main\" class=\"content\">{content}</section>\
109 <section id=\"search\" class=\"content hidden\"></section>\
110 <section class=\"footer\"></section>\
113 window.rootPath = \"{root_path}\";\
114 window.currentCrate = \"{krate}\";\
116 <script src=\"{root_path}aliases{suffix}.js\"></script>\
117 <script src=\"{static_root_path}main{suffix}.js\"></script>\
118 {static_extra_scripts}\
120 <script defer src=\"{root_path}search-index{suffix}.js\"></script>\
123 css_extension
= if layout
.css_file_extension
.is_some() {
124 format
!("<link rel=\"stylesheet\" \
126 href=\"{static_root_path}theme{suffix}.css\">",
127 static_root_path
= static_root_path
,
128 suffix
=page
.resource_suffix
)
132 content
= Buffer
::html().to_display(t
),
133 static_root_path
= static_root_path
,
134 root_path
= page
.root_path
,
135 css_class
= page
.css_class
,
137 let p
= format
!("{}{}", page
.root_path
, layout
.krate
);
138 let p
= ensure_trailing_slash(&p
);
139 if layout
.logo
.is_empty() {
140 format
!("<a href='{path}index.html'>\
141 <div class='logo-container'>\
142 <img src='{static_root_path}rust-logo{suffix}.png' alt='logo'></div></a>",
144 static_root_path
=static_root_path
,
145 suffix
=page
.resource_suffix
)
147 format
!("<a href='{}index.html'>\
148 <div class='logo-container'><img src='{}' alt='logo'></div></a>",
154 description
= page
.description
,
155 keywords
= page
.keywords
,
156 favicon
= if layout
.favicon
.is_empty() {
157 format
!(r
#"<link rel="shortcut icon" href="{static_root_path}favicon{suffix}.ico">"#,
158 static_root_path
=static_root_path
,
159 suffix
=page
.resource_suffix
)
161 format
!(r
#"<link rel="shortcut icon" href="{}">"#, layout.favicon)
163 in_header
= layout
.external_html
.in_header
,
164 before_content
= layout
.external_html
.before_content
,
165 after_content
= layout
.external_html
.after_content
,
166 sidebar
= Buffer
::html().to_display(sidebar
),
167 krate
= layout
.krate
,
168 themes
= themes
.iter()
169 .filter_map(|t
| t
.file_stem())
170 .filter_map(|t
| t
.to_str())
171 .map(|t
| format
!(r
#"<link rel="stylesheet" type="text/css" href="{}.css">"#,
172 Escape(&format
!("{}{}{}",
175 page
.resource_suffix
))))
176 .collect
::<String
>(),
177 suffix
=page
.resource_suffix
,
178 static_extra_scripts
=page
.static_extra_scripts
.iter().map(|e
| {
179 format
!("<script src=\"{static_root_path}{extra_script}.js\"></script>",
180 static_root_path
=static_root_path
,
182 }).collect
::<String
>(),
183 extra_scripts
=page
.extra_scripts
.iter().map(|e
| {
184 format
!("<script src=\"{root_path}{extra_script}.js\"></script>",
185 root_path
=page
.root_path
,
187 }).collect
::<String
>(),
188 filter_crates
=if layout
.generate_search_filter
{
189 "<select id=\"crate-search\">\
190 <option value=\"All crates\">All crates</option>\
198 pub fn redirect(url
: &str) -> String
{
199 // <script> triggers a redirect before refresh, so this is fine.
204 <meta http-equiv="refresh" content="0;URL={url}">
207 <p>Redirecting to <a href="{url}">{url}</a>...</p>
208 <script>location.replace("{url}" + location.search + location.hash);</script>