]>
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
::render
::ensure_trailing_slash
;
5 use crate::html
::format
::{Buffer, Print}
;
11 pub external_html
: ExternalHtml
,
13 /// The given user css file which allow to customize the generated
14 /// documentation theme.
15 pub css_file_extension
: Option
<PathBuf
>,
16 /// If false, the `select` element to have search filtering by crates on rendered docs
17 /// won't be generated.
18 pub generate_search_filter
: bool
,
23 pub css_class
: &'a
str,
24 pub root_path
: &'a
str,
25 pub static_root_path
: Option
<&'a
str>,
26 pub description
: &'a
str,
27 pub keywords
: &'a
str,
28 pub resource_suffix
: &'a
str,
29 pub extra_scripts
: &'a
[&'a
str],
30 pub static_extra_scripts
: &'a
[&'a
str],
33 pub fn render
<T
: Print
, S
: Print
>(
40 let static_root_path
= page
.static_root_path
.unwrap_or(page
.root_path
);
41 format
!("<!DOCTYPE html>\
44 <meta charset=\"utf-8\">\
45 <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
46 <meta name=\"generator\" content=\"rustdoc\">\
47 <meta name=\"description\" content=\"{description}\">\
48 <meta name=\"keywords\" content=\"{keywords}\">\
49 <title>{title}</title>\
50 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}normalize{suffix}.css\">\
51 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}rustdoc{suffix}.css\" \
52 id=\"mainThemeStyle\">\
54 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}dark{suffix}.css\">\
55 <link rel=\"stylesheet\" type=\"text/css\" href=\"{static_root_path}light{suffix}.css\" \
57 <script src=\"{static_root_path}storage{suffix}.js\"></script>\
58 <noscript><link rel=\"stylesheet\" href=\"{static_root_path}noscript{suffix}.css\"></noscript>\
62 <style type=\"text/css\">\
63 #crate-search{{background-image:url(\"{static_root_path}down-arrow{suffix}.svg\");}}\
66 <body class=\"rustdoc {css_class}\">\
68 <div class=\"warning\">\
69 This old browser is unsupported and will most likely display funky \
74 <nav class=\"sidebar\">\
75 <div class=\"sidebar-menu\">☰</div>\
79 <div class=\"theme-picker\">\
80 <button id=\"theme-picker\" aria-label=\"Pick another theme!\">\
81 <img src=\"{static_root_path}brush{suffix}.svg\" \
83 alt=\"Pick another theme!\">\
85 <div id=\"theme-choices\"></div>\
87 <script src=\"{static_root_path}theme{suffix}.js\"></script>\
89 <form class=\"search-form js-only\">\
90 <div class=\"search-container\">\
92 <input class=\"search-input\" name=\"search\" \
93 autocomplete=\"off\" \
94 spellcheck=\"false\" \
95 placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \
98 <a id=\"settings-menu\" href=\"{root_path}settings.html\">\
99 <img src=\"{static_root_path}wheel{suffix}.svg\" \
101 alt=\"Change settings\">\
106 <section id=\"main\" class=\"content\">{content}</section>\
107 <section id=\"search\" class=\"content hidden\"></section>\
108 <section class=\"footer\"></section>\
111 window.rootPath = \"{root_path}\";\
112 window.currentCrate = \"{krate}\";\
114 <script src=\"{root_path}aliases{suffix}.js\"></script>\
115 <script src=\"{static_root_path}main{suffix}.js\"></script>\
116 {static_extra_scripts}\
118 <script defer src=\"{root_path}search-index{suffix}.js\"></script>\
121 css_extension
= if layout
.css_file_extension
.is_some() {
122 format
!("<link rel=\"stylesheet\" \
124 href=\"{static_root_path}theme{suffix}.css\">",
125 static_root_path
= static_root_path
,
126 suffix
=page
.resource_suffix
)
130 content
= Buffer
::html().to_display(t
),
131 static_root_path
= static_root_path
,
132 root_path
= page
.root_path
,
133 css_class
= page
.css_class
,
135 let p
= format
!("{}{}", page
.root_path
, layout
.krate
);
136 let p
= ensure_trailing_slash(&p
);
137 if layout
.logo
.is_empty() {
138 format
!("<a href='{path}index.html'>\
139 <div class='logo-container'>\
140 <img src='{static_root_path}rust-logo{suffix}.png' alt='logo'></div></a>",
142 static_root_path
=static_root_path
,
143 suffix
=page
.resource_suffix
)
145 format
!("<a href='{}index.html'>\
146 <div class='logo-container'><img src='{}' alt='logo'></div></a>",
152 description
= page
.description
,
153 keywords
= page
.keywords
,
154 favicon
= if layout
.favicon
.is_empty() {
155 format
!(r
#"<link rel="shortcut icon" href="{static_root_path}favicon{suffix}.ico">"#,
156 static_root_path
=static_root_path
,
157 suffix
=page
.resource_suffix
)
159 format
!(r
#"<link rel="shortcut icon" href="{}">"#, layout.favicon)
161 in_header
= layout
.external_html
.in_header
,
162 before_content
= layout
.external_html
.before_content
,
163 after_content
= layout
.external_html
.after_content
,
164 sidebar
= Buffer
::html().to_display(sidebar
),
165 krate
= layout
.krate
,
166 themes
= themes
.iter()
167 .filter_map(|t
| t
.file_stem())
168 .filter_map(|t
| t
.to_str())
169 .map(|t
| format
!(r
#"<link rel="stylesheet" type="text/css" href="{}{}{}.css">"#,
172 page
.resource_suffix
))
173 .collect
::<String
>(),
174 suffix
=page
.resource_suffix
,
175 static_extra_scripts
=page
.static_extra_scripts
.iter().map(|e
| {
176 format
!("<script src=\"{static_root_path}{extra_script}.js\"></script>",
177 static_root_path
=static_root_path
,
179 }).collect
::<String
>(),
180 extra_scripts
=page
.extra_scripts
.iter().map(|e
| {
181 format
!("<script src=\"{root_path}{extra_script}.js\"></script>",
182 root_path
=page
.root_path
,
184 }).collect
::<String
>(),
185 filter_crates
=if layout
.generate_search_filter
{
186 "<select id=\"crate-search\">\
187 <option value=\"All crates\">All crates</option>\
195 pub fn redirect(url
: &str) -> String
{
196 // <script> triggers a redirect before refresh, so this is fine.
201 <meta http-equiv="refresh" content="0;URL={url}">
204 <p>Redirecting to <a href="{url}">{url}</a>...</p>
205 <script>location.replace("{url}" + location.search + location.hash);</script>