10.5.3.1 Content
Typically when creating a website, there are various common elements you want to include on all pages (e.g., output options, CSS styles, header and footer elements, etc.). Here are additions in three files to the example above to make use of common elements:
_site.yml:name: "my-website" navbar: title: "My Website" left: - text: "Home" href: index.html - text: "About" href: about.html output: html_document: theme: cosmo highlight: textmate include: after_body: footer.html css: styles.cssfooter.html:<p>Copyright © 2016 Skynet, Inc. All rights reserved.</p>styles.cssblockquote { font-style: italic }
Note that we have included an output element within our _site.yml file. This defines shared output options for all R Markdown documents within a site. Note that individual documents can also include their own output options, which will be merged with the common options at render time.
As part of our common output options, we have specified an HTML footer (via the include: after-body: option) and a CSS stylesheet. You can also include HTML before the body or in the document’s <head> tag (see Section 3.1.10.2).
In addition to whatever common options you define, there are two output options that are automatically set when rendering a site:
The
self_containedoption is setFALSE; andThe
lib_diroption is set tosite_libs.
These options are set so that dependent files (e.g., jQuery, Bootstrap, and HTML widget libraries) are shared across all documents within the site rather than redundantly embedded within each document.