hermanp / website

Source code of personal website. Based on Wowchemy Hugo theme.
https://hermanp.github.io
2 stars 1 forks source link

Table of contents on a post #8

Closed hermanp closed 4 years ago

hermanp commented 4 years ago

Get a table of contents (TOC, ToC) for a post page. Google search: hugo "table of contents" OR toc, hugo "table of contents" OR toc aside and hugo "table of contents" OR toc float* OR aside

hermanp commented 4 years ago

Need to adjust the settings startLevel and endLevel for goldmark renderer in config.toml:

hermanp commented 4 years ago

If single.html is modified as below (as Table of contents - Hugo docs suggests):

{{- define "main" -}}

<article class="article">
  {{ partial "page_header" . }}
  <div class="article-container">
    <div class="article-style">
      {{ .Content }}
    </div>
    {{ partial "page_footer" . }}
  </div>
</article>

<!--- Below is added --->
<aside>
  {{ .TableOfContents }}
</aside>
<!--- Above is added --->

{{- end -}}

Then the result is a TOC on the left side, as this picture shows: TOC_aside_error

hermanp commented 4 years ago

After searched in Google for hugo "table of contents" OR toc aside, found goHugo Table of Contents

Modified single.html as:

{{- define "main" -}}

<article class="article">
  {{ partial "page_header" . }}
  <div class="article-container">
    <div class="article-style">
      {{ .Content }}
    </div>
    {{ partial "page_footer" . }}
  </div>
</article>

<aside style="float: right;">
  {{ .TableOfContents }}
</aside>

{{- end -}}

This happened: TOC_aside_error2

hermanp commented 4 years ago

In the end TOC for blog posts #1520 was modified at the if condition, according to Adding a useful Table of Contents to Hugo sites.