Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [ "derive", "lib"]
members = [ "derive", "lib", "cli"]
resolver = "2"

[workspace.package]
Expand All @@ -11,6 +11,6 @@ description = "epub、mobi电子书读写"
repository = "https://github.com/inkroom/iepub"
readme = "./README.md"
keywords = ["epub","mobi","azw","ebook"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[patch.crates-io]
iepub = { path = "lib" }
10 changes: 10 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "iepub-cli"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
description = { workspace = true }

[dependencies]
md-5 = {version = "0.10.6", optional = true }
iepub = { path = "../lib", version = "1.3.1" }
18 changes: 18 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::path::Path;

fn main() {
let out_path = std::env::var("OUT_DIR").expect("OUT_DIR not found");
let m = format!(
r##"
pub const PROJECT_NAME :&str = r#"{}"#;
pub const PKG_VERSION :&str = r#"{}"#;
"##,
std::env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME not found"),
std::env::var("CARGO_PKG_VERSION").expect("CARGO_PKG_VERSION not found")
);

let path = Path::new(out_path.as_str()).join("version.rs");
std::fs::write(path, m).expect("write version fail");
println!("cargo:rerun-if-env-changed=CARGO_PKG_NAME");
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
}
2 changes: 1 addition & 1 deletion lib/src/cli/arg.rs → cli/src/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ impl OptUtil for &[ArgOption] {

#[cfg(test)]
mod tests {
use crate::cli::arg::{OptUtil, OptionType};
use crate::arg::{OptUtil, OptionType};

use super::{parse_command_arg, parse_global_arg, Arg, CommandOptionDef, OptionDef};
fn create_option_def() -> Vec<OptionDef> {
Expand Down
22 changes: 10 additions & 12 deletions lib/src/cli/command.rs → cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::Write;

use crate::{
cli::arg::{self, OptUtil},
arg::{self, OptUtil},
exec_err, msg,
};
use iepub::prelude::*;
Expand Down Expand Up @@ -121,14 +121,14 @@ fn read_book(file: &str) -> IResult<OwnBook> {
}

pub(crate) mod epub {

use std::vec;

use crate::cli::arg::OptUtil;
use crate::cli::command::get_single_input;
use crate::cli::command::is_overiade;
use crate::cli::command::out_file;
use crate::cli::command::write_file;
use crate::arg::OptUtil;
use crate::command::get_single_input;
use crate::command::is_overiade;
use crate::command::out_file;
use crate::command::write_file;
use crate::exec_err;
use crate::Book;
use iepub::prelude::adapter::add_into_epub;
Expand All @@ -143,7 +143,7 @@ pub(crate) mod epub {
use iepub::prelude::MobiWriter;

use crate::{
cli::arg::{self, ArgOption, CommandOptionDef, OptionDef, OptionType},
arg::{self, ArgOption, CommandOptionDef, OptionDef, OptionType},
msg, Command,
};

Expand Down Expand Up @@ -1117,10 +1117,8 @@ pub(crate) mod mobi {
use iepub::prelude::{adapter::mobi_to_epub, EpubWriter, MobiNav, MobiWriter};

use crate::{
cli::{
arg::{self, ArgOption, OptUtil, OptionDef, OptionType},
command::out_file,
},
arg::{self, ArgOption, OptUtil, OptionDef, OptionType},
command::out_file,
exec_err, msg, Book, Command,
};

Expand Down
2 changes: 1 addition & 1 deletion lib/src/cli/log.rs → cli/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) fn set_enable_log(value: bool) {
macro_rules! msg {
( $($arg:tt)+) => {
unsafe{
if $crate::cli::log::IS_LOG {
if $crate::log::IS_LOG {
println!($($arg)+)
}
}
Expand Down
20 changes: 10 additions & 10 deletions lib/src/main.rs → cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
//!
//! tool -i file.epub get-cover 1.jpg
//!

mod cli;
mod arg;
mod command;
mod log;

use std::{env, fs::File};

use cli::arg::{Arg, ArgOption, OptionDef, OptionType};
use crate::arg::{Arg, ArgOption, OptionDef, OptionType};
use commands::{epub, mobi};
use iepub::prelude::*;

Expand All @@ -24,7 +24,7 @@ fn create_option_def() -> Vec<OptionDef> {
mod commands {
macro_rules! register_command {
($($cmd_type:ident),*) => {
pub(crate) fn create_command_option_def() -> Vec<$crate::cli::arg::CommandOptionDef> {
pub(crate) fn create_command_option_def() -> Vec<$crate::arg::CommandOptionDef> {
vec![
$(
$cmd_type::def(),
Expand All @@ -43,7 +43,7 @@ mod commands {
};
}
pub(crate) mod epub {
use crate::cli::command::epub::*;
use crate::command::epub::*;

// 注册子命令
#[cfg(feature = "md-5")]
Expand Down Expand Up @@ -73,7 +73,7 @@ mod commands {
);
}
pub(crate) mod mobi {
use crate::cli::command::mobi::*;
use crate::command::mobi::*;
register_command!(
BookInfoGetter,
GetImage,
Expand Down Expand Up @@ -170,10 +170,10 @@ fn main() {
let mut s: Vec<String> = env::args().collect();
let exe_file_name = s.remove(0); //把第一个参数去掉

let (mut arg, index) = cli::arg::parse_global_arg(s, create_option_def()).unwrap();
let (mut arg, index) = arg::parse_global_arg(s, create_option_def()).unwrap();

// 设置日志
cli::log::set_enable_log(arg.find_opt("l").is_some());
log::set_enable_log(arg.find_opt("l").is_some());

if print_useage(&arg, &exe_file_name) {
return;
Expand All @@ -187,7 +187,7 @@ fn main() {
if let Some((input_type, _)) = input_type {
// 解析参数
// 解析后续参数
cli::arg::parse_command_arg(
arg::parse_command_arg(
&mut arg,
env::args().skip(index + 1).map(|f| f.to_string()).collect(),
if input_type == 0 {
Expand Down
4 changes: 2 additions & 2 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "iepub-derive"
version = { workspace=true }
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
description = { workspace = true }

[lib]
proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

9 changes: 4 additions & 5 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ keywords = { workspace = true }
rust-version = { workspace = true }

[dependencies]
zip = "7.2.0"
anyhow = "1.0.100"
quick-xml = { version = "0.39.0" }
zip = "8.1.0"
anyhow = "1.0.102"
quick-xml = { version = "0.39.2" }
ab_glyph = { version = "0.2.32", optional = true }
imageproc = { version = "0.26.0", optional = true}
serde_json = { version = "1.0.149", optional = true }
iepub-derive = { path = "../derive", version = "1.3.1" }
serde = { version = "1.0.228", features = ["derive"], optional = true }
image = { version = "0.25.9", default-features = false, features = ["jpeg"], optional = true }
md-5 = {version = "0.10.6", optional = true }

[dev-dependencies]
reqwest = { version = "0.13.1", features = ["blocking"] }
reqwest = { version = "0.13.2", features = ["blocking"] }

[features]
no_nav=[]
Expand Down
14 changes: 7 additions & 7 deletions lib/src/adapter/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ pub mod concat {
.with_title("1.1")
.with_file_name("1/1.xhtml"),
);
let mut builder = EpubBuilder::new()
let builder = EpubBuilder::new()
.custome_nav(true)
.with_title("测试合并")
.with_creator("作者")
Expand Down Expand Up @@ -706,7 +706,7 @@ pub mod concat {
.with_title("3.1")
.with_file_name("2/1.xhtml"),
);
let mut builder = EpubBuilder::new()
let builder = EpubBuilder::new()
.custome_nav(true)
.with_title("测试合并2")
.with_creator("作者2")
Expand All @@ -730,11 +730,11 @@ pub mod concat {
);
let mut book2 = builder.book().unwrap();

let mut builder = EpubBuilder::default();
let (mut builder, len, a_len) =
let builder = EpubBuilder::default();
let (builder, len, a_len) =
add_into_epub(builder, &mut book1, 0, 0, 0, None, &[]).unwrap();

let (mut builder, len, a_len) =
let (builder, _, _) =
add_into_epub(builder, &mut book2, len, a_len, 0, None, &[]).unwrap();

let b = builder.book().unwrap();
Expand Down Expand Up @@ -859,13 +859,13 @@ mod tests {
let assets = vec![
MobiAssets {
_file_name: "1.jpg".to_string(),
media_type: String::new(),
_media_type: String::new(),
_data: None,
recindex: 55,
},
MobiAssets {
_file_name: "2.jpg".to_string(),
media_type: String::new(),
_media_type: String::new(),
_data: None,
recindex: 56,
},
Expand Down
3 changes: 0 additions & 3 deletions lib/src/cli/mod.rs

This file was deleted.

4 changes: 2 additions & 2 deletions lib/src/epub/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl EpubHtml {
}

pub fn raw_data(&mut self) -> Option<&str> {
let (id, origin) = if let Some(index) = self._file_name.find('#') {
let (_, origin) = if let Some(index) = self._file_name.find('#') {
(
Some(&self._file_name[(index + 1)..]),
self._file_name[0..index].to_string(),
Expand Down Expand Up @@ -410,7 +410,7 @@ impl EpubHtml {
self
}

fn get_links(&mut self) -> Option<&mut Vec<EpubLink>> {
pub fn get_links(&mut self) -> Option<&mut Vec<EpubLink>> {
self.links.as_mut()
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/epub/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ pub(crate) fn to_html(chap: &mut EpubHtml, append_title: bool, dir: &Option<Dire
{body}
</body>
</html>"#,
chap
.body_attribute
chap.body_attribute
.as_ref()
.and_then(|f| String::from_utf8(f.clone()).ok()).unwrap_or_default(),
.and_then(|f| String::from_utf8(f.clone()).ok())
.unwrap_or_default(),
if append_title {
format!(r#"<h1 style="text-align: center">{}</h1>"#, title)
} else {
Expand Down Expand Up @@ -367,7 +367,7 @@ pub(crate) fn do_to_opf(book: &mut EpubBook, generator: &str) -> IResult<String>
}
xml.write_event(Event::Start(spine.borrow()))?;
// 把封面放第一个 nav,导航第二个
if let Some(co) = book.cover_chapter() {
if let Some(_) = book.cover_chapter() {
xml.create_element("itemref")
.with_attribute(("idref", "cover"))
.write_empty()?;
Expand Down
Loading