Skip to content

Commit

Permalink
gitbook() and ebook() store cover.png at the same location as the pdf…
Browse files Browse the repository at this point in the history
… version
  • Loading branch information
ThierryO committed May 15, 2023
1 parent e59aea0 commit 754741f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ importFrom(dplyr,mutate_all)
importFrom(fs,dir_create)
importFrom(fs,dir_exists)
importFrom(fs,file_copy)
importFrom(fs,file_exists)
importFrom(fs,is_dir)
importFrom(fs,is_file)
importFrom(fs,path)
Expand Down
11 changes: 5 additions & 6 deletions R/ebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @export
#' @importFrom assertthat assert_that has_name
#' @importFrom bookdown epub_book
#' @importFrom fs path
#' @importFrom fs file_exists path
#' @importFrom pdftools pdf_convert
#' @importFrom rmarkdown pandoc_variable_arg yaml_front_matter
#' @family output
Expand Down Expand Up @@ -64,14 +64,13 @@ epub_book <- function() {
)
cover_image <- NULL
if (has_name(fm, "cover")) {
cover_path <- file.path(getwd(), "cover.png")
if (!file.exists(cover_path)) {
cover_image <- gsub("\\.pdf$", ".png", fm$cover)
if (!file_exists(cover_image)) {

Check warning on line 68 in R/ebook.R

View check run for this annotation

Codecov / codecov/patch

R/ebook.R#L67-L68

Added lines #L67 - L68 were not covered by tests
pdf_convert(
pdf = file.path(getwd(), fm$cover), format = "png", pages = 1,
dpi = 770 * 25.4 / 210, filenames = cover_path
pdf = fm$cover, format = "png", pages = 1, dpi = 770 * 25.4 / 210,
filenames = cover_image

Check warning on line 71 in R/ebook.R

View check run for this annotation

Codecov / codecov/patch

R/ebook.R#L70-L71

Added lines #L70 - L71 were not covered by tests
)
}
cover_image <- basename(cover_path)
}
meta_author <- vapply(
fm$author,
Expand Down
14 changes: 8 additions & 6 deletions R/gitbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @export
#' @importFrom assertthat assert_that has_name
#' @importFrom bookdown gitbook
#' @importFrom fs path
#' @importFrom fs file_exists path
#' @importFrom htmltools htmlDependency
#' @importFrom pdftools pdf_convert
#' @importFrom rmarkdown pandoc_variable_arg yaml_front_matter
Expand Down Expand Up @@ -64,15 +64,17 @@ gitbook <- function(code_folding = c("none", "show", "hide")) {
system.file(file.path("pandoc", "translations.lua"), package = "INBOmd")
)
assert_that(
file.exists(file.path(getwd(), "index.Rmd")),
getwd() |>
path("index.Rmd") |>
file_exists(),

Check warning on line 69 in R/gitbook.R

View check run for this annotation

Codecov / codecov/patch

R/gitbook.R#L67-L69

Added lines #L67 - L69 were not covered by tests
msg = "You need to render an INBOmd::gitbook() from it's working directory"
)
if (has_name(fm, "cover")) {
cover_path <- file.path(getwd(), "cover.png")
if (!file.exists(cover_path)) {
cover_path <- gsub("\\.pdf$", ".png", fm$cover)
if (!file_exists(cover_path)) {

Check warning on line 74 in R/gitbook.R

View check run for this annotation

Codecov / codecov/patch

R/gitbook.R#L73-L74

Added lines #L73 - L74 were not covered by tests
pdf_convert(
pdf = file.path(getwd(), fm$cover), format = "png", pages = 1,
dpi = 770 * 25.4 / 210, filenames = cover_path
pdf = fm$cover, format = "png", pages = 1, dpi = 770 * 25.4 / 210,
filenames = cover_path

Check warning on line 77 in R/gitbook.R

View check run for this annotation

Codecov / codecov/patch

R/gitbook.R#L76-L77

Added lines #L76 - L77 were not covered by tests
)
}
pandoc_args <- c(
Expand Down

0 comments on commit 754741f

Please sign in to comment.