Consider the following MWE. By placing the following three files into a folder, opening the file index.Rmd in RStudio, and running the following command in the Console:
bookdown::render_book()
you'll get an HTML book made with bookdown in a separate subfolder "book". Below are the three files of this MWE.
index.RMD:
---
title: "MWE"
documentclass: book
output:
bookdown::gitbook: default
author: John Doe
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Preface
This is the preface.
01-chapter_one.Rmd:
# First chapter
This is the first chapter.
_bookdown.yml:
output_dir: "book"
delete_merged_file: true
My question: is there any way to add a custom link to the sidebar? For instance, let's say that we wanted a link to the French version of the HTML book, so that when the user clicks on that link, they would be taken to an entirely different bookdown book and home page. I will try and describe the result I'm desiring in the following image:
It is quite possible to insert things into the TOC as part of the build process. You can put them before or after.
You can find the feature documented in the bookdown documentation here. Here is the relevant text:
You may add more items before and after the TOC using the HTML tag
<li>
. These items will be separated from the TOC using a horizontal divider. You can use the pipe character | so that you do not need to escape any characters in these items following the YAML syntax...
Here is some example code for your index.Rmd file that shows how to insert multiple lines of html including links and images above the TOC.
output:
bookdown::gitbook:
config:
toc:
scroll_highlight: yes
before: |
<li><a href="https://www.example.com"><img src="/images/booklogo.png" width="260"></a></li>
<li><a href="./">Book Title — Book Author</a></li>
after: |
<li><a href="https://github.com/rstudio/bookdown">Proudly published with bookdown</a></li>