Skip to content

Commit 071182b

Browse files
committed
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
1 parent 674e58e commit 071182b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

+6-5
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

0 commit comments

Comments
 (0)