Blogdown 新帖子插件创建但不加载新文件 [英] Blogdown new post addin creates but not loads new file
问题描述
上下文
安装后(参见之前的
<代码>>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
软件包创建者的建议.已检查.
- 启动插件,
blogdown::new_post_addin
被调用. - 这会调用
new_post.R
.源代码可以在以下位置找到:https://github.com/rstudio/blogdown/blob/master/inst/scripts/new_post.R blogdown::new_post()
是 最后调用,带有 更新 输入文本字段,这是在问题的情况下:post\2020-11-04-how-this-site-was-created\index.en.md"new_post()
函数(在 hugo.R) 调用new_content()
带第三个参数,open = FALSE
,表示不会打开文件,只覆盖file
的值变量(此后的路径).在new_post()
的末尾应该打开文件:这是发生错误的地方(通过尝试在错误的位置打开文件,错误的路径).这意味着在new_content()
中必须发生一些不好的事情.new_content()
修改 带有content_file()
的路径.这也是实际创建文件的步骤.content_file()
修改 通过向路径添加前缀来生成由get_config()
生成的路径.get_config()
尝试 extract 配置中某个字段的值,以 Hugo 为例:尝试查找contentDir
.如果这导致 NULL(没有这样的列表项),那么查看另一种可能性并最后返回默认值(在 Hugo:content
的情况下).就是这样!RStudio 尝试打开内容目录中的文件,而不是语言子目录中的文件!- 这意味着最后一个选项在
%n%
行中返回(它是从 knitr 导入的,代表:if (is.null(x)) y else x
).这意味着前面的参数返回 NULL,这意味着在config
变量中找不到 contentDir.config
的默认值由config = load_config()
设置.这使用find_config()
来查找要解析的配置文件. 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:
- 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
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.
- Launching the addin,
blogdown:::new_post_addin
is called. - This calls
new_post.R
. The source code can be find at: https://github.com/rstudio/blogdown/blob/master/inst/scripts/new_post.R blogdown::new_post()
is called at the end, withfile
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"new_post()
function (in hugo.R) callsnew_content()
with the third argument,open = FALSE
, which means it will not open the file, just overwrite the value of thefile
variable (the path hereafter). At the end ofnew_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 innew_content()
.new_content()
modify the path withcontent_file()
. Also this is the step, where the file is actually created.content_file()
modify the path by adding a prefix to it generated byget_config()
.get_config()
tries to extract the value of a field in the configuration, in the case of Hugo: try to findcontentDir
. 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!- 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 inconfig
variable. The default value ofconfig
is set byconfig = load_config()
. This usesfind_config()
to find the config file to parse. find_config()
usesconfig_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屋!