Blogdown 新帖子插件创建但不加载新文件 [英] Blogdown new post addin creates but not loads new file

查看:38
本文介绍了Blogdown 新帖子插件创建但不加载新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文

安装后(参见之前的

<代码>>blogdown:::new_post_addin()听 http://127.0.0.1:6918C:\Users\HP\Documents\R\website\content\en\post\2020-11-04-how-this-site-was-created\index.en.md created文件中的警告(con,r"):无法打开文件content/post/2020-11-04-how-this-site-was-created/index.en.md":没有这样的文件或目录警告:文件错误:无法打开连接91:文件90:读行87:hugo_convert_one86:新内容85:blogdown::new_post84:观察事件处理程序13:闪亮::运行应用程序12:闪亮::运行小工具11:评估10:评估4:评估3:评估2:系统源1: blogdown:::new_post_addin

问题

如何解决?据我所知,创建文件后必须与文件路径有关,因为文件是在正确的位置创建的.

配置

<代码>>会话信息()R 版本 4.0.3 (2020-10-10)平台:x86_64-w64-mingw32/x64(64位)运行于:Windows 7 x64 (build 7601) Service Pack 1矩阵产品:默认语言环境:[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附带的基础包:[1] stats graphics grDevices utils datasets 方法基础其他附加包:[1]闪亮_1.5.0通过命名空间加载(而不是附加):[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

解决方案

我不擅长使用调试工具,所以只是单步调试代码.(欣赏好教程的建议!)

第一件事:当有疑问时,尝试升级您的软件包 这是blogdown 软件包创建者的建议.已检查.

  1. 启动插件,blogdown::new_post_addin 被调用.
  2. 这会调用 new_post.R.源代码可以在以下位置找到:https://github.com/rstudio/blogdown/blob/master/inst/scripts/new_post.R
  3. blogdown::new_post()最后调用,带有 更新 输入文本字段,这是在问题的情况下:post\2020-11-04-how-this-site-was-created\index.en.md"
  4. new_post() 函数(在 hugo.R) 调用 new_content() 带第三个参数,open = FALSE,表示不会打开文件,只覆盖file的值变量(此后的路径).在 new_post() 的末尾应该打开文件:这是发生错误的地方(通过尝试在错误的位置打开文件,错误的路径).这意味着在 new_content() 中必须发生一些不好的事情.
  5. new_content() 修改 带有 content_file() 的路径.这也是实际创建文件的步骤.
  6. content_file() 修改 通过向路径添加前缀来生成由 get_config() 生成的路径.
  7. get_config() 尝试 extract 配置中某个字段的值,以 Hugo 为例:尝试查找 contentDir.如果这导致 NULL(没有这样的列表项),那么查看另一种可能性并最后返回默认值(在 Hugo: content 的情况下).就是这样!RStudio 尝试打开内容目录中的文件,而不是语言子目录中的文件!
  8. 这意味着最后一个选项在 %n% 行中返回(它是从 knitr 导入的,代表:if (is.null(x)) y else x).这意味着前面的参数返回 NULL,这意味着在 config 变量中找不到 contentDir.config 的默认值由 config = load_config() 设置.这使用 find_config() 来查找要解析的配置文件.
  9. find_config() 使用 config_files() 设置 Hugo 的值:c('config.toml', 'config.yaml').但是我的设置在一个子目录中:在 /config/default_/languages.toml 文件中!哦,另一个学术主题的悲哀...

总结一下:blogdown 当前仅加载根目录中的 config.toml 以检查 contentDir 值.Academic,现在是 Wowchemy Hugo 主题也将配置文件保存在 /config/default_/ 目录中,其中 languages.toml 包含所需的值.

保留学术主题还是不保留? 是否坚持使用blogdown? 也许配置文件应该合并到一个配置中.toml,但无法在网络上找到有关 Academic 的提示或示例.

好的,问题的根源已经找到,但引发错误消息的实际错误与hugo_convert_one()有关,作为回溯在问题中建议.这是第一次(也是最后一次)尝试打开错误路径的文件.

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:

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

解决方案

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.

这篇关于Blogdown 新帖子插件创建但不加载新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆