I’m using Ghost Pro and the Solo Theme. I followed the tutorial on the developer site to add table of contents to my site I just started. However, the table of contents is doing two things wrong:
Its using my name as the table of contents header. How do I avoid this?
The table of contents is displaying behind the author meta data on the left. Is there a way to move it below or to the right of the article?
Because Solo has a different setup than Casper, you’ll need to do some modifications to get the table of contents working.
The author metadata section is included in gh-content, and the author name is an h4, which explains why it’s included in your TOC. Tocbot includes an ignore selector option that you could use to exclude author name.
This is again because of Solo’s layout, which includes the author metadata in the content section. You’ll need to customize the CSS for the TOC or change where it’s rendered.
It looks like you’re trying out a new library. Let us know if that works better for you.
The first thing I would do if you want to use tocbot is to add some content to your site with headings, so it’s easier to see how things are working (or not). That way, we can test some things out and see what works and what doesn’t.
But I went back to the Ghost.org tutorial and implemented that. I’m glad I figured out the H4 thing which is below for anyone else who is having that issue.
<script>
tocbot.init({
// Where to render the table of contents.
tocSelector: '.gh-toc',
// Where to grab the headings to build the table of contents.
contentSelector: '.gh-content',
// Which headings to grab inside of the contentSelector element.
headingSelector: 'h2, h3',
// Ensure correct positioning
hasInnerContainers: true,
});
</script>
Now I just need it pushed below the author metadata somehow, or shown to the right of the article (preferred).
I figured it all out. For others who wish to do this:
@media (min-width: 1300px) {
.gh-sidebar {
position: absolute;
right: 0;
top: 0;
bottom: 0;
margin-top: 4vmin;
grid-column: wide-start / main-start; /* Place the TOC to the left of the content */
}
.gh-toc {
position: sticky; /* On larger screens, TOC will stay in the same spot on the page */
top: 7vmin;
}
}
Now I just need to figure out how to make the vertical list lines go to the right of the wording and add a table of contents header text above the list…
Have you figured out how to put the TOC on the right. I firstly thought the trick is on the grid-column of the below block. It turns out that modifying this is not enough. I am not very familiar with the Ghost template languages. Hopefully you can advise if you or anyone else figure it out. THX.
@media (min-width: 1300px) {
.gh-sidebar {
position: absolute;
top: 0;
bottom: 0;
margin-top: 4vmin;
grid-column: main-end / wide-end; /* Place the TOC to the left of the content */
}