.yml 中的设置不会显示在呈现的 .Rmd 中

Settings in .yml do not show up in rendered .Rmd

我正在创建一个 R Markdown website。但是,我在设置文档输出样式的样式时遇到问题。

我的 _site.yml 输出参数如下所示:

output:
  bookdown::html_document2:
    toc: true
    toc_float: true
    theme: flatly
    highlight: tango
    df_print: paged
    include:
      in_header: "header.html"
      after_body: "footer.html"
    css: "./assets/style.css"

我在同一目录中有几个 .Rmd 文件,它们具有简单的 YAML 问题:

---
title: "A title"
subtitle: "A subtitle"
author: "Name"
---

我渲染网站 rmarkdown::render_site()。站点和页面工作,但呈现的 .Rmd 文件不显示 [=12= 中定义的设置(目录、主题、突出显示等)和 css 样式] 文件。页眉和页脚也不显示。 header.html、footer.html、style.css的path/location已验证

我是否必须在每个 .Rmd 文件中指定输出设置?

问题似乎来自使用 bookdown::html_document2 而不是 rmarkdown 函数 html_document

使用 RStudio here 提供的模板,我对设置进行了一些编辑,添加了 theme: flatly:

name: "my-website"
navbar:
  title: "My Website"
  left:
    - text: "Home"
      href: index.html
    - text: "About"
      href: about.html
output:
  html_document:
    highlight: textmate
    theme: flatly
    include:
      after_body: footer.html
    css: styles.css

html_document 替换为 bookdown::html_document2()

查看 render_site 函数的 source code,除了 html_document 之外,它似乎无法解析任何其他输出。实际上,当提供bookdown::html_document2()时,它会将_site.yml文件覆盖为:

name: my-website
navbar:
  title: My Website
  left:
  - text: Home
    href: index.html
  - text: About
    href: about.html
output:
  html_document:
    lib_dir: site_libs
    self_contained: no
output_dir: _site

If you are looking to benefit from using html_documents2 within your website, you should check out blogdown.