rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.74k stars 331 forks source link

no content rendered to page on serve_site() #704

Closed bjsmith closed 2 years ago

bjsmith commented 2 years ago

I am attempting to serve a blogdown website. It's an old one that used to work, but it doesn't now. Specifically, serve_site() runs without an error, but the compiled page, viewable in the browser on the View panel, contains no content.

In order to isolate the problem I have created a minimal example. I followed the guide at https://www.apreshill.com/blog/2020-12-new-year-new-blogdown/ to create a brand new website. I created a new R project in a blank directory, then ran the following code:

remotes::install_github("rstudio/blogdown")
blogdown::new_site(theme = "wowchemy/starter-academic")

Following this, in RStudio, the View Panel activates, but its contents is blank. Using my browser to browse to http://localhost:4321, the contents are blank. Using "inspect source" in-browser, I see the source is:

<pre>
</pre>

The output in the R console is:

> blogdown::new_site(theme = "wowchemy/starter-academic")
― Creating your new site
► The directory '.' is not empty. Create the site anyway? (y/n) y
| Installing the theme wowchemy/starter-academic from github.com
trying URL 'https://github.com/wowchemy/starter-academic/archive/main.tar.gz'
downloaded 1.8 MB

| Adding the sample post to content/post/2020-12-01-r-rmarkdown/index.Rmd
| Converting all metadata to the YAML format
| Adding netlify.toml in case you want to deploy the site to Netlify
| Adding .Rprofile to set options() for blogdown
― The new site is ready
○ To start a local preview: use blogdown::serve_site(), or the RStudio add-in "Serve Site"
○ To stop a local preview: use blogdown::stop_server(), or restart your R session
► Want to serve and preview the site now? (y/n) y
Launching the server via the command:
  /Users/benjaminsmith/Library/Application Support/Hugo/0.74.3/hugo server --bind 127.0.0.1 -p 4901 --themesDir themes -t starter-hugo-academic -D -F --navigateToChanged
Serving the directory . at http://localhost:4901
Launched the hugo server in the background (process ID: 39241). To stop it, call blogdown::stop_server() or restart the R session.
Rendering content/post/2020-12-01-r-rmarkdown/index.Rmd... Done.

I wondered if it could be an RStudio View Panel problem. I dont' think so, because the problem affects in-browser view as well, but just in case, I tried:

plot(c(1,2,3))

This correctly renders a plot with 3 data points on it in the View Panel.

I ran the following commands trying to see if anything made a difference, but the results were more or less the same:

blogdown::serve_site()
blogdown::check_site()
blogdown::stop_server()
blogdown::serve_site()
xfun::session_info('blogdown')

check_site gives the following output:

> blogdown::check_site()
― Running a series of automated checks for your blogdown website project...
---------------------------------------------------------------------------------------------
○ A successful check looks like this.
● [TODO] A check that needs your attention looks like this.
| Let's check out your blogdown site!
---------------------------------------------------------------------------------------------
― Checking config.yaml
| Checking "baseURL" setting for Hugo...
● [TODO] Set "baseURL" to "/" if you do not yet have a domain.
| Checking "ignoreFiles" setting for Hugo...
● [TODO] Set "ignoreFiles" to ["\\.Rmd$", "\\.Rmarkdown$", "_cache$"]
| Checking setting for Hugo's Markdown renderer...
| You are using the Markdown renderer 'goldmark'.
● [TODO] Allow goldmark to render raw HTML by adding this setting to config.yaml (see https://github.com/rstudio/blogdown/issues/447 for more info):

markup:
  goldmark:
    renderer:
      unsafe: true

► Do you want blogdown to set this for you? (y/n) y
― Check complete: config.yaml

― Checking .gitignore
● [TODO] .gitignore was not found. You may want to add this.
― Checking Hugo
| Checking Hugo version...
○ Found 2 versions of Hugo. You are using Hugo 0.74.3.
| Checking .Rprofile for Hugo version used by blogdown...
| Hugo version not set in .Rprofile.
● [TODO] Set options(blogdown.hugo.version = "0.74.3") in .Rprofile and restart R.
― Check complete: Hugo

― Checking netlify.toml...
○ Found HUGO_VERSION = 0.74.3 in [build] context of netlify.toml.
| Checking that remote & local Hugo versions match...
○ It's a match! Local and remote Hugo versions are identical (0.74.3).
| Checking that Netlify & local Hugo publish directories match...
○ Good to go - blogdown and Netlify are using the same publish directory: public
― Check complete: netlify.toml

― Checking content files
| Checking for validity of YAML metadata in posts...
○ All YAML metadata appears to be syntactically valid.
| Checking for previewed content that will not be published...
○ Found 0 files with future publish dates.
○ Found 0 files marked as drafts.
| Checking your R Markdown content...
○ All R Markdown files have been knitted.
○ All R Markdown output files are up to date with their source files.
| Checking for .html/.md files to clean up...
○ Found 0 duplicate .html output files.
○ Found 0 incompatible .html files to clean up.
| Checking for the unnecessary 'content/' directory in theme...
○ Great! Your theme does not contain the content/ directory.
― Check complete: Content

And then session_info:

> xfun::session_info('blogdown')
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6, RStudio 1.3.959

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  base64enc_0.1.3  blogdown_1.9.1   bookdown_0.26    bslib_0.3.1      digest_0.6.29   
  evaluate_0.15    fastmap_1.1.0    fs_1.5.2         glue_1.6.2       graphics_4.0.2  
  grDevices_4.0.2  highr_0.9        htmltools_0.5.2  httpuv_1.6.5     jquerylib_0.1.4 
  jsonlite_1.8.0   knitr_1.39       later_1.3.0      magrittr_2.0.3   methods_4.0.2   
  mime_0.12        promises_1.2.0.1 R6_2.5.1         rappdirs_0.3.3   Rcpp_1.0.8.3    
  rlang_1.0.2      rmarkdown_2.14   sass_0.4.1       servr_0.24       stats_4.0.2     
  stringi_1.7.6    stringr_1.4.0    tinytex_0.38     tools_4.0.2      utils_4.0.2     
  xfun_0.30        yaml_2.3.5      

Hugo version: 0.74.3

Any idea what could be going wrong?

yihui commented 2 years ago

If you have an old site with the wowchemy/academic theme that used to work, it shouldn't be too hard to make it continue to work. The only thing you need to figure out is which Hugo version you were using at that time. Then pin the Hugo version in .Rprofile (follow the tips of blogdown::check_site()). If you don't remember the version now, you may

Then install that version of Hugo with blogdown::install_hugo("THAT_VERSION").

I have felt exhausted to keep up with the academic theme. It's constantly changing. If you must use this theme, that's totally fine---just remember to pin the Hugo version, and never upgrade the theme. Alternatively, you may consider the apero theme (https://github.com/hugo-apero/hugo-apero) if you are to create new sites in the future.

Anyway, thanks for the report! I'll see why the academic theme is broken in blogdown again.

bjsmith commented 2 years ago

Thank you for the tip! I've already upgraded to the latest version of the theme to try to address the issue but it doesn't seem to help. I'll try another theme later today and see if it makes a difference.

bjsmith commented 2 years ago

Just a note to say the problem really is with the theme (as you seem to believe already). I tried blogdown::new_site(theme="hugo-apero/hugo-apero") and that created a functional site.

bjsmith commented 2 years ago

Thank you yihui! Your tip on hugo releases was what I needed to fix my site. The theme was downloaded ~Sep 2017, and after I installed the corresponding hugo version, 0.27, and pointed to it using the .Rprofile file, it all compiles nicely.

bjsmith commented 2 years ago

In case it helps, after having installed hugo 0.98 instead of running in 0.74 as previously, I'm getting different errors. From an empty working directory:

> blogdown::new_site(theme = "wowchemy/starter-hugo-academic")
― Creating your new site
► The directory '.' is not empty. Create the site anyway? (y/n) y
| Installing the theme wowchemy/starter-hugo-academic from github.com
trying URL 'https://github.com/wowchemy/starter-hugo-academic/archive/main.tar.gz'
downloaded 1.8 MB

| Adding the sample post to content/post/2020-12-01-r-rmarkdown/index.Rmd
| Converting all metadata to the YAML format
Error: module "github.com/wowchemy/wowchemy-hugo-modules/wowchemy/v5" not found; either add it as a Hugo Module or store it in "/Users/benjaminsmith/Google Drive/website/www_test4/themes".: module does not exist
| Adding netlify.toml in case you want to deploy the site to Netlify
| Adding .Rprofile to set options() for blogdown
― The new site is ready
○ To start a local preview: use blogdown::serve_site(), or the RStudio add-in "Serve Site"
○ To stop a local preview: use blogdown::stop_server(), or restart your R session
► Want to serve and preview the site now? (y/n) y
Launching the server via the command:
  /Users/benjaminsmith/Library/Application Support/Hugo/0.98.0/hugo server --bind 127.0.0.1 -p 4321 --themesDir themes -t starter-hugo-academic -D -F --navigateToChanged
Error: module "github.com/wowchemy/wowchemy-hugo-modules/wowchemy/v5" not found; either add it as a Hugo Module or store it in "/Users/benjaminsmith/Google Drive/website/www_test4/themes".: module does not exist
bjsmith commented 2 years ago

In any case, I'm just happy to have my old site running in the old version. I'd be happy to close the issue but perhaps you want to deal with it anyway, so I'll leave it for you to decide.

yihui commented 2 years ago

Error: module "github.com/wowchemy/wowchemy-hugo-modules/wowchemy/v5" not found; either add it as a Hugo Module or store it in "/Users/benjaminsmith/Google Drive/website/www_test4/themes".: module does not exist

I've been investigating this problem in the past few hours. I'll close this issue once I figure out a fix.

after I installed the corresponding hugo version, 0.27, and pointed to it using the .Rprofile file, it all compiles nicely

Great! That's what I expected. Thanks for letting me know!

yihui commented 2 years ago

@bjsmith It was not easy to figure out the fix, but I made it anyway. The academic theme should work with blogdown again (although not recommended).

@cderv When you have time, could you add a daily Github action workflow to test a few themes? Currently I'm thinking of these themes but may add more later:

themes = c(
  'hugo-apero/hugo-apero',
  'wowchemy/starter-hugo-academic',
  'wowchemy/starter-research-group',
  'yihui/hugo-prose'
)
for (theme in themes) {
  d = tempfile()
  dir.create(d)
  xfun::in_dir(d, {
    blogdown::new_site(theme = theme, serve = FALSE)
    blogdown::build_site(build_rmd = 'newfile')
  })
  unlink(d, recursive = TRUE)
}

With this workflow, we will know sooner if a theme is broken again in the future (especially the academic theme). Thanks!

bjsmith commented 2 years ago

nice work! I will stick with my existing older version of the academic theme and consider a different theme entirely next time I do a full overhaul.

Also, lovely to virtually meet you after all this time enjoying your blogdown content. Your book on it is wonderfully clear and straightforward. This is not the only website I have running on blogdown. Appreciate all your work!

yihui commented 2 years ago

Thanks for the kind words! It's my great pleasure!

Yes, for older sites with the academic theme, they should continue to work perfectly fine for the years to come, as long as you fix the Hugo version.