From 5a3155aba73f4b6889cddecb6cfdc3e6da5c06e6 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Mon, 14 Sep 2015 17:45:30 +0200 Subject: [PATCH] Fix #50 base url sometimes not correct for index.html --- src/renderer/html_handlebars/hbs_renderer.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index deb4c556..e15689df 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -9,7 +9,7 @@ use book::bookitem::BookItem; use {utils, theme}; use std::path::{Path, PathBuf}; -use std::fs::{self, File}; +use std::fs::File; use std::error::Error; use std::io::{self, Read, Write}; use std::collections::BTreeMap; @@ -107,10 +107,17 @@ impl Renderer for HtmlHandlebars { // Create an index.html from the first element in SUMMARY.md if index { debug!("[*]: index.html"); - try!(fs::copy( - book.get_dest().join(&ch.path.with_extension("html")), - book.get_dest().join("index.html") - )); + + let mut index_file = try!(File::create(book.get_dest().join("index.html"))); + let mut content = String::new(); + let _source = try!(File::open(book.get_dest().join(&ch.path.with_extension("html")))) + .read_to_string(&mut content); + + // This could cause a problem when someone displays code containing + // on the front page, however this case should be very very rare... + content = content.lines().filter(|line| !line.contains("