Skip to content

Commit

Permalink
fix #1307: load the custom config file directly instead of renaming i…
Browse files Browse the repository at this point in the history
…t to _bookdown.yml
  • Loading branch information
cderv authored and yihui committed Oct 27, 2023
1 parent e717c5e commit a0ef873
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# CHANGES IN bookdown VERSION 0.37

- Custom config files passed to the `config_file` argument of `render_book()` are no longer temporarily renamed to `_bookdown.yml` (thanks, @debruine, #1307).

# CHANGES IN bookdown VERSION 0.36

- Fix an issue with parsing resources from raw HTML code (thanks, @lennylin, https://community.rstudio.com/t/bookdown-image-with-a-weblink/172542)
Expand Down
11 changes: 1 addition & 10 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,8 @@ render_book = function(
"versions of bookdown."
)

if (config_file != '_bookdown.yml') {
unlink(tmp_config <- tempfile('_bookdown_', '.', '.yml'))
if (file.exists('_bookdown.yml')) file.rename('_bookdown.yml', tmp_config)
file.rename(config_file, '_bookdown.yml')
on.exit({
file.rename('_bookdown.yml', config_file)
if (file.exists(tmp_config)) file.rename(tmp_config, '_bookdown.yml')
}, add = TRUE)
}

on.exit(opts$restore(), add = TRUE)
opts$set(config_file = config_file)
config = load_config() # configurations in _bookdown.yml
output_dir = output_dirname(output_dir, config)
on.exit(xfun::del_empty_dir(output_dir), add = TRUE)
Expand Down
7 changes: 4 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ get_base_format = function(format, options = list()) {
do.call(format, options)
}

load_config = function() {
if (length(opts$get('config')) == 0 && file.exists('_bookdown.yml')) {
load_config = function(config_file = '_bookdown.yml') {
config_file = opts$get('config_file') %n% config_file
if (length(opts$get('config')) == 0 && file.exists(config_file)) {
# store the book config
opts$set(config = rmarkdown:::yaml_load_file('_bookdown.yml'))
opts$set(config = rmarkdown:::yaml_load_file(config_file))
}
opts$get('config')
}
Expand Down

0 comments on commit a0ef873

Please sign in to comment.