-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
documentation on toc depth #1357
Comments
If I explore the code of function, the only place I can see the source of Line 304 in 42dbedc
which means that the information should be added in toc:
depth: 3 This is what I did, but there is no effect on the TOC in pkgdown. # Create fake package
temp_dir <- tempdir()
pkg_path <- file.path(temp_dir, "fake.pkg")
dir.create(pkg_path)
usethis::create_package(path = pkg_path, open = FALSE)
# Create meta yaml
yaml_file <- file.path(pkg_path, ".pkgdown.yml")
cat("toc:
depth: 4", file = yaml_file)
# Create vignette with multiple titles
dir.create(file.path(pkg_path, "vignettes"))
cat('---
title: "Title"
author: "Sébastien Rochette"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\\VignetteIndexEntry{Title}
%\\VignetteEngine{knitr::rmarkdown}
%\\VignetteEncoding{UTF-8}
---
# Title 1a
## Title 2a
### Title 3a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
### Title 3b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
## Title 2b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
# Title 1b
## Title 2a
### Title 3a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
### Title 3b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
## Title 2b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
# Title 1c
## Title 2a
### Title 3a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
#### Title 4a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
#### Title 4b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
#### Title 4a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
### Title 3b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
## Title 2b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
', file = file.path(pkg_path, "vignettes", "my_vignette.Rmd"))
# Build pkgdown
pkgdown::build_site(pkg = pkg_path) |
This option has no effect because bootstrap-toc now generates the TOC. We should remove the option. You might be able to achieve the behavior by modifying the TOC scope; you would place relevant code in |
Thank you for the answer. I am not enough comfortable with Javascript. # Create fake package
temp_dir <- tempdir()
pkg_path <- file.path(temp_dir, "fake.pkg")
dir.create(pkg_path)
usethis::create_package(path = pkg_path, open = TRUE)
# Create meta yaml
yaml_file <- file.path(pkg_path, ".pkgdown.yml")
cat("toc:
depth: 4", file = yaml_file)
# Create vignette with multiple titles
dir.create(file.path(pkg_path, "vignettes"))
cat('---
title: "Title"
author: "Sébastien Rochette"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\\VignetteIndexEntry{Title}
%\\VignetteEngine{knitr::rmarkdown}
%\\VignetteEncoding{UTF-8}
---
# Title 1a
## Title 2a
### Title 3a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
### Title 3b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
## Title 2b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
# Title 1b
## Title 2a
### Title 3a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
### Title 3b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
## Title 2b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
# Title 1c
## Title 2a
### Title 3a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
#### Title 4a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
#### Title 4b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
#### Title 4a
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
### Title 3b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
## Title 2b
', paste(sample(c(" ", letters), 300, replace = TRUE), collapse = "") , '
', file = file.path(pkg_path, "vignettes", "my_vignette.Rmd"))
# Change TOC
dir.create(file.path(pkg_path, "pkgdown"))
cat('(function($) {
$(function() {
var navSelector = "#toc";
var $myNav = $(navSelector);
Toc.init({$scope: $("h3")});
$("body").scrollspy({
target: navSelector
});
});
})(window.jQuery || window.$);
', file = file.path(pkg_path, "pkgdown", "extra.js"))
# Build pkgdown
pkgdown::build_site(pkg = pkg_path) |
@statnmap bootstrap-toc doesn't support more than two levels in the TOC afeld/bootstrap-toc#27 so unless pkgdown no longer uses bootstrap-toc one day, it is not possible to change the TOC depth. |
FYI @maelle the vignette still says it's possible : https://pkgdown.r-lib.org/reference/build_articles.html |
@moodymudskipper those changes will only appear in the dev docs for now: https://pkgdown.r-lib.org/dev/reference/build_articles.html |
There are several PRs that attempt to implement a depth > 2 in bootstrap-toc:
But no reaction on those from the author. The project appears to basically be deprecated/unmaintained for several years now. So the best way forward would probably be to
|
I see in the documentation that we can define the toc depth in articles: https://pkgdown.r-lib.org/reference/build_articles.html
I tried to add this option directly in my _pkgdown.yml, also in the yaml header of my vignette, but it seems there is no effect.
Could you add a little more information in the documentation of this "build_articles()" function to know exactly where to add this option ?
The text was updated successfully, but these errors were encountered: