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};
13 pub(crate) struct Layout {
14 pub(crate) logo: String,
15 pub(crate) favicon: String,
16 pub(crate) external_html: ExternalHtml,
17 pub(crate) default_settings: FxHashMap<String, String>,
18 pub(crate) krate: String,
19 /// The given user css file which allow to customize the generated
20 /// documentation theme.
21 pub(crate) css_file_extension: Option<PathBuf>,
22 /// If true, then scrape-examples.js will be included in the output HTML file
23 pub(crate) scrape_examples_extension: bool,
26 pub(crate) struct Page<'a> {
27 pub(crate) title: &'a str,
28 pub(crate) css_class: &'a str,
29 pub(crate) root_path: &'a str,
30 pub(crate) static_root_path: Option<&'a str>,
31 pub(crate) description: &'a str,
32 pub(crate) keywords: &'a str,
33 pub(crate) resource_suffix: &'a str,
37 pub(crate) fn get_static_root_path(&self) -> &str {
38 self.static_root_path.unwrap_or(self.root_path)
43 #[template(path = "page.html")]
44 struct PageLayout<'a> {
45 static_root_path: &'a str,
51 krate_with_trailing_slash: String,
52 pub(crate) rustdoc_version: &'a str,
55 pub(crate) fn render<T: Print, S: Print>(
60 style_files: &[StylePath],
62 let static_root_path = page.get_static_root_path();
63 let krate_with_trailing_slash = ensure_trailing_slash(&layout.krate).to_string();
64 let mut themes: Vec<String> = style_files
66 .map(StylePath::basename)
67 .collect::<Result<_, Error>>()
70 let rustdoc_version = rustc_interface::util::version_str().unwrap_or("unknown version");
71 let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar.
72 let sidebar = Buffer::html().to_display(sidebar);
80 krate_with_trailing_slash,
87 pub(crate) fn redirect(url: &str) -> String {
88 // <script> triggers a redirect before refresh, so this is fine.
93 <meta http-equiv="refresh" content="0;URL={url}">
94 <title>Redirection</title>
97 <p>Redirecting to <a href="{url}">{url}</a>...</p>
98 <script>location.replace("{url}" + location.search + location.hash);</script>