Last active
April 4, 2017 14:35
-
-
Save randy3k/6d94e78115c666d5692a3a34ef60023a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/Rscript --vanilla | |
| # from https://github.com/muuankarski/blog | |
| # run ./knitpages.R to update all Rmd files that need to be updated. | |
| KnitPost <- function(input, outfile) { | |
| require(knitr); | |
| opts_knit$set(base.dir = "content") | |
| opts_knit$set(base.url = "/") | |
| fig.path <- paste0("images/", sub(".Rmd$", "", basename(input)), "/") | |
| opts_chunk$set(fig.path = fig.path) | |
| opts_chunk$set(fig.cap = "center") | |
| knit(input, outfile, envir = parent.frame()) | |
| } | |
| for (infile in list.files("content", pattern = "*.Rmd", full.names = TRUE)) { | |
| outfile <- paste0("content/rmd/", sub(".Rmd$", ".md", basename(infile))) | |
| # knit only if the input file is the last one modified | |
| if (!file.exists(outfile) | | |
| file.info(infile)$mtime > file.info(outfile)$mtime) { | |
| KnitPost(infile, outfile) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment