Skip to content

Commit a0ef873

Browse files
cdervyihui
authored andcommitted
fix #1307: load the custom config file directly instead of renaming it to _bookdown.yml
1 parent e717c5e commit a0ef873

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# CHANGES IN bookdown VERSION 0.37
2+
3+
- Custom config files passed to the `config_file` argument of `render_book()` are no longer temporarily renamed to `_bookdown.yml` (thanks, @debruine, #1307).
4+
15
# CHANGES IN bookdown VERSION 0.36
26

37
- Fix an issue with parsing resources from raw HTML code (thanks, @lennylin, https://community.rstudio.com/t/bookdown-image-with-a-weblink/172542)

R/render.R

+1-10
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,8 @@ render_book = function(
104104
"versions of bookdown."
105105
)
106106

107-
if (config_file != '_bookdown.yml') {
108-
unlink(tmp_config <- tempfile('_bookdown_', '.', '.yml'))
109-
if (file.exists('_bookdown.yml')) file.rename('_bookdown.yml', tmp_config)
110-
file.rename(config_file, '_bookdown.yml')
111-
on.exit({
112-
file.rename('_bookdown.yml', config_file)
113-
if (file.exists(tmp_config)) file.rename(tmp_config, '_bookdown.yml')
114-
}, add = TRUE)
115-
}
116-
117107
on.exit(opts$restore(), add = TRUE)
108+
opts$set(config_file = config_file)
118109
config = load_config() # configurations in _bookdown.yml
119110
output_dir = output_dirname(output_dir, config)
120111
on.exit(xfun::del_empty_dir(output_dir), add = TRUE)

R/utils.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ get_base_format = function(format, options = list()) {
6969
do.call(format, options)
7070
}
7171

72-
load_config = function() {
73-
if (length(opts$get('config')) == 0 && file.exists('_bookdown.yml')) {
72+
load_config = function(config_file = '_bookdown.yml') {
73+
config_file = opts$get('config_file') %n% config_file
74+
if (length(opts$get('config')) == 0 && file.exists(config_file)) {
7475
# store the book config
75-
opts$set(config = rmarkdown:::yaml_load_file('_bookdown.yml'))
76+
opts$set(config = rmarkdown:::yaml_load_file(config_file))
7677
}
7778
opts$get('config')
7879
}

0 commit comments

Comments
 (0)