Skip to content

Commit

Permalink
Make --static-root-path point to static.files
Browse files Browse the repository at this point in the history
  • Loading branch information
jsha committed Sep 29, 2022
1 parent edfb74e commit ea51f8a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ pub(crate) struct Page<'a> {
}

impl<'a> Page<'a> {
pub(crate) fn get_static_root_path(&self) -> &str {
self.static_root_path.unwrap_or(self.root_path)
pub(crate) fn get_static_root_path(&self) -> String {
match self.static_root_path {
Some(s) => s.to_string(),
None => format!("{}{}", self.root_path, "static.files/"),
}
}
}

#[derive(Template)]
#[template(path = "page.html")]
struct PageLayout<'a> {
static_root_path: &'a str,
static_root_path: String,
page: &'a Page<'a>,
layout: &'a Layout,

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub(super) fn print_item(
};

let item_vars = ItemVars {
static_root_path: page.get_static_root_path(),
static_root_path: &page.get_static_root_path(),
clipboard_svg: &static_files::STATIC_FILES.clipboard_svg,
typ,
name: item.name.as_ref().unwrap().as_str(),
Expand Down
9 changes: 6 additions & 3 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use crate::{try_err, try_none};
/// URL if the contents change, so they are safe to cache with the
/// `Cache-Control: immutable` directive. They are written under the static.files/
/// directory and are written when --emit-type is empty (default) or contains
/// "toolchain-specific".
/// "toolchain-specific". If using the --static-root-path flag, it should point
/// to a URL path prefix where each of these filenames can be fetched.
/// - Invocation specific files. These are generated based on the crate(s) being
/// documented. Their filenames need to be predictable without knowing their
/// contents, so they do not include a hash in their filename and are not safe to
Expand Down Expand Up @@ -85,8 +86,10 @@ pub(super) fn write_shared(

if options.emit.is_empty() || options.emit.contains(&EmitType::Toolchain) {
for f in &static_files::STATIC_FILES_LIST {
let filename = static_files::static_filename(f.filename, f.bytes);
cx.shared.fs.write(cx.dst.join(filename), f.minified())?;
let filename = cx.dst.join(
Path::new("static.files/").join(static_files::static_filename(f.filename, f.bytes)),
);
cx.shared.fs.write(filename, f.minified())?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use rustc_data_structures::fx::FxHasher;
use std::hash::Hasher;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::{fmt, str};

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

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

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

0 comments on commit ea51f8a

Please sign in to comment.