fix issues from code review
This commit is contained in:
parent
d605938886
commit
43008ef2ef
|
@ -237,14 +237,15 @@ fn load_summary_item<P: AsRef<Path> + Clone>(
|
|||
}
|
||||
}
|
||||
|
||||
fn load_chapter<P: AsRef<Path> + Clone>(
|
||||
fn load_chapter<P: AsRef<Path>>(
|
||||
link: &Link,
|
||||
src_dir: P,
|
||||
parent_names: Vec<String>,
|
||||
) -> Result<Chapter> {
|
||||
let src_dir = src_dir.as_ref();
|
||||
|
||||
let mut ch = if let Some(ref link_location) = link.location {
|
||||
debug!("Loading {} ({})", link.name, link_location.display());
|
||||
let src_dir = src_dir.as_ref();
|
||||
|
||||
let location = if link_location.is_absolute() {
|
||||
link_location.clone()
|
||||
|
@ -276,7 +277,7 @@ fn load_chapter<P: AsRef<Path> + Clone>(
|
|||
let sub_items = link
|
||||
.nested_items
|
||||
.iter()
|
||||
.map(|i| load_summary_item(i, src_dir.clone(), sub_item_parents.clone()))
|
||||
.map(|i| load_summary_item(i, src_dir, sub_item_parents.clone()))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
ch.sub_items = sub_items;
|
||||
|
|
|
@ -251,8 +251,11 @@ impl MDBook {
|
|||
|
||||
for item in book.iter() {
|
||||
if let BookItem::Chapter(ref ch) = *item {
|
||||
if let Some(ref chapter_path) = ch.path {
|
||||
if !chapter_path.as_os_str().is_empty() {
|
||||
let chapter_path = match ch.path {
|
||||
Some(ref path) if !path.as_os_str().is_empty() => path,
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
let path = self.source_dir().join(&chapter_path);
|
||||
info!("Testing file: {:?}", path);
|
||||
|
||||
|
@ -285,8 +288,6 @@ impl MDBook {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,12 @@ impl HtmlHandlebars {
|
|||
print_content: &mut String,
|
||||
) -> Result<()> {
|
||||
// FIXME: This should be made DRY-er and rely less on mutable state
|
||||
if let BookItem::Chapter(ref ch) = *item {
|
||||
if let Some(ref path) = ch.path {
|
||||
|
||||
let (ch, path) = match item {
|
||||
BookItem::Chapter(ch) if !ch.is_draft_chapter() => (ch, ch.path.as_ref().unwrap()),
|
||||
_ => return Ok(()),
|
||||
};
|
||||
|
||||
let content = ch.content.clone();
|
||||
let content = utils::render_markdown(&content, ctx.html_config.curly_quotes);
|
||||
|
||||
|
@ -99,13 +103,7 @@ impl HtmlHandlebars {
|
|||
let rendered_index =
|
||||
self.post_process(rendered_index, &ctx.html_config.playpen, ctx.edition);
|
||||
debug!("Creating index.html from {}", ctx_path);
|
||||
utils::fs::write_file(
|
||||
&ctx.destination,
|
||||
"index.html",
|
||||
rendered_index.as_bytes(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
utils::fs::write_file(&ctx.destination, "index.html", rendered_index.as_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -71,13 +71,7 @@ fn render_item(
|
|||
item: &BookItem,
|
||||
) -> Result<()> {
|
||||
let chapter = match *item {
|
||||
BookItem::Chapter(ref ch) => {
|
||||
if let Some(_) = ch.path {
|
||||
ch
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
BookItem::Chapter(ref ch) if !ch.is_draft_chapter() => ch,
|
||||
_ => return Ok(()),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue