The Academic theme for Hugo has support for automatic tables of contents when using the docs
page type. (See their live example here.)
By enabling toc: true
in the YAML front matter of a document page (i.e. with type: docs
), a TOC appears on the right side of the page.
However, this seems to only work on vanilla .md
files. If you enable this on an R Markdown page, the TOC area is empty and there's an errant "true" under the title, presumably because the toc: true
from the YAML front matter somehow gets partially rendered as HTML
Is there a way to use Hugo / Academic's automatic ToC creation with R Markdown files? It seems like this might be a bug, since the YAML value appears in the HTML, but I'm not sure where to even start debugging.
This is reproducible by doing the following:
-
Create a new example blogdown/Hugo site with the academic theme:
blogdown::new_site(theme = "gcushen/hugo-academic", theme_example = TRUE)
-
Rename
content/courses/example/example2.md
tocontent/courses/example/example2.Rmd
-
Run
blogdown:::serve_site()
and go to http://localhost:4321/courses/example/example1/ and http://localhost:4321/courses/example/example2/ and note the differences.
The only workaround I've found is to not use Hugo's TOC capabilities (by removing the toc: BLAH
entry entirely) and instead include this in the YAML front matter:
output:
blogdown::html_page:
toc: true
This add knitr's own TOC at the top of the page, but not in the sidebar, which is less than ideal.