Skip to content

Commit 9242423

Browse files
steveklabnikMichael-F-Bryan
authored andcommitted
Handle input path with regards to custom css (rust-lang#598)
* Handle input path with regards to custom css Before, when someone like the Reference set their extra css as "theme/reference.css" in their book.toml, this path would be treated as relative to the invocation of mdbook, and not respect the input path. This PR modifies these relative paths to do so. Fixes the build of rust-lang/rust#47753 which blocks updating rustc to mdbook 0.1 * don't use file-name the style name is theme/reference.css, this results in a Err(StripPrefixError(())), which means that we push only the file_name, losing the theme bit
1 parent 8840f6a commit 9242423

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,27 +238,28 @@ impl HtmlHandlebars {
238238

239239
/// Copy across any additional CSS and JavaScript files which the book
240240
/// has been configured to use.
241-
fn copy_additional_css_and_js(&self, html: &HtmlConfig, destination: &Path) -> Result<()> {
241+
fn copy_additional_css_and_js(&self, html: &HtmlConfig, root: &Path, destination: &Path) -> Result<()> {
242242
let custom_files = html.additional_css.iter().chain(html.additional_js.iter());
243243

244244
debug!("Copying additional CSS and JS");
245245

246246
for custom_file in custom_files {
247+
let input_location = root.join(custom_file);
247248
let output_location = destination.join(custom_file);
248249
if let Some(parent) = output_location.parent() {
249250
fs::create_dir_all(parent)
250251
.chain_err(|| format!("Unable to create {}", parent.display()))?;
251252
}
252253
debug!(
253254
"Copying {} -> {}",
254-
custom_file.display(),
255+
input_location.display(),
255256
output_location.display()
256257
);
257258

258-
fs::copy(custom_file, &output_location).chain_err(|| {
259+
fs::copy(&input_location, &output_location).chain_err(|| {
259260
format!(
260261
"Unable to copy {} to {}",
261-
custom_file.display(),
262+
input_location.display(),
262263
output_location.display()
263264
)
264265
})?;
@@ -338,7 +339,7 @@ impl Renderer for HtmlHandlebars {
338339
debug!("Copy static files");
339340
self.copy_static_files(&destination, &theme, &html_config)
340341
.chain_err(|| "Unable to copy across static files")?;
341-
self.copy_additional_css_and_js(&html_config, &destination)
342+
self.copy_additional_css_and_js(&html_config, &ctx.root, &destination)
342343
.chain_err(|| "Unable to copy across additional CSS and JS")?;
343344

344345
// Copy all remaining files
@@ -375,11 +376,11 @@ fn make_data(root: &Path, book: &Book, config: &Config, html_config: &HtmlConfig
375376
let mut css = Vec::new();
376377
for style in &html.additional_css {
377378
match style.strip_prefix(root) {
378-
Ok(p) => css.push(p.to_str().expect("Could not convert to str")),
379+
Ok(p) => {
380+
css.push(p.to_str().expect("Could not convert to str"))
381+
},
379382
Err(_) => {
380-
css.push(style.file_name()
381-
.expect("File has a file name")
382-
.to_str()
383+
css.push(style.to_str()
383384
.expect("Could not convert to str"))
384385
}
385386
}

0 commit comments

Comments
 (0)