rstudio / blogdown

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

Problem using serve_site(): "module "starter-academic" not found" #598

Closed diegouriarte closed 2 years ago

diegouriarte commented 3 years ago

Hi, 02-28 I was able to serve my site using serve_site(). However, today I'm receiving the following error:

> blogdown:::serve_site()
Launching the server via the command:
  C:/Users/diego/AppData/Roaming/Hugo/0.80.0/hugo.exe server --bind 127.0.0.1 -p 4321 --themesDir themes -t starter-academic -D -F --navigateToChanged
Error: module "starter-academic" not found; either add it as a Hugo Module or store it in "C:\\Users\\diego\\Documents\\themes".: module does not exist

I've already updated to the latest dev version but it didn't fixed the issue.

I'm able to build the site using blogdown::hugo_build()

> xfun::session_info('blogdown')
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042), RStudio 1.4.1103
Locale: LC_COLLATE=Spanish_Peru.1252  LC_CTYPE=Spanish_Peru.1252    LC_MONETARY=Spanish_Peru.1252 LC_NUMERIC=C                  LC_TIME=Spanish_Peru.1252    

Package version:
  base64enc_0.1.3   BH_1.75.0.0       blogdown_1.2.1    bookdown_0.21     digest_0.6.27     evaluate_0.14     glue_1.4.2        graphics_4.0.3   
  grDevices_4.0.3   highr_0.8         htmltools_0.5.1.1 httpuv_1.5.5      jsonlite_1.7.2    knitr_1.31        later_1.1.0.1     magrittr_2.0.1   
  markdown_1.1      methods_4.0.3     mime_0.10         promises_1.2.0.1  R6_2.5.0          Rcpp_1.0.6        rlang_0.4.10      rmarkdown_2.7    
  servr_0.21        stats_4.0.3       stringi_1.5.3     stringr_1.4.0     tinytex_0.30      tools_4.0.3       utils_4.0.3       xfun_0.21        
  yaml_2.2.1       

Hugo version: 0.80.0

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

yihui commented 3 years ago

The above checklist says:

  • [x] included a minimal, self-contained, and reproducible example?

but I don't see your reproducible example...

antaldaniel commented 3 years ago

The problem is that current, popular academic theme has the confg file in another directory. There are two ways to solve this.

Either add wowchemy's usual config path to the config_files()in utils.R, or copy the

config_files = function(which = generator()) {
  all = list(
    hugo = c('config.toml', 'config.yaml', file.path( "config", "_default", c('config.toml', 'config.yaml') )),  # only support TOML and YAML (no JSON)
    jekyll = '_config.yml',
    hexo = '_config.yml'
  )
  if (is.null(which)) all else all[[which]]
}

or bring the "lost' config.yaml or config.toml out to the root directory. This an exception for the wowchemy templates, so I do not know which is the more elegant solution.

config_helper <- function( config_dir =  file.path( "config", "_default") ) {

  if ( ! dir.exists ( config_dir) ) {
    warning( config_dir, " does not exist.")
    return(NULL)
  }

  potential_config_files <- file.exists (file.path(config_dir, c('config.toml', 'config.yaml')))

  if (! any(potential_config_files))  {
    warning("No config.toml or config.yaml was found at config_dir='", config_dir, "'")
    return(NULL)
    }

  actual_config_files <- file.path( config_dir, c('config.toml', 'config.yaml') )[potential_config_files]
  message ( "Copying ", actual_config_files, " to the root directory of the project.")

  file.copy (
    from = actual_config_files,
    to = c('config.toml', 'config.yaml')[potential_config_files],
    overwrite = TRUE
    )

 }

For a non-programmatic solution, on a user level, just copy your config.yaml or config.toml to the root directory, too, but do not forget to keep it in synch with config/_default/config.* , probably with regularly running file.copy() with the above parameters.

yihui commented 3 years ago

@antaldaniel Thanks! This has already been done in blogdown::new_site() and blogdown::install_theme() long time ago: https://github.com/rstudio/blogdown/blob/20a8258b39f5cbda7911cc8c0cdb35a4bb31aa52/R/hugo.R#L455-L465

As mentioned in #611, I'll just support the config dir instead of assuming the config file is under the root directory in the near future. Thanks anyway!

yihui commented 2 years ago

FYI the config dir is supported now: https://github.com/rstudio/blogdown/issues/611#issuecomment-962044694 Thanks!