Skip to content

Commit ea51f8a

Browse files
committed
Make --static-root-path point to static.files
1 parent edfb74e commit ea51f8a

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/librustdoc/html/layout.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ pub(crate) struct Page<'a> {
3535
}
3636

3737
impl<'a> Page<'a> {
38-
pub(crate) fn get_static_root_path(&self) -> &str {
39-
self.static_root_path.unwrap_or(self.root_path)
38+
pub(crate) fn get_static_root_path(&self) -> String {
39+
match self.static_root_path {
40+
Some(s) => s.to_string(),
41+
None => format!("{}{}", self.root_path, "static.files/"),
42+
}
4043
}
4144
}
4245

4346
#[derive(Template)]
4447
#[template(path = "page.html")]
4548
struct PageLayout<'a> {
46-
static_root_path: &'a str,
49+
static_root_path: String,
4750
page: &'a Page<'a>,
4851
layout: &'a Layout,
4952

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub(super) fn print_item(
147147
};
148148

149149
let item_vars = ItemVars {
150-
static_root_path: page.get_static_root_path(),
150+
static_root_path: &page.get_static_root_path(),
151151
clipboard_svg: &static_files::STATIC_FILES.clipboard_svg,
152152
typ,
153153
name: item.name.as_ref().unwrap().as_str(),

src/librustdoc/html/render/write_shared.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use crate::{try_err, try_none};
2424
/// URL if the contents change, so they are safe to cache with the
2525
/// `Cache-Control: immutable` directive. They are written under the static.files/
2626
/// directory and are written when --emit-type is empty (default) or contains
27-
/// "toolchain-specific".
27+
/// "toolchain-specific". If using the --static-root-path flag, it should point
28+
/// to a URL path prefix where each of these filenames can be fetched.
2829
/// - Invocation specific files. These are generated based on the crate(s) being
2930
/// documented. Their filenames need to be predictable without knowing their
3031
/// contents, so they do not include a hash in their filename and are not safe to
@@ -85,8 +86,10 @@ pub(super) fn write_shared(
8586

8687
if options.emit.is_empty() || options.emit.contains(&EmitType::Toolchain) {
8788
for f in &static_files::STATIC_FILES_LIST {
88-
let filename = static_files::static_filename(f.filename, f.bytes);
89-
cx.shared.fs.write(cx.dst.join(filename), f.minified())?;
89+
let filename = cx.dst.join(
90+
Path::new("static.files/").join(static_files::static_filename(f.filename, f.bytes)),
91+
);
92+
cx.shared.fs.write(filename, f.minified())?;
9093
}
9194
}
9295

src/librustdoc/html/static_files.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use rustc_data_structures::fx::FxHasher;
77
use std::hash::Hasher;
8-
use std::path::{Path, PathBuf};
8+
use std::path::PathBuf;
99
use std::{fmt, str};
1010

1111
pub(crate) struct StaticFile {
@@ -51,7 +51,7 @@ pub(crate) fn suffix_path(filename: &str, suffix: &str) -> PathBuf {
5151

5252
pub(crate) fn static_filename(filename: &str, contents: &[u8]) -> PathBuf {
5353
let filename = filename.rsplit("/").next().unwrap();
54-
Path::new("static.files").join(suffix_path(filename, &static_suffix(contents)))
54+
suffix_path(filename, &static_suffix(contents))
5555
}
5656

5757
fn static_suffix(bytes: &[u8]) -> String {

0 commit comments

Comments
 (0)