Skip to content

Commit

Permalink
Merge pull request #82 from blandger/add_epubchecker_to_build
Browse files Browse the repository at this point in the history
added epubchecker
  • Loading branch information
blandger authored Jan 19, 2024
2 parents 2f302a6 + 60f6258 commit 95948c3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
uses: actions/checkout@v2
- name: Install cargo version
uses: dtolnay/rust-toolchain@stable
- name: Install epub checker
run: sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get install -y epubcheck
# - name: Install cargo audit
# run: cargo install cargo-audit
- name: Show rust version
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ addons:
packages:
- python3
- python3-pip
- epubcheck

# Rust 1.38 and above supports the new Cargo.lock format
# https://github.com/rust-lang/cargo/pull/7579
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ doc = false
[dependencies]
eyre = "0.6"
epub-builder = "0.7"
thiserror = "1.0.43"
thiserror = "1.0.49"
pulldown-cmark = "0.9.3"
semver = "1.0.17"
serde = { version = "1.0.163", features = ["derive"] }
Expand All @@ -41,7 +41,7 @@ toml = "0.5.11" # downgraded due to parent 'mdbook' dependency and error there
html_parser = "0.7.0"
url = "2.3"
ureq = "2.5"
const_format = "0.2.30"
const_format = "0.2.31"

[dev-dependencies]
tempdir = "0.3.7"
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub enum Error {
#[error("Error reading stylesheet")]
StylesheetRead,

#[error("Epub check failed, ensure the epubcheck program is installed")]
EpubCheck,
#[error("epubcheck has failed: {0}")]
EpubCheck(String),

#[error(transparent)]
Io(#[from] std::io::Error),
Expand Down Expand Up @@ -125,6 +125,7 @@ pub fn generate(ctx: &RenderContext) -> Result<(), Error> {
}

let f = File::create(&outfile)?;
debug!("Path to epub file: '{:?}'", f);
Generator::new(ctx)?.generate(f)?;

Ok(())
Expand Down
14 changes: 4 additions & 10 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,8 @@ fn find_assets_in_nested_html_tags(element: &Element) -> Result<Vec<String>, Err
}
}
for item in &element.children {
match item {
Node::Element(ref nested_element) => {
found_asset.extend(find_assets_in_nested_html_tags(nested_element)?.into_iter());
}
_ => {}
if let Node::Element(ref nested_element) = item {
found_asset.extend(find_assets_in_nested_html_tags(nested_element)?.into_iter());
}
}

Expand All @@ -290,11 +287,8 @@ fn find_assets_in_markdown(chapter_src_content: &str) -> Result<Vec<String>, Err

if let Ok(dom) = Dom::parse(&content) {
for item in dom.children {
match item {
Node::Element(ref element) => {
found_asset.extend(find_assets_in_nested_html_tags(element)?.into_iter());
}
_ => {}
if let Node::Element(ref element) = item {
found_asset.extend(find_assets_in_nested_html_tags(element)?.into_iter());
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn output_epub_exists() {
assert!(output_file.exists());
}

#[ignore = "Needs reworking for resource outside src"]
#[ignore = "Waiting for issue = https://github.com/lise-henry/epub-builder/issues/45"]
#[test]
#[serial]
fn output_epub_is_valid() {
Expand All @@ -82,21 +82,23 @@ fn output_epub_is_valid() {

fn epub_check(path: &Path) -> Result<(), Error> {
init_logging();
debug!("epub_check...");
debug!("epub_check in path = {}...", &path.display());
let cmd = Command::new("epubcheck").arg(path).output();

match cmd {
Ok(output) => {
if output.status.success() {
Ok(())
} else {
Err(Error::EpubCheck)
let error_from_epubcheck = String::from_utf8_lossy(output.stderr.as_slice());
error!("Error: {:?}", &error_from_epubcheck);
Err(Error::EpubCheck(error_from_epubcheck.to_string()))
}
}
Err(_) => {
Err(err) => {
// failed to launch epubcheck, it's probably not installed
debug!("Failed to launch epubcheck, it's probably not installed here...");
Err(Error::EpubCheck)
Err(Error::EpubCheck(err.to_string()))
}
}
}
Expand Down

0 comments on commit 95948c3

Please sign in to comment.