about summary refs log tree commit diff
path: root/src/librustdoc/html/layout.rs
diff options
context:
space:
mode:
authorJacob Hoffman-Andrews <github@hoffman-andrews.com>2022-10-24 01:28:55 -0700
committerJacob Hoffman-Andrews <github@hoffman-andrews.com>2022-10-29 12:47:48 -0700
commitf9e1f6ffdf03ec33cb29e20c88fc7bcc938c7f42 (patch)
tree0149d623019575412f9da7350c3d4d7c7312f1b6 /src/librustdoc/html/layout.rs
parent68c836a904e5a421712db311421c5266f9ce71c0 (diff)
downloadrust-f9e1f6ffdf03ec33cb29e20c88fc7bcc938c7f42.tar.gz
rust-f9e1f6ffdf03ec33cb29e20c88fc7bcc938c7f42.zip
rustdoc: add hash to filename of toolchain files
All static files used by rustdoc are now stored in static.files/ and
include a hash of their contents. They no longer include the contents of
the --resource-suffix flag. This clarifies caching semantics. Anything
in static.files can use Cache-Control: immutable because any updates
will show up as a new URL.

Invocation-specific files like crates-NN.js, search-index-NN.js,
and sidebar-items-NN.js still get the resource suffix.

The --disable-minification flag is removed because it would vary the
output of static files based on invocation flags. Instead, for
rustdoc development purposes it's preferable to symlink static files
to a non-minified copy for quick iteration.
Diffstat (limited to 'src/librustdoc/html/layout.rs')
-rw-r--r--src/librustdoc/html/layout.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs
index 7d6d4b71e2e..087e9219b67 100644
--- a/src/librustdoc/html/layout.rs
+++ b/src/librustdoc/html/layout.rs
@@ -2,13 +2,14 @@ use std::path::PathBuf;
 
 use rustc_data_structures::fx::FxHashMap;
 
-use crate::error::Error;
 use crate::externalfiles::ExternalHtml;
 use crate::html::format::{Buffer, Print};
 use crate::html::render::{ensure_trailing_slash, StylePath};
 
 use askama::Template;
 
+use super::static_files::{StaticFiles, STATIC_FILES};
+
 #[derive(Clone)]
 pub(crate) struct Layout {
     pub(crate) logo: String,
@@ -45,6 +46,9 @@ struct PageLayout<'a> {
     static_root_path: &'a str,
     page: &'a Page<'a>,
     layout: &'a Layout,
+
+    files: &'static StaticFiles,
+
     themes: Vec<String>,
     sidebar: String,
     content: String,
@@ -61,12 +65,9 @@ pub(crate) fn render<T: Print, S: Print>(
 ) -> String {
     let static_root_path = page.get_static_root_path();
     let krate_with_trailing_slash = ensure_trailing_slash(&layout.krate).to_string();
-    let mut themes: Vec<String> = style_files
-        .iter()
-        .map(StylePath::basename)
-        .collect::<Result<_, Error>>()
-        .unwrap_or_default();
+    let mut themes: Vec<String> = style_files.iter().map(|s| s.basename().unwrap()).collect();
     themes.sort();
+
     let rustdoc_version = rustc_interface::util::version_str().unwrap_or("unknown version");
     let content = Buffer::html().to_display(t); // Note: This must happen before making the sidebar.
     let sidebar = Buffer::html().to_display(sidebar);
@@ -74,6 +75,7 @@ pub(crate) fn render<T: Print, S: Print>(
         static_root_path,
         page,
         layout,
+        files: &STATIC_FILES,
         themes,
         sidebar,
         content,