mtn / cocoa-eh-hugo-theme

A enhanced version of Cocoa. Clean, fast, and responsive theme with cool typography.
https://themes.gohugo.io/theme/cocoa-eh-hugo-theme/
MIT License
224 stars 111 forks source link

Add optional table of contents for blog posts #105

Open danyspin97 opened 6 years ago

mtn commented 6 years ago
screen shot 2018-09-16 at 9 49 51 pm

Is this what it's supposed to look like?

I think the concept is useful, but there should be some styling before this is merged. Any thoughts?

Thanks for your work in initiating this! 🎈

mtn commented 6 years ago

I also think this might be a better as a post-level parameter.

danyspin97 commented 6 years ago

screenshot_2018-09-17_13-27-04

Strange, it should look like this. I'll investigate this.

danyspin97 commented 6 years ago

It should be fixed now. Let me explain better how it works now. It gets all the line that are formatted as h[1-4] and put them in the same level in the table of contents, that is enabled by adding toc: true in the post parameters and it is disabled by default.

The original snippet tried to understand the level number and insert relative nested lists. The wanted result was something like this:

If you prefer to have the table of contents formatted as this last example, I don't mind working to achieve this last example, but I would prefer to have it simple as it is currently.

mtn commented 6 years ago

Hm, it seems kind of strange to flatten the table of contents, at least without offering both as an option. By default, I'd think it'd be better to retain information about the structure of the post.

But I don't want to make this too much of a burden either. We could merge this, and allow it to be enabled with a flag like flat-toc and then possibly add a hierarchical toc in the future.

danyspin97 commented 6 years ago

Improved! Now the table of contents respect the paragraph level, as the original post. I needed to add some css to remove blank lines between the levels. It also reads all the section from h2 to h4. I've a left the button "Table of Contents" as the original gist.