'Bookdown generates index file with a chapter title instead of "index.html" when knitted
I am compiling a long report into a html document with Bookdown and didn't have any problems knitting it with bookdown::gitbook until recently. Not sure what happened.
The code runs without errors, all the plots and files are generated as needed, but the index.rmd is generated into an .html file named after the first heading's id ("chapter00.html"), rather than "index.html". This means it the website does not work when uploaded to github.
Everything works great if the file name is manually changed to "index.html".
My index.rmd file looks as follows:
---
title: "Eesti inimarengu aruanne 2019"
author: "Eesti Koostöö Kogu"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [bibliography/bib_chapter23.bib, bibliography/bib_chapterXY.bib]
biblio-style: authoryear
biblatexoptions: [refsegment=chapter]
csl: keel-ja-kirjandus.csl
link-citations: yes
description: "Eesti inimarengu aruanne 2019"
css: eia.css
lang: et
---
# Sissejuhatus {-#chapter00 .chapter_section .intro_section}
_bookdown.yml file is as follows:
book_filename: "EIA_2019_digi"
language:
label:
fig: 'Joonis '
tab: 'Tabel '
eq: 'Valem '
ui:
chapter_name: ""
delete_merged_file: true
_output.yml is as follows:
bookdown::gitbook:
split_by: section
split_bib: yes
config:
toc:
collapse: subsection
scroll_highlight: yes
before: null
after: null
toolbar:
position: fixed
edit : null
download: null
search: yes
sharing:
facebook: no
twitter: no
google: no
linkedin: no
weibo: no
instapaper: no
vk: no
all: ['facebook', 'google', 'twitter', 'linkedin', 'weibo', 'instapaper']
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
Any insight about what may cause the problem? Thanks!
Solution 1:[1]
The problem is that you are knitting your bookdown project, when you should render it with bookdown. In the R console:
bookdown::render_book("index.Rmd")
Check the last line of your output is something like
Output created: docs/index.html
[1] "/my/path/mybook/docs/index.html"
That should generate an index.html file from your index.rmd file
(And remember to set Source master branch/docs folder under Settings > Github Pages if you are using github.io to publish)
Solution 2:[2]
I had this problem in a project where I included chapters written in .md files using this approach:
in _bookdown.yml:
book_filename: "PGDEPhysics"
language:
ui:
chapter_name: ""
appendix_name: "Appendix "
delete_merged_file: true
output_dir: "docs"
rmd_files: [
'index.Rmd'
,'content.Rmd'
,'appendix.Rmd'
,'bibliography.Rmd'
]
the file content.Rmd:
```{r content, echo=FALSE}
library(fs)
cvec = dir_ls("Content", regexp = "^(.+).md$")
```
```{r child = cvec}
```
If the first file in the Content folder begins with a top-level heading:
# The first chapter
Everything is fine, and bookdown outputs an index.html file as required. If that first heading the first file starts with a subheading:
## The first chapter
Then we see this in the output:
Output created: docs/welcome.html
instead of the required:
Output created: docs/index.html
('Welcome' is the first top-level heading in index.Rmd)
Solution for me is to just live with it, and have that first .md file begin with a top-level heading.
The difficulty with this feature is that the problem is not noticed at the point it is introduced unless you are clearing out the target folder (in my case, docs) each time you build the book, because an older version of index.html may remain there and the site looks fine during development. The build process only adds files, it doesn't delete them from the target folder.
Best practice workflow, then, is to delete the target folder before you build.
Solution 3:[3]
I had experienced this problem, and I can actually reproduce it in a particular way, which doesn't appear to be exactly the same as yours. If I don't keep any actual content or a markdown header in the index.Rmd file, then the rendered HTML file is named after the first header in the next Rmd file. If I put just one header in the index.Rmd file, then it renders to index.html
Solution 4:[4]
It also can happen if the first chapter (index.Rmd) has more than one level one header (#)
Solution 5:[5]
This happened to me as well when including index.Rmd from a location not in the project directory. Moving the file fixed the naming problem.
For instance, I originally had the file in a subdirectory (e.g., doc/index.Rmd) and included this in _bookdown.yml: rmd_files: ["doc/index.Rmd", "doc/introduction.Rmd"]. This led to the output file being introduction.html.
Moving index.Rmd to the root directory and using rmd_files: ["index.Rmd"] led to the output file being index.html.
Note that it seems that removing index.Rmd from _bookdown.yml (i.e., rmd_files: ["doc/introduction.Rmd"]), also leads to an output of introduction.html.
Solution 6:[6]
You can only have one yaml header. If you have more then one, than the last one overwrites the main title.
See: https://bookdown.org/yihui/rmarkdown/bookdown-project.html#bookdown-project
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Idiot Tom |
| Solution 2 | NixImagery |
| Solution 3 | Abhijit |
| Solution 4 | Ferroao |
| Solution 5 | shir |
| Solution 6 | kabr |
