-
Notifications
You must be signed in to change notification settings - Fork 0
/
_publish.R
41 lines (36 loc) · 1.39 KB
/
_publish.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# publish the book with different HTML styles; you should not need this script
unlink('_book', recursive = TRUE)
x = readLines('index.Rmd')
i = 1
s = paste0('title: "Metagenomics Workshop NCGR (', c('Bootstrap', 'Tufte'), ' Style)"')
for (fmt in c('html_book', 'tufte_html_book')) {
unlink('_book', recursive = TRUE)
file.copy('index.Rmd', '_index.Rmd')
file.copy('_output.yml', '_output.yml2')
writeLines(
gsub('^title: ".*"', s[i], gsub('gitbook', fmt, x)), 'index.Rmd'
)
cat(
'bookdown::', fmt, ':\n', ' css: [style.css, toc.css]\n', sep = '', file = '_output.yml',
append = TRUE
)
cmd = sprintf("bookdown::render_book('index.Rmd', 'bookdown::%s', quiet = TRUE)", fmt)
res = xfun::Rscript(c('-e', shQuote(cmd)))
file.rename('_index.Rmd', 'index.Rmd')
file.rename('_output.yml2', '_output.yml')
if (res != 0) stop('Failed to compile the book to ', fmt)
i = i + 1
bookdown::publish_book(paste0('bookdown-demo', i))
}
unlink('_book', recursive = TRUE)
# default formats
formats = c(
'bookdown::pdf_book', 'bookdown::epub_book', 'bookdown::gitbook'
)
# render the book to all formats unless they are specified via command-line args
for (fmt in formats) {
cmd = sprintf("bookdown::render_book('index.Rmd', '%s', quiet = TRUE)", fmt)
res = xfun::Rscript(c('-e', shQuote(cmd)))
if (res != 0) stop('Failed to compile the book to ', fmt)
}
bookdown::publish_book('bookdown-demo')