diff --git a/src/epub.rs b/src/epub.rs index 5e5d377..6c2d5f3 100644 --- a/src/epub.rs +++ b/src/epub.rs @@ -71,7 +71,7 @@ pub fn generate_epubs( let section_name = article.metadata().title(); let content_url = format!("article_{}.xhtml", idx); let mut content = EpubContent::new(&content_url, xhtml_str.as_bytes()) - .title(replace_metadata_value(section_name)); + .title(replace_escaped_characters(section_name)); let header_level_tocs = get_header_level_toc_vec(&content_url, article.article()); @@ -79,7 +79,7 @@ pub fn generate_epubs( content = content.child(toc_element); } - epub.metadata("title", replace_metadata_value(name))?; + epub.metadata("title", replace_escaped_characters(name))?; epub.add_content(content)?; info!("Adding images for {:?}", name); article.img_urls.iter().for_each(|img| { @@ -109,7 +109,7 @@ pub fn generate_epubs( let appendix = generate_appendix(articles.iter().collect()); if let Err(err) = epub.add_content( EpubContent::new("appendix.xhtml", appendix.as_bytes()) - .title(replace_metadata_value("Article Sources")), + .title(replace_escaped_characters("Article Sources")), ) { let mut paperoni_err: PaperoniError = err.into(); paperoni_err.set_article_source(name); @@ -161,9 +161,9 @@ pub fn generate_epubs( get_header_level_toc_vec("index.xhtml", article.article()); if let Some(author) = article.metadata().byline() { - epub.metadata("author", replace_metadata_value(author))?; + epub.metadata("author", replace_escaped_characters(author))?; } - let title = replace_metadata_value(article.metadata().title()); + let title = replace_escaped_characters(article.metadata().title()); epub.metadata("title", &title)?; let mut content = @@ -189,7 +189,7 @@ pub fn generate_epubs( let appendix = generate_appendix(vec![&article]); epub.add_content( EpubContent::new("appendix.xhtml", appendix.as_bytes()) - .title(replace_metadata_value("Article Source")), + .title(replace_escaped_characters("Article Source")), )?; epub.generate(&mut out_file)?; bar.inc(1); @@ -216,7 +216,7 @@ pub fn generate_epubs( } /// Replaces characters that have to be escaped before adding to the epub's metadata -fn replace_metadata_value(value: &str) -> String { +fn replace_escaped_characters(value: &str) -> String { value .replace("&", "&") .replace("<", "<") @@ -235,8 +235,8 @@ fn generate_appendix(articles: Vec<&Extractor>) -> String { }; format!( "{}

", - replace_metadata_value(&article.url), - replace_metadata_value(article_name) + replace_escaped_characters(&article.url), + replace_escaped_characters(article_name) ) }) .collect(); @@ -300,20 +300,22 @@ fn get_header_level_toc_vec(content_url: &str, article: &NodeRef) -> Vec