Change right sidebar header in bs4_book (bookdown)?

Viewed 353

I'm using the bs4_book format to set up the framework for a new book project using bookdown. Is there a way to change "On this page" at the top of the right sidebar to "In this chapter"? So far, I haven't been able to find where that text snippet lives.

1 Answers

Here is a solution:

I placed a short JavaScript function in the file local_js.html in the folder with the Rmd chapter files. The contents are:

<script>
    $(function() {
        $("#toc h2").html("In this chapter");
    });
</script>

(Using JQuery 3.5.1)

#toc is the id for the right sidebar contents list, and the heading text is inside the h2 tags.

Then I added the following to the YAML header for the b4_book output:

output: 
  bookdown::bs4_book:
    theme:
      primary: "#637238"
    includes:
      in_header: local_js.html

This seems to work well enough, at least for a book framework that still hasn't got much text or image content in the chapters. I still haven't figured out where the default heading "On this page" is coming from. If anyone knows and can explain how to change it directly, I'd be grateful.

Related