about summary refs log tree commit diff
path: root/src/librustdoc/html/static/js/storage.js
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/static/js/storage.js
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/static/js/storage.js')
-rw-r--r--src/librustdoc/html/static/js/storage.js24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js
index b462a2c50f1..db2db83ca63 100644
--- a/src/librustdoc/html/static/js/storage.js
+++ b/src/librustdoc/html/static/js/storage.js
@@ -126,33 +126,29 @@ function getCurrentValue(name) {
     }
 }
 
-function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
-    const newHref = mainStyleElem.href.replace(
-        /\/rustdoc([^/]*)\.css/, "/" + newTheme + "$1" + ".css");
-
+function switchTheme(styleElem, mainStyleElem, newThemeName, saveTheme) {
     // If this new value comes from a system setting or from the previously
     // saved theme, no need to save it.
     if (saveTheme) {
-        updateLocalStorage("theme", newTheme);
-    }
-
-    if (styleElem.href === newHref) {
-        return;
+        updateLocalStorage("theme", newThemeName);
     }
 
-    let found = false;
     if (savedHref.length === 0) {
         onEachLazy(document.getElementsByTagName("link"), el => {
             savedHref.push(el.href);
         });
     }
-    onEach(savedHref, el => {
-        if (el === newHref) {
-            found = true;
+    const newHref = savedHref.find(url => {
+        const m = url.match(/static\.files\/(.*)-[a-f0-9]{16}\.css$/);
+        if (m && m[1] === newThemeName) {
+            return true;
+        }
+        const m2 = url.match(/\/([^/]*)\.css$/);
+        if (m2 && m2[1].startsWith(newThemeName)) {
             return true;
         }
     });
-    if (found) {
+    if (newHref && newHref !== styleElem.href) {
         styleElem.href = newHref;
     }
 }