-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5004b9a
commit 8a7d64b
Showing
5 changed files
with
36 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
pdf: | ||
Rscript _render.R "bookdown::pdf_book" | ||
|
||
gitbook: | ||
Rscript _render.R "bookdown::gitbook" | ||
|
||
all: | ||
Rscript _render.R | ||
|
||
wordcount: | ||
@texcount _book/sjtu-thesis-rmd.tex -inc -ch-only | awk '/total/ {getline; print "纯中文字数\t\t\t:",$$4}' | ||
@texcount _book/sjtu-thesis-rmd.tex -inc -chinese | awk '/total/ {getline; print "总字数(英文单词 + 中文字)\t:",$$4}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,27 @@ | ||
quiet = "--quiet" %in% commandArgs(FALSE) | ||
formats = commandArgs(TRUE) | ||
format = commandArgs(TRUE) | ||
travis = !is.na(Sys.getenv('CI', NA)) | ||
|
||
# install bookdown | ||
local({ | ||
r = getOption('repos') | ||
if (!length(r) || all(r['CRAN'] == '@CRAN@')) r['CRAN'] = 'https://cran.rstudio.com' | ||
options(repos = r) | ||
}) | ||
if (system.file(package = 'bookdown') == '') install.packages('bookdown') | ||
|
||
src = (function() { | ||
attr(body(sys.function()), 'srcfile') | ||
})()$filename | ||
if (is.null(src) || src == '') src = '.' | ||
owd = setwd(dirname(src)) | ||
|
||
# provide default formats if necessary | ||
if (length(formats) == 0) formats = c( | ||
'bookdown::pdf_book', 'bookdown::epub_book', 'bookdown::gitbook' | ||
) | ||
# provide default format if necessary | ||
if (length(format) == 0) format = 'bookdown::pdf_book' | ||
# 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 = %s)", fmt, quiet) | ||
res = bookdown:::Rscript(c('-e', shQuote(cmd))) | ||
if (res != 0) stop('Failed to compile the book to ', fmt) | ||
if (!travis && fmt == 'bookdown::epub_book') | ||
bookdown::calibre('_book/bookdown.epub', 'mobi') | ||
} | ||
|
||
r = '<body onload="window.location = \'https://bookdown.org/yihui\'+location.pathname">' | ||
for (f in list.files('_book', '[.]html$', full.names = TRUE)) { | ||
x = readLines(f) | ||
if (length(i <- grep('^\\s*<body>\\s*$', x)) == 0) next | ||
# patch HTML files in gh-pages if built on Travis, to redirect to bookdown.org | ||
if (travis) x[i[1]] = r | ||
i = grep('<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">.+</a>', x)[1] | ||
# shorter title on the toolbar | ||
if (!is.na(i)) x[i] = gsub('bookdown: ', '', x[i], fixed = TRUE) | ||
i = c( | ||
grep('^\\s*<meta name="generator" content="bookdown [.0-9]+ and GitBook [.0-9]+">$', x), | ||
grep('^<meta name="date" content="[-0-9]+">$', x) | ||
) | ||
if (travis && length(i)) x = x[-i] | ||
writeLines(x, f) | ||
} | ||
|
||
if (length(formats) > 1) bookdown::publish_book() | ||
cmd = sprintf("bookdown::render_book('index.Rmd', '%s', quiet = %s)", format, quiet) | ||
res = bookdown:::Rscript(c('-e', shQuote(cmd))) | ||
if (res != 0) stop('Failed to compile the book to ', format) | ||
|
||
setwd(owd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters