Skip to content

Commit 04ef6ee

Browse files
committed
pause for 2 seconds after an Rmd file is compiled, so that Hugo server can be sure about the last changed file and navigate to its output page
this trick should mostly fix #486
1 parent 409d154 commit 04ef6ee

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: blogdown
22
Type: Package
33
Title: Create Blogs and Websites with R Markdown
4-
Version: 0.20.17
4+
Version: 0.20.18
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
77
person("Beilei", "Bian", role = "ctb"),

R/render.R

+9-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ timestamp_filter = function(files) {
9797
files[require_rebuild(output_file(files), files)]
9898
}
9999

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

137+
out = NULL
137138
for (f in files) {
138139
d = dirname(f)
139140
out = output_file(f, to_md <- is_rmarkdown(f))
@@ -152,6 +153,12 @@ build_rmds = function(files) {
152153
append(s, 'draft: yes', 1)
153154
})
154155
}
156+
# when serving the site, pause for a moment so Hugu server's auto navigation
157+
# can navigate to the `out` page
158+
if (pause || (!is.null(out) && length(opts$get('served_dirs')))) {
159+
Sys.sleep(getOption('blogdown.build_rmds.wait', 2))
160+
xfun::process_file(out)
161+
}
155162
message('Done.')
156163
}
157164
}

R/site.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ blogdown_site = function(input, ...) {
1313
# rendering a single file (by clicking the Knit button)
1414
if (!is.null(input_file)) xfun::in_dir(site_root(), {
1515
input_file = rmarkdown::relative_to(getwd(), input_file)
16-
build_rmds(input_file)
16+
build_rmds(input_file, pause = TRUE)
1717
# run serve_site() to preview the site if the server has not been started
1818
if (interactive()) preview_site() else tryCatch(
1919
rstudioapi::sendToConsole('blogdown:::preview_site()', echo = FALSE)

0 commit comments

Comments
 (0)