微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于创建新帖子的 Rmarkdown 插件不起作用

如何解决用于创建新帖子的 Rmarkdown 插件不起作用

今天我想为我的网站创建一个新帖子(使用 blogdown 构建),但新帖子插件似乎不起作用。 当我选择“新帖子”或运行

blogdown:::new_post_addin()

我收到一个错误

Error in FUN(X[[i]],...) : subscript out of bounds
In addition: Warning messages:
1: In value[[3L]](cond) :
  Cannot parse the YAML Metadata in 'content/photo.md': Scanner error: while scanning an alias at line 3,column 1 did not find expected alphabetic or numeric character at line 3,column 2

2: In value[[3L]](cond) :
  Cannot parse the YAML Metadata in 'content/research.md': Scanner error: while scanning an alias at line 4,column 1 did not find expected alphabetic or numeric character at line 4,column 2

我不确定附加警告是关于什么的,但我想关注主要错误。以下是 traceback() 返回的详细信息:

> traceback()
10: lapply(Meta,`[[`,i)
9: unlist(lapply(Meta,i))
8: blogdown:::collect_yaml()
7: eval(exprs[i],envir)
6: eval(exprs[i],envir)
5: sys.source(pkg_file("scripts",file),envir = new.env(parent = globalenv()),keep.source = FALSE)
4: xfun::in_dir(site_root(),expr)
3: in_root(sys.source(pkg_file("scripts",keep.source = FALSE))
2: source_addin("new_post.R")
1: blogdown:::new_post_addin()

有趣的是,当我运行这个命令时:

blogdown::new_post(title,ext = '.md')

它工作正常,我可以创建一个新帖子。我更新了 blogdown 和 Hugo,但无济于事。有人能帮我理解这个错误是什么吗?其他插件(如插入图像)工作正常。

根据要求,Githup 存储库为 https://github.com/msmielak/msmielak.github.io,dput() 输出如下:

>dput(blogdown:::scan_yaml())
list(`content/about.md` = "<img align=\"right\" src=\"/./about_files/rsz_screenshot_2020-12-28_une_home.png\" alt=\"\" width=\"100px\"/>\n\n**2014-**\nPhD candidate at the School of Environmental and Rural Sciences University of New England in ArmiDale,Australia.",`content/code.md` = NULL,`content/contact.md` = NULL,`content/photo.md` = NULL,`content/post/2021-03-29-extracting-date-and-time-from-photo-using-ocr-engine-tesseract/index.md` = list(
        title = "Extracting date and time from camera trap photos using R and tesseract",author = "",date = "2021-03-29",slug = list(),categories = c("code","R"),tags = c("R","code","camera trap","OCR"),description = "",featured = "",featuredalt = "",featuredpath = "",linktitle = ""),`content/research.md` = NULL,`content/technology.md` = NULL)

Warning messages:
1: In value[[3L]](cond) :
  Cannot parse the YAML Metadata in 'content/code.md': Parser error: did not find expected <document start> at line 3,column 67
2: In value[[3L]](cond) :
  Cannot parse the YAML Metadata in 'content/photo.md': Scanner error: while scanning an alias at line 3,column 2

3: In value[[3L]](cond) :
  Cannot parse the YAML Metadata in 'content/research.md': Scanner error: while scanning an alias at line 4,column 2

解决方法

文件 content/about.md 的 YAML 元数据似乎无效。通常 YAML 元数据应采用以下形式:

---
tag1: value1
tag2: value2
---

更新:使用blogdown (>= v1.2.4) 的开发版本,错误将不再出现。此外,blogdown::check_site() 可以检测到此问题并建议用户修复有问题的 YAML 元数据。

remotes::install_github('rstudio/blogdown')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。