【问题标题】:Settings in .yml do not show up in rendered .Rmd.yml 中的设置不会显示在渲染的 .Rmd 中
【发布时间】:2018-04-11 11:50:27
【问题描述】:

我正在创建一个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 文件不显示_site.yml 文件中定义的设置(目录、主题、突出显示等)和 css 样式。页眉和页脚也不显示。 header.html、footer.html和style.css的路径/位置已经过验证。

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

【问题讨论】:

    标签: r r-markdown knitr


    【解决方案1】:

    问题似乎来自使用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
    

    如果您希望从在您的网站中使用 html_documents2 中受益,您应该查看 blogdown

    【讨论】:

      猜你喜欢
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-22
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多