Skip to content
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

FR: Table of Contents #120

Closed
stevenroose opened this issue Aug 28, 2023 · 4 comments · Fixed by #121
Closed

FR: Table of Contents #120

stevenroose opened this issue Aug 28, 2023 · 4 comments · Fixed by #121
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@stevenroose
Copy link
Contributor

I see some themes have table of contents with like anchors for all the headings that optionally can be added in front of either a blog post of any page. I'd be very interested in having this 🙏

@stevenroose stevenroose added the enhancement New feature or request label Aug 28, 2023
@stevenroose
Copy link
Contributor Author

Oh, I see that it is already provided as an [extra] field, but not documented :)

Then maybe change this in an issue to move the field to the top-level front-matter because it seems that Zola supports this field natively.

You could support both I guess. Maybe I can fix that.

@stevenroose
Copy link
Contributor Author

Wait, I'm confused, I see this line

51:        {% if page.extra.toc | default(value=false) and page.toc %}

What does that do/mean exactly? I thought the top-level toc field was a boolean too (because the page I linked does if page.toc { but I guess that check just checks if the variable is provided.

So the extra.toc boolean is necessary and we can't use the top-level toc fields?

@welpo welpo added documentation Improvements or additions to documentation question Further information is requested and removed enhancement New feature or request labels Aug 28, 2023
@welpo
Copy link
Owner

welpo commented Aug 28, 2023

Hey Steven!

  • page.extra.toc is tabi's own boolean value to enable the ToC at the top of the page.

  • page.toc is an array of Header objects that Zola generates automatically based on the headings in the markdown content. Each Header object has a few fields.

The line of code you shared is checking whether two conditions are met:

  1. page.extra.toc = true: the ToC should be rendered at the top of the article (defaults to false)
  2. page.toc: the page actually has a ToC (the array of Header). It will evaluate tofalse if it doesn't.

It's important to check the second part because not all pages have ToCs. For example, this page has no headers in the article, so it doesn't get a page.toc.

Zola doesn't actually have a built-in ToC. The page you linked simply shows an example as to how it could be implemented. In tabi, the ToC is built by the table_of_contents.html macro.

I'm glad you found the documentation on the theme's demo. In the future, I plan on adding a long page explaining all of tabi's features (both in config.toml and within the [extra] section of post's front matter).

@welpo welpo closed this as completed Aug 28, 2023
welpo added a commit that referenced this issue Sep 6, 2023
@welpo
Copy link
Owner

welpo commented Sep 18, 2023

The guide to all of tabi's settings is live! Check it out: Mastering tabi Settings: A Comprehensive Guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants