1 use std::path::PathBuf;
3 use rustc_data_structures::fx::FxHashMap;
5 use crate::error::Error;
6 use crate::externalfiles::ExternalHtml;
7 use crate::html::format::{Buffer, Print};
8 use crate::html::render::{ensure_trailing_slash, StylePath};
12 #[derive(Clone, Serialize)]
15 crate favicon: String,
16 crate external_html: ExternalHtml,
17 crate default_settings: FxHashMap<String, String>,
19 /// The given user css file which allow to customize the generated
20 /// documentation theme.
21 crate css_file_extension: Option<PathBuf>,
22 /// If false, the `select` element to have search filtering by crates on rendered docs
23 /// won't be generated.
24 crate generate_search_filter: bool,
25 /// If true, then scrape-examples.js will be included in the output HTML file
26 crate scrape_examples_extension: bool,
30 crate struct Page<'a> {
32 crate css_class: &'a str,
33 crate root_path: &'a str,
34 crate static_root_path: Option<&'a str>,
35 crate description: &'a str,
36 crate keywords: &'a str,
37 crate resource_suffix: &'a str,
38 crate extra_scripts: &'a [&'a str],
39 crate static_extra_scripts: &'a [&'a str],
43 crate fn get_static_root_path(&self) -> &str {
44 self.static_root_path.unwrap_or(self.root_path)
49 struct PageLayout<'a> {
50 static_root_path: &'a str,
56 krate_with_trailing_slash: String,
57 crate rustdoc_version: &'a str,
60 crate fn render<T: Print, S: Print>(
61 templates: &tera::Tera,
66 style_files: &[StylePath],
68 let static_root_path = page.get_static_root_path();
69 let krate_with_trailing_slash = ensure_trailing_slash(&layout.krate).to_string();
70 let mut themes: Vec<String> = style_files
72 .map(StylePath::basename)
73 .collect::<Result<_, Error>>()
76 let rustdoc_version = rustc_interface::util::version_str().unwrap_or("unknown version");
77 let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar.
78 let sidebar = Buffer::html().to_display(sidebar);
79 let teractx = tera::Context::from_serialize(PageLayout {
86 krate_with_trailing_slash,
90 templates.render("page.html", &teractx).unwrap()
93 crate fn redirect(url: &str) -> String {
94 // <script> triggers a redirect before refresh, so this is fine.
99 <meta http-equiv="refresh" content="0;URL={url}">
100 <title>Redirection</title>
103 <p>Redirecting to <a href="{url}">{url}</a>...</p>
104 <script>location.replace("{url}" + location.search + location.hash);</script>