Skip to content

Commit

Permalink
pause for 2 seconds after an Rmd file is compiled, so that Hugo serve…
Browse files Browse the repository at this point in the history
…r can be sure about the last changed file and navigate to its output page

this trick should mostly fix #486
  • Loading branch information
yihui committed Oct 9, 2020
1 parent 409d154 commit 04ef6ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: blogdown
Type: Package
Title: Create Blogs and Websites with R Markdown
Version: 0.20.17
Version: 0.20.18
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Beilei", "Bian", role = "ctb"),
Expand Down
11 changes: 9 additions & 2 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ timestamp_filter = function(files) {
files[require_rebuild(output_file(files), files)]
}

# raw indicates paths of dependencies are not encoded in the HTML output
build_rmds = function(files) {
# build R Markdown posts
build_rmds = function(files, pause = FALSE) {
if (length(files) == 0) return()
# ignore files that are locked (being rendered by another process)
i = !file.exists(locks <- paste0(files, '.lock~'))
Expand Down Expand Up @@ -134,6 +134,7 @@ build_rmds = function(files) {
if (file.copy(shared_yml, copy)) copied_yaml <<- c(copied_yaml, copy)
}

out = NULL
for (f in files) {
d = dirname(f)
out = output_file(f, to_md <- is_rmarkdown(f))
Expand All @@ -152,6 +153,12 @@ build_rmds = function(files) {
append(s, 'draft: yes', 1)
})
}
# when serving the site, pause for a moment so Hugu server's auto navigation
# can navigate to the `out` page
if (pause || (!is.null(out) && length(opts$get('served_dirs')))) {
Sys.sleep(getOption('blogdown.build_rmds.wait', 2))
xfun::process_file(out)
}
message('Done.')
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/site.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ blogdown_site = function(input, ...) {
# rendering a single file (by clicking the Knit button)
if (!is.null(input_file)) xfun::in_dir(site_root(), {
input_file = rmarkdown::relative_to(getwd(), input_file)
build_rmds(input_file)
build_rmds(input_file, pause = TRUE)
# run serve_site() to preview the site if the server has not been started
if (interactive()) preview_site() else tryCatch(
rstudioapi::sendToConsole('blogdown:::preview_site()', echo = FALSE)
Expand Down

0 comments on commit 04ef6ee

Please sign in to comment.