Skip to content

Instantly share code, notes, and snippets.

@dfeng
Created March 1, 2016 19:10
Show Gist options
  • Save dfeng/fbd262b663b3999f109d to your computer and use it in GitHub Desktop.
Save dfeng/fbd262b663b3999f109d to your computer and use it in GitHub Desktop.
build.R
local({
baseurl = paste0(servr:::jekyll_config('.', 'baseurl'), "/")
knitr::opts_knit$set(base.url = baseurl)
# fall back on 'kramdown' if markdown engine is not specified
# markdown = servr:::jekyll_config('.', 'markdown', 'kramdown')
# see if we need to use the Jekyll render in knitr
# if (markdown == 'kramdown') {
# knitr::render_jekyll()
# } else knitr::render_markdown()
# input/output filenames are passed as two additional arguments to Rscript
a = commandArgs(TRUE)
a1 = unlist(strsplit(a[1], "/"))
a2 = unlist(strsplit(a[2], "/"))
d = gsub('^_|[.][a-zA-Z]+$', '', a1[2])
knitr::opts_chunk$set(
fig.path = sprintf('figure/%s/', d),
cache.path = sprintf('cache/%s/', d)
)
# set where you want to host the figures (I store them in my Dropbox Public
# folder, and you might prefer putting them in GIT)
# if (Sys.getenv('USER') == 'yihui') {
# # these settings are only for myself, and they will not apply to you, but
# # you may want to adapt them to your own website
# knitr::opts_chunk$set(fig.path = sprintf('%s/', gsub('^.+/', '', d)))
# knitr::opts_knit$set(
# base.dir = '~/Dropbox/Public/jekyll/',
# base.url = 'http://db.yihui.name/jekyll/'
# )
# }
knitr::opts_knit$set(width = 70)
new_out = paste0(a1[1], "/", a2[2])
rmarkdown::render(a[1], output_file = new_out,
output_format = tufte::tufte_html(
template = "_includes/rmd.html",
lib_dir = "_stupid", # can change the tufte package too, but instead just move lib to fake folder
self_contained = FALSE,
toc = TRUE,
mathjax = NULL,
highlight = "default"
# template = system.file("rmd/fragment/default.html", package = "rmarkdown")
),
quiet = TRUE, encoding = 'UTF-8', envir = .GlobalEnv,
params = list(
# template = "_includes/rmd.html"
lib_dir = "_stupid"
)
)
# move file back to right position
file.rename(new_out, a[2])
})
# rmarkdown::render("projects.Rmd",
# output_format = tufte::tufte_html(
# self_contained = FALSE,
# toc = TRUE,
# mathjax = NULL,
# highlight = "default",
# template = system.file("rmd/fragment/default.html", package = "rmarkdown")
# ),
# quiet = TRUE, encoding = 'UTF-8', envir = .GlobalEnv
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment