Skip to content

Commit

Permalink
Handle input path with regards to custom css
Browse files Browse the repository at this point in the history
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
  • Loading branch information
steveklabnik committed Jan 28, 2018
1 parent 674e58e commit 071182b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,28 @@ impl HtmlHandlebars {

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

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

for custom_file in custom_files {
let input_location = root.join(custom_file);
let output_location = destination.join(custom_file);
if let Some(parent) = output_location.parent() {
fs::create_dir_all(parent)
.chain_err(|| format!("Unable to create {}", parent.display()))?;
}
debug!(
"Copying {} -> {}",
custom_file.display(),
input_location.display(),
output_location.display()
);

fs::copy(custom_file, &output_location).chain_err(|| {
fs::copy(&input_location, &output_location).chain_err(|| {
format!(
"Unable to copy {} to {}",
custom_file.display(),
input_location.display(),
output_location.display()
)
})?;
Expand Down Expand Up @@ -338,7 +339,7 @@ impl Renderer for HtmlHandlebars {
debug!("Copy static files");
self.copy_static_files(&destination, &theme, &html_config)
.chain_err(|| "Unable to copy across static files")?;
self.copy_additional_css_and_js(&html_config, &destination)
self.copy_additional_css_and_js(&html_config, &ctx.root, &destination)
.chain_err(|| "Unable to copy across additional CSS and JS")?;

// Copy all remaining files
Expand Down

0 comments on commit 071182b

Please sign in to comment.