This commit is contained in:
Maverick Liu 2025-02-23 15:16:37 +08:00
parent 24a373c45a
commit f8189b5d6d
4 changed files with 8 additions and 11 deletions

2
Cargo.lock generated
View file

@ -192,7 +192,7 @@ dependencies = [
[[package]] [[package]]
name = "epub2mdbook" name = "epub2mdbook"
version = "0.9.0" version = "0.10.0"
dependencies = [ dependencies = [
"clap", "clap",
"epub", "epub",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "epub2mdbook" name = "epub2mdbook"
version = "0.9.0" version = "0.10.0"
edition = "2024" edition = "2024"
description = "A tool to convert EPUB files to MDBook format" description = "A tool to convert EPUB files to MDBook format"
authors = ["Maverick Liu <maverick.liu42@gmail.com>"] authors = ["Maverick Liu <maverick.liu42@gmail.com>"]

View file

@ -16,8 +16,5 @@ epub2mdbook --input-epub path/to/input.epub --output-dir path/to/output
```rust ```rust
use epub2mdbook::convert_epub_to_mdbook; use epub2mdbook::convert_epub_to_mdbook;
convert_epub_to_mdbook( convert_epub_to_mdbook("path/to/input.epub", Some("path/to/output"));
PathBuf::from("path/to/input.epub"),
Some(PathBuf::from("path/to/output")),
);
``` ```

View file

@ -25,8 +25,8 @@ pub fn convert_epub_to_mdbook(
if !epub_path.is_file() { if !epub_path.is_file() {
return Err(Error::NotAFile(epub_path.display().to_string())); return Err(Error::NotAFile(epub_path.display().to_string()));
} }
let book_name = epub_path.with_extension(""); let book_name = epub_path
let book_name = book_name .with_extension("")
.file_name() .file_name()
.expect("unreachable") .expect("unreachable")
.to_string_lossy() .to_string_lossy()
@ -78,7 +78,7 @@ fn epub_nav_to_md(
/// ///
/// # Arguments /// # Arguments
/// ///
/// * `doc` - The EPUB document /// * `epub_doc` - The EPUB document
/// * `title` - The title of the book /// * `title` - The title of the book
/// ///
/// # Returns /// # Returns
@ -189,11 +189,11 @@ fn write_book_toml(
creator: Option<String>, creator: Option<String>,
) -> io::Result<()> { ) -> io::Result<()> {
let output_dir = output_dir.as_ref(); let output_dir = output_dir.as_ref();
let creator = match creator { let author = match creator {
Some(creator) => format!("author = \"{creator}\"\n"), Some(creator) => format!("author = \"{creator}\"\n"),
None => "".to_string(), None => "".to_string(),
}; };
let toml_content = format!("[book]\ntitle = \"{title}\"\n{creator}",); let toml_content = format!("[book]\ntitle = \"{title}\"\n{author}",);
fs::write(output_dir.join("book.toml"), toml_content)?; fs::write(output_dir.join("book.toml"), toml_content)?;
Ok(()) Ok(())
} }