Closed xie186 closed 7 years ago
Could you try knitr::include_graphics("/img/test.jpg")
instead? See https://bookdown.org/yihui/blogdown/static-files.html
This didn't work for me - following the usual advice, I continued to get an error when running serve_site (also on the demo sites) when blogdown
tries to build the html file to pass on to hugo.
Error in knitr::include_graphics("/img/test.jpg") :
Cannot find the file(s): "/img/test.jpg"
The solution for me was to add error = FALSE
to include_graphics - that way the html gets generated correctly, even if knitr is momentarily confused that the file that is referenced doesn't yet live in the place the path points to.
# this works
knitr::include_graphics("/img/test.jpg", error = FALSE)
For reference, this is a major change in knitr 1.28 https://github.com/yihui/knitr/blob/master/NEWS.md#changes-in-knitr-version-128
And there is now a way in knitr 1.29 to change the new default behavior globally https://github.com/yihui/knitr/blob/master/NEWS.md#changes-in-knitr-version-129 That would be interesting for bookdown.
I'm trying to use
knitr::include_graphics
. But it seemed that in the html file generated byblogdown::build_site()
. The src value is the absolute value on the linux server which is not I want. Is this a bug? Or there is a better way to do this? Thanks in advance. Rmd code:Html output: