taikii / whiteplain

Simple and Functional Hugo theme.
https://themes.gohugo.io/whiteplain/
MIT License
132 stars 44 forks source link

Can not show TOC by default #1

Open Honghe opened 6 years ago

Honghe commented 6 years ago

I can not see TOC by default. This is my page: http://localhost:1313/blog/posts/init/ Can you help to explain? Thanks!

image

taikii commented 6 years ago

TOC will be automatically displayed in articles with more than 400 words. But, Hugo can not count word well in Chinese, Korean and Japanese.

If you add toc: true to Front matter of your articles, you can forcibly display TOC.

 ---
 title: "Title of Article"
 date: 2018-01-15T00:04:00+09:00
+toc: true
 ---

By copying themes/whiteplain/layout/partials/toc.html to layout/partcials/toc.html and deleting the if statements, you can display TOC in all articles regardless of the number of words.

-{{- if or .Params.toc (and (gt .WordCount 400 ) (ne .Params.toc "false")) }}
 <aside class="toc">
   {{ .TableOfContents }}
 </aside>
-{{- end }}
Nodraak commented 5 years ago

Hi @taikii,

I'll use this relevant issue to ask a question: what is your policy on adding new variables in config.toml? Does one can add whatever option fits their need? For instance, for this issue, we could add an option minWordCountToShowToc. If set to 0, this would always show the toc. I have another idea that could use a new option as well: in the archive page, group the articles by years instead of months.

I can submit one PR for each if it's ok

As always, thank you for your work.