template/book/exercises/002.md
Tom van Woudenberg dc4e7fbf5b fix formatting
2024-12-13 16:48:50 +01:00

3.6 KiB

Exercise 2: Add a new file to the table of contents

Let's continue by adding one additional step. Let's add a file to the table of contents! the _toc.yml contains a list of all the files to be shown in your book-website. Let's create a new file and add it to that list!

Can you create a file named my_first_file.md and add it successfully to the book?

  1. Go to the /book directory of your GitHub repository and add a file (https://github.com/<your_username>/<your_repo_name>) - {octicon}code;1em Code - Book - intro.md - Add file - {octicon}plus;1em Create new file
  2. Name your file my_first_file.md. Don't forget the .md!
  3. In the Edit field, start the first line with the header of your page (each file needs to have a header which will be the title shown in the table of contents):
# Title of my first file
  1. On a new line, add some more text so that you end up with something like:
# Title of my first file
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean id diam non mauris auctor sollicitudin. Ut quis nunc lobortis, iaculis massa id, eleifend justo. Nulla ac auctor sapien. Etiam sit amet est a ex vestibulum porta. Nulla non lacus a purus luctus blandit sit amet non nibh. Curabitur vitae cursus dolor. Ut eu nisi nec enim ullamcorper fermentum.
  1. Want to view all the text without horizontal scrolling? Click No wrap and select Soft wrap
  2. Click Commit changes
  3. Add a message and description of your change
  4. Select Commit directly to the main branch (this adds your change your change to the default version instead of making a new one)
  5. Click Commit changes
  6. Go to the the file book/_toc.yml on your GitHub repository (https://github.com/<your_username>/<your_repo_name>) - {octicon}code;1em Code - Book - _toc.yml - {octicon}pencil;1em Edit this file
  7. Add this file as a second item in the Some content chapter
:class: tip, dropdown
Your `_toc.yml` should look like
```yaml
format: jb-book
root: intro.md

parts:
  - caption: Contents
    chapters:
    - file: some_content/overview.md
      sections:
      - file: some_content/text_and_code.ipynb
      - file: my_first_file.md
    - file: exercises/exercises
      sections:
      - file: exercises/001.md
      - file: exercises/002.md
      - file: exercises/003.md
      - file: exercises/004.md
      - file: exercises/005.md
      - file: exercises/006.md
    - file: references.md
    - file: changelog.md
    - file: credits.md
```
  1. Click Commit changes
  2. Add a message and description of your change
  3. Select Commit directly to the main branch (this adds your change your change to the default version instead of making a new one)
  4. Click Commit changes
  5. Go to {octicon}play;1em Actions - The most recent workflow run Update _toc.yml / the commit message of the commit you just made - Wait for it to finish - In the summary, click on the link of your book shown in the table Branches deployed and under Primary book at root (getting bored of waiting? There'll be exercising on doing this locally which prevents you from waiting)
  6. Do you see your change? If you don't see it click CTRL+F5/Control+F5to refresh the page.
:class: note

Before moving on to the next exercise, make sure you understand the following:
- Are all files in the repository added to the website?
- How many commits does it take to add a file online?
- What needs to be on a page at least to be edit to the book?
- What is the purpose of the `_toc.yml` file?