I'm building a course website with blogdown. I'd like to follow a similar setup as this site, which was from the rstudio::conf(2020) workshops. That is, I'd like all of the blogdown stuff to live in site/(e.g., config.toml, themes/, etc.), and then I can put other course materials in the materials directory.
I've set up my netlify.toml file as in the example repo, and everything works great when I push to GitHub. However, when I try to build locally with the blogdown::serve_site() addin, I get the following error:
Error in site_root(config, .site_dir) :
Could not find config.toml / config.yaml under
/Users/jakethompson/Documents/GIT/references/intro-to-ml-tidy
/Users/jakethompson/Documents/GIT/references/
/Users/jakethompson/Documents/GIT
/Users/jakethompson/Documents
/Users/jakethompson
/Users
/
So blogdown doesn't know to look under the site/ directory. I'm sure there is an option somewhere to make this happen, but I have so far been unsuccessful in finding it (e.g., here or here).
Does anyone have guidance for making blogdown build locally from a subdirectory?
cc: blogdown wizard @apreshill, who created the original site
With blogdown, the addins and helper function are defaulting to using the current working dir.
So if you work in the parent directory of the site, they would not work well if you are not.
So, in this case I believe you would need to call
blogdown::serve_site(.site_dir = "site")
to serve the site from this subdir. But you can't configure that for the addin for now.
Or you would need to change the working directory to site/ when you are working on the website. This way the addin would work.
blogdown is best working currently when the project directory is the website directory. When using subdir, default behavior could not work properly.
However, in last blogdown version, the Knit button is working now, and when you knit a document in a project, by default, serve_site() will be run if not server is currently running. You should try this because I believe even if the Rmd post is a a site sub-directory, the website will be served correctly.
This is a new feature that works like the Serve Site addin, but will work with a website in a subdir.
Would it work for you ?
We could provide an option to configure this site root dir in the .Rprofile maybe
If you think it would be useful in addition to the solution above.
The knit button does indeed serve the site correctly from the subdirectory!
I do think having an option that could be set in .Rprofile would be helpful, but I don't think is urgent. Because I have a keyboard shortcut tied to the addin and keep hitting it out of habit, I have added a setwd() call to my project's .Rprofile that sets the working directory to site/. I don't feel good about it, but it works!
In that case, I would suggest to open a feature request on the blogdown repo with your context and use case so that this is shared and people could that request and we do not forget.
I don't think it would have a lot of side effect, so I think it would be safe to add it.
setwd() is not THAT bad when you use it wisely and for you personal purpose, with relative path. But I agree that this is the hack that we should prevent on our side.
Now you can set options(blogdown.site_root = "site/") in your .Rprofile to modify the default value of .site_dir in serve_site. This allow the addin to work with sub directories.