Make --static-root-path point to static.files

This commit is contained in:
Jacob Hoffman-Andrews 2022-09-28 23:52:00 -07:00
parent f9e1f6ffdf
commit bf25334066
6 changed files with 19 additions and 13 deletions

View file

@ -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,

View file

@ -636,7 +636,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
<link rel=\"stylesheet\" type=\"text/css\" \
href=\"{static_root_path}{settings_css}\">\
<script defer src=\"{static_root_path}{settings_js}\"></script>",
static_root_path = page.static_root_path.unwrap_or(""),
static_root_path = page.get_static_root_path(),
settings_css = static_files::STATIC_FILES.settings_css,
settings_js = static_files::STATIC_FILES.settings_js,
)

View file

@ -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(),

View file

@ -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
@ -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())?;
}
}

View file

@ -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 {
@ -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 {

View file

@ -1,18 +1,18 @@
// compile-flags:-Z unstable-options --static-root-path /cache/
// @has static_root_path/struct.SomeStruct.html
// @matchesraw - '"/cache/static.files/main-'
// @matchesraw - '"/cache/main-'
// @!matchesraw - '"\.\./main'
// @matchesraw - 'data-root-path="\.\./"'
// @!matchesraw - '"/cache/search-index\.js"'
pub struct SomeStruct;
// @has src/static_root_path/static-root-path.rs.html
// @matchesraw - '"/cache/static.files/source-script-'
// @matchesraw - '"/cache/source-script-'
// @!matchesraw - '"\.\./\.\./source-script'
// @matchesraw - '"\.\./\.\./source-files.js"'
// @!matchesraw - '"/cache/source-files\.js"'
// @has settings.html
// @matchesraw - '/cache/static.files/settings-'
// @matchesraw - '/cache/settings-'
// @!matchesraw - '\../settings'