rstudio / blogdown

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

Error building site with Doks theme #716

Closed pensivedog closed 2 years ago

pensivedog commented 2 years ago

Here are the steps to reproduce:

  1. Initiate new blogdown project with Doks theme
  2. In terminal, cd to themes/doks and run npm install to get dependencies, as per the Doks quick start guide
  3. Return to project root directory, initiate git, and make a commit
  4. Use blogdown addin to serve site

The following error occurs:

Error: Error building site: failed to render pages: render of "page" failed: execute of template failed: template: _default/versions.html:25:7: executing "_default/versions.html" at <partial "footer/script-footer.html" .>: error calling partial: "C:\me\dokstest\themes\doks\layouts\partials\footer\script-footer.html:41:23": execute of template failed: template: partials/footer/script-footer.html:41:23: executing "partials/footer/script-footer.html" at <append $flexSearch>: error calling append: reflect: call of reflect.Value.Type on zero Value

Any ideas what could be the problem?

Here are the results of xfun::session_info():

R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044), RStudio 2022.2.3.492

Locale:
  LC_COLLATE=English_United States.utf8 
  LC_CTYPE=English_United States.utf8   
  LC_MONETARY=English_United States.utf8
  LC_NUMERIC=C                          
  LC_TIME=English_United States.utf8    

Package version:
  base64enc_0.1.3  blogdown_1.10.3  bookdown_0.26   
  bslib_0.3.1      cli_3.3.0        compiler_4.2.0  
  digest_0.6.29    evaluate_0.15    fastmap_1.1.0   
  fs_1.5.2         glue_1.6.2       graphics_4.2.0  
  grDevices_4.2.0  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.2.0    mime_0.12        processx_3.5.3  
  promises_1.2.0.1 ps_1.7.0         R6_2.5.1        
  rappdirs_0.3.3   Rcpp_1.0.8.3     rlang_1.0.2     
  rmarkdown_2.14   rstudioapi_0.13  sass_0.4.1      
  servr_0.24       stats_4.2.0      stringi_1.7.6   
  stringr_1.4.0    tinytex_0.39     tools_4.2.0     
  utils_4.2.0      xfun_0.30        yaml_2.3.5
yihui commented 2 years ago

I don't understand this error, but you can follow this theme's guide to create a new site instead of using blogdown::new_site() (e.g., git clone https://github.com/h-enk/doks.git). Then npm install. In the end, create a .Rprofile in the site root and set the Hugo version/path there, e.g.,

options(blogdown.hugo.version = "0.101.0", blogdown.hugo.dir = "node_modules/.bin/hugo")

Restart R, and you should be able to blogdown::serve_site().

pensivedog commented 2 years ago

Works like a charm!

yihui commented 2 years ago

Great! Thanks for letting me know!

pensivedog commented 2 years ago

Separate issue but also related to this theme: blogdown's "New post" addin is not generating correct paths for Doks, similar to this recently fixed issue:

https://github.com/rstudio/blogdown/issues/712#issuecomment-1181223445

pensivedog commented 2 years ago

I'm still trying to figure out how to use this as a theme imported by blogdown when initiating a new blogdown project. This way is preferable because it places the relevant theme files in a themes/doks/ directory, which is in keeping with standard Hugo setups, allowing for easy overriding of some theme files via Theme Components.

The above error mentioned in the original post is related to flexSearch, so I tried setting flexSearch = false in params.toml. That resulted in a similar error for lazySizes, so I set lazySizes = false in params.toml. This continued with clipBoard, instantPage, bootStrapJs, and highLight. After setting each of these to false in params.toml, the site is successfully served, although with limited functionality due to those features being disabled. So it seems the site is having trouble finding those libraries with doks now living in a themes/ directory.

Any suggestions for how to get this working properly?

FWIW, Doks is based on Hyas, which is the starter kit now recommended by Netlify to replace its deprecated Victor Hugo template, so it seems it might be worthwhile finding a way to get these both working smoothly with blogdown as Hugo themes.

yihui commented 2 years ago

blogdown's "New post" addin is not generating correct paths for Doks

I just fixed this problem in the dev version of blogdown. Thanks for the report!

Any suggestions for how to get this working properly?

I suggest you follow the instructions of this theme, instead of using blogdown::new_site() to put the theme under the theme/ directory. This theme seems to be quite different with other themes.

If you want to override anything, I think you can just modify the relevant files directly. I understand that you may be concerned that you may need to update the theme in future, but from my experience, once you have a working site, you probably don't want to pull upstream updates any more (which could break your site).