Skip to content

Commit

Permalink
Exclude h1 from TOC (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle authored Apr 2, 2021
1 parent dd9f343 commit 5b5baea
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/build-home-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ data_home_sidebar_links <- function(pkg = ".") {
data_home_toc <- function(pkg) {
sidebar_section(
"Table of contents",
'<nav id="toc" data-toggle="toc" class="sticky-top"></nav>'
'<nav id="toc" class="sticky-top"></nav>'
)
}

Expand Down
5 changes: 5 additions & 0 deletions inst/assets/BS4/pkgdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
offset: 60
});

Toc.init({
$nav: $("#toc"),
$scope: $("h2, h3, h4, h5, h6")
});

// Activate popovers
$('[data-toggle="popover"]').popover({
container: 'body',
Expand Down
2 changes: 1 addition & 1 deletion inst/templates/BS4/content-article.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h4 data-toc-skip class="date">$date$</h4>
<div class="col-md-3 d-none d-md-block" id="sidebar">
$if(toc)$
<div class="sticky-top">
<nav id="toc" data-toggle="toc" >
<nav id="toc">

<h2 data-toc-skip>Contents</h2>

Expand Down
2 changes: 1 addition & 1 deletion inst/templates/BS4/content-news.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1 class="display-4" data-toc-skip>Changelog <small>{{version}}</small></h1>

<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div class="sticky-top">
<nav id="toc" data-toggle="toc" >
<nav id="toc">

<h2 data-toc-skip>Contents</h2>

Expand Down
2 changes: 1 addition & 1 deletion inst/templates/BS4/content-reference-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3 id="{{slug}}" class="hasAnchor"><a href="#{{slug}}" class="anchor"></a>{{sub

<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<div class="sticky-top">
<nav id="toc" data-toggle="toc" >
<nav id="toc">

<h2 data-toc-skip>Contents</h2>

Expand Down
2 changes: 1 addition & 1 deletion inst/templates/BS4/content-reference-topic.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examp
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<div class="sticky-top">
<nav id="toc" data-toggle="toc" >
<nav id="toc">

<h2 data-toc-skip>Contents</h2>

Expand Down
2 changes: 1 addition & 1 deletion inst/templates/BS4/content-title-body.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1 class="display-4">{{pagetitle}}</h1>

<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<div class="sticky-top">
<nav id="toc" data-toggle="toc" >
<nav id="toc">

<h2 data-toc-skip>Contents</h2>

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/data_home_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{html_node}
<div class="table-of-contents">
[1] <h2 data-toc-skip>Table of contents</h2>
[2] <ul class="list-unstyled">\n<li><nav id="toc" data-toggle="toc" class="st ...
[2] <ul class="list-unstyled">\n<li><nav id="toc" class="sticky-top"></nav></ ...

# data_home_sidebar() outputs informative error messages

Expand Down

2 comments on commit 5b5baea

@jayhesselberth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes removed the package versions in the Changelog TOC, it's nicer to have the versions in the TOC for easy nav.

Maybe convert the version sections to h2 instead of h1?

@hadley
Copy link
Member

@hadley hadley commented on 5b5baea Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think they should be <h2> for consistency with the other pages.

Please sign in to comment.