Blogdown new post addin creates but not loads new file

霸气de小男生 提交于 2021-01-28 08:00:16

问题


Context

After installed (see previous post) and configured my personal Hugo website for a multilingual setup (by directories), I wanted to start creating content. Ideally, I wanted to use blogdown in RStudio, via the addins. The website uses the Academic theme, rebranded now as Wowchemy.

The content directory tree is as follows:

content
|
├── en
    ├── authors
    ├── files (for static files)
    ├── home (homepage widgets)
    ├── post
    ├── project
    └── resources
|
└── hu
    ├── authors
    ├── files (for static files)
    ├── home (homepage widgets)
    ├── post
    ├── project
    └── resources

Multilingual setup references:

  • Hugo Multilingual Part 1: Content translation - general overview, with managing content translations by directories and page bundles
  • Start a Multi Language Blog with Hugo on Github Pages - for basic config.toml settings and highlighting the use of partials
  • Light/Dark/Automatic translation - for getting to know how to make modification in interface translations (although do not know how to share it with the themes repo)
  • How can I add credits by the end of the page? - for translating the footers of the webpages (which is not a content and can not be set in any config file), through partials.

Problem

When I use the new post addin in RStudio, the file is created in place, but does not open automatically for editing. The English and Hungarian language setting both works the same way.

> blogdown:::new_post_addin()

Listening on http://127.0.0.1:6918
C:\Users\HP\Documents\R\website\content\en\post\2020-11-04-how-this-site-was-created\index.en.md created
Warning in file(con, "r") :
  cannot open file 'content/post/2020-11-04-how-this-site-was-created/index.en.md': No such file or directory
Warning: Error in file: cannot open the connection
  91: file
  90: readLines
  87: hugo_convert_one
  86: new_content
  85: blogdown::new_post
  84: observeEventHandler
  13: shiny::runApp
  12: shiny::runGadget
  11: eval
  10: eval
   4: eval
   3: eval
   2: sys.source
   1: blogdown:::new_post_addin

Question

How can this be resolved? As far as I see, something has to be with the file path after creating the file, because the file is created in the right place.

Configuration

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Hungarian_Hungary.1250  LC_CTYPE=Hungarian_Hungary.1250   
[3] LC_MONETARY=Hungarian_Hungary.1250 LC_NUMERIC=C                      
[5] LC_TIME=Hungarian_Hungary.1250    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.5.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5      bookdown_0.21   crayon_1.3.4    digest_0.6.26   later_1.1.0.1  
 [6] mime_0.9        R6_2.4.1        jsonlite_1.7.1  xtable_1.8-4    magrittr_1.5   
[11] evaluate_0.14   blogdown_0.21   rlang_0.4.8     rstudioapi_0.11 miniUI_0.1.1.1 
[16] promises_1.1.1  rmarkdown_2.4   tools_4.0.3     tinytex_0.26    fastmap_1.0.1  
[21] httpuv_1.5.4    xfun_0.18       yaml_2.2.1      compiler_4.0.3  htmltools_0.5.0
[26] knitr_1.30

回答1:


I am not good at using the debug tools, so just stepped through the code. (Appreciate the suggestion of good tutorials!)

First things first: When in Doubt, Try to Upgrade Your Software Packages This is the blogdown package creator's advice. Checked.

  1. Launching the addin, blogdown:::new_post_addin is called.
  2. This calls new_post.R. The source code can be find at: https://github.com/rstudio/blogdown/blob/master/inst/scripts/new_post.R
  3. blogdown::new_post() is called at the end, with file parameter from the updated input text field, which is in the case of the question: "post\2020-11-04-how-this-site-was-created\index.en.md"
  4. new_post() function (in hugo.R) calls new_content() with the third argument, open = FALSE, which means it will not open the file, just overwrite the value of the file variable (the path hereafter). At the end of new_post() the file should be opened: this is where the error occurs (by trying to open the file at the wrong place, a wrong path). This means that something bad has to happen in new_content().
  5. new_content() modify the path with content_file(). Also this is the step, where the file is actually created.
  6. content_file() modify the path by adding a prefix to it generated by get_config().
  7. get_config() tries to extract the value of a field in the configuration, in the case of Hugo: try to find contentDir. If this results in NULL (there's no such list item), then see the other possibility and lastly return the default value (which is in the case of Hugo: content). And that's it! RStudio tries to open a file in the content directory, not in a language subdirectory!
  8. That means that the last option is returned in the row of %n% (which is imported from knitr and stands for: if (is.null(x)) y else x). That means that the previous arguments returned NULL, which means contentDir cannot be found in config variable. The default value of config is set by config = load_config(). This uses find_config() to find the config file to parse.
  9. find_config() uses config_files() to set the value in case of Hugo: c('config.toml', 'config.yaml'). But my setting is in a subdirectory: in the /config/default_/languages.toml file! Oh, another Academic theme woe...

To conclude this: blogdown is currently loads only the config.toml in the root directory to check the contentDir value. The Academic, now Wowchemy Hugo theme however keep config files in the /config/default_/ directory also, where the languages.toml contains the needed value.

To keep or not to keep Academic theme? Stick with blogdown or not? Maybe the config files should be merged into one config.toml, but couldn't find hint or examples for Academic on the web.

Edit: OK, the root of the problem has been found, but the actual error which raised the error message is in connection with hugo_convert_one(), as the traceback suggests in the question. This was the first (and last) try to open the file of the wrong path.



来源:https://stackoverflow.com/questions/64688201/blogdown-new-post-addin-creates-but-not-loads-new-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!