diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 87fda93..c8646f4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,7 @@ jobs: run: | cargo build --release --target ${{ matrix.target }} - name: Upload Binary File to release + if: startsWith(github.ref, 'refs/tags/v') uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} @@ -80,6 +81,7 @@ jobs: run: | cargo build --release --target ${{ matrix.target }} - name: Upload Binary File to release + if: startsWith(github.ref, 'refs/tags/v') uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} @@ -120,6 +122,7 @@ jobs: -w /build --platform arm64 rust bash -c \ "rustup target add ${{ matrix.target }} && cargo build --release --target ${{ matrix.target }}" - name: Upload Binary File to release + if: startsWith(github.ref, 'refs/tags/v') uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 358ac1c..fb30d0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "GPL-3.0" name = "mdbook-pdf" readme = "README.md" repository = "https://github.com/HollowMan6/mdbook-pdf" -version = "0.1.3" +version = "0.1.4" include = [ "**/*.rs", "Cargo.toml", @@ -23,6 +23,3 @@ mdbook-pdf-headless_chrome = "0" regex = "1" serde = "1" serde_derive = "1" - -[output.pdf-outline] -like-wkhtmltopdf = false diff --git a/src/main.rs b/src/main.rs index 3e76851..4bf63ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,6 +145,7 @@ fn main() -> Result<(), Box> { .idle_browser_timeout(Duration::from_secs(600)) .path(browser_binary) .args(vec![ + OsStr::new("--disable-pdf-tagging"), OsStr::new("--unlimited-storage"), OsStr::new("--disable-web-security"), OsStr::new("--webkit-print-color-adjust"), @@ -177,6 +178,25 @@ fn main() -> Result<(), Box> { let page = tab.navigate_to(&url)?.wait_until_navigated()?; page.wait_for_element("#content-has-all-loaded-for-mdbook-pdf-generation")?; + // Find the theme and click it to change the theme. + if !cloned_cfg.theme.is_empty() { + match tab.find_element(&format!("button.theme#{}", cloned_cfg.theme.to_lowercase())) { + Ok(_) => { + tab.evaluate( + &format!( + "document.querySelector('button.theme#{}').click()", + cloned_cfg.theme.to_lowercase() + ), + false, + )?; + } + Err(_) => println!( + "Unable to find theme {}, return to default one.", + cloned_cfg.theme.to_lowercase() + ), + }; + } + // Generate the PDF. let generated_pdf = match page.print_to_pdf(Some(pdf_opts)) { Ok(output) => output, @@ -222,6 +242,7 @@ pub struct PrintOptions { pub landscape: bool, pub display_header_footer: bool, pub print_background: bool, + pub theme: String, pub scale: f64, pub paper_width: f64, pub paper_height: f64, @@ -250,6 +271,7 @@ impl Default for PrintOptions { landscape: false, display_header_footer: false, print_background: false, + theme: "".to_string(), scale: 1_f64, paper_width: 8.5_f64, paper_height: 11_f64, diff --git a/test_doc/book.toml b/test_doc/book.toml index 32e697d..3fdaeac 100644 --- a/test_doc/book.toml +++ b/test_doc/book.toml @@ -21,6 +21,7 @@ title = "An Example" landscape = false display-header-footer = true print-background = true +theme = "ayu" scale = 1 paper-width = 8 paper-height = 10