forked from poldham/minute_website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structure.Rmd
103 lines (76 loc) · 3.44 KB
/
structure.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: "Understanding Site Structure"
author: "Paul Oldham"
date: "30/08/2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
In RStudio web pages are built from the Rmarkdown (.Rmd) files. So,
- index.Rmd becomes index.html
- writepage.Rmd becomes writepage.html
When we use the Build button, the rmarkdown files are converted to html. Those html files become the pages of the website in the site structure.
The structure of the site is contained in the file `_site.yml`. It looks like this.
```{r eval=FALSE}
name: "Create a simple Rmarkdown website"
output:
html_document:
theme: cosmo
#highlight: textmate
navbar:
left:
- text: "Home"
href: index.html
- text: "Next Steps"
menu:
- text: "Writing Pages"
href: writepage.html
- text: "Include Images"
href: images.html
- text: "Embed a webpage"
href: embed.html
- text: "Embed an infographic"
href: info.html
- text: "Change the Structure"
menu:
- text: "Site structure"
href: structure.html
- text: "Publish to Github"
menu:
- text: "publish"
href: publish.html
- text: "submenu item"
href: yourfile.html
output_dir: "."
```
### The basics
The site structure starts with the name of the site. Then we have the output as html_document and a theme. For available themes see the [RStudio](http://rmarkdown.rstudio.com/html_document_format.html) websites section. You can also choose the text highlight option (commented out with # here).
Next comes location of the navigation bar.
### The index file
All websites must have an index file. In this case the `- text:` provides the instruction on what to call the menu item `"Home"`. Below that we have the reference to the html file that corresponds with home. To build a website on GitHub you must have an index file, so this goes here.
An important point here is that the indents matter. If they are slightly out the site will create an error or not display properly. Use the tab key to make sure things are properly aligned.
```{r eval=FALSE}
- text: "Home"
href: index.html
```
### Menus and sub menus
To create sub-menus on the navigation bar we start by giving the text that we want to see in the menu. Next we specify that this is a menu and then indent the pages that appear under the menu with text and href.
```{r eval=FALSE}
- text: "Next Steps"
menu:
- text: "Writing Pages"
href: mypage.html
- text: "Include Images"
href: images.html
- text: "Embed a webpage"
href: embed.html
- text: "Embed an infographic"
href: info.html
```
If we want a new sub-menu we simply repeat the above with the relevant titles and links to the html files.
The most important things to remember here are:
- The indents above really matter. If the site will not build it is probably because the indents of - text and href are not aligned.
- The file names matter. If the markdown file is called info1 it will rended as info1.html. If you put info.html into the structure then the `_site.yml` will not find info1.html and that will cause a problem.
## output_dir
This is set to "." if you want to publish the site on GitHub. For other options see the [Publishing Websites](http://rmarkdown.rstudio.com/rmarkdown_websites.html#publishing_websites) section of the RStudio guide.