mirror of
https://github.com/cyborg42/epub2mdbook.git
synced 2026-02-10 16:24:50 -05:00
refactor
This commit is contained in:
parent
24a373c45a
commit
f8189b5d6d
4 changed files with 8 additions and 11 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -192,7 +192,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "epub2mdbook"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"epub",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "epub2mdbook"
|
||||
version = "0.9.0"
|
||||
version = "0.10.0"
|
||||
edition = "2024"
|
||||
description = "A tool to convert EPUB files to MDBook format"
|
||||
authors = ["Maverick Liu <maverick.liu42@gmail.com>"]
|
||||
|
|
|
|||
|
|
@ -16,8 +16,5 @@ epub2mdbook --input-epub path/to/input.epub --output-dir path/to/output
|
|||
```rust
|
||||
use epub2mdbook::convert_epub_to_mdbook;
|
||||
|
||||
convert_epub_to_mdbook(
|
||||
PathBuf::from("path/to/input.epub"),
|
||||
Some(PathBuf::from("path/to/output")),
|
||||
);
|
||||
convert_epub_to_mdbook("path/to/input.epub", Some("path/to/output"));
|
||||
```
|
||||
|
|
|
|||
10
src/lib.rs
10
src/lib.rs
|
|
@ -25,8 +25,8 @@ pub fn convert_epub_to_mdbook(
|
|||
if !epub_path.is_file() {
|
||||
return Err(Error::NotAFile(epub_path.display().to_string()));
|
||||
}
|
||||
let book_name = epub_path.with_extension("");
|
||||
let book_name = book_name
|
||||
let book_name = epub_path
|
||||
.with_extension("")
|
||||
.file_name()
|
||||
.expect("unreachable")
|
||||
.to_string_lossy()
|
||||
|
|
@ -78,7 +78,7 @@ fn epub_nav_to_md(
|
|||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `doc` - The EPUB document
|
||||
/// * `epub_doc` - The EPUB document
|
||||
/// * `title` - The title of the book
|
||||
///
|
||||
/// # Returns
|
||||
|
|
@ -189,11 +189,11 @@ fn write_book_toml(
|
|||
creator: Option<String>,
|
||||
) -> io::Result<()> {
|
||||
let output_dir = output_dir.as_ref();
|
||||
let creator = match creator {
|
||||
let author = match creator {
|
||||
Some(creator) => format!("author = \"{creator}\"\n"),
|
||||
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)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue