diff --git a/config.toml b/config.toml index ffe702f..a427882 100644 --- a/config.toml +++ b/config.toml @@ -206,3 +206,12 @@ show_qr = true # # Your GoatCounter username user = "duckquill" + +# Table of Contents (TOC) configs +[extra.toc] +# whether to render inline static TOC at the top of the articles or not +inline = true +# where to show the TOC as a pop-up button +popup = true +# Show numbered TOC +numbered = true diff --git a/templates/article.html b/templates/article.html index 803a8a1..f701c5a 100644 --- a/templates/article.html +++ b/templates/article.html @@ -4,6 +4,13 @@ {%- set date_format = macros_translate::translate(key="date_format", default="%B %d, %Y", language_strings=language_strings) -%} {%- set date_locale = macros_translate::translate(key="date_locale", default="en_US", language_strings=language_strings) -%} {%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%} + +{% if config.extra.toc.numbered %} + {% set list_element = "ol" %} +{% else %} + {% set list_element = "ul" %} +{% endif %} +
{%- if page.extra.banner -%}
- {%- if page.extra.toc -%} + {%- if page.extra.toc and config.extra.toc.popup -%}
{{ macros_translate::translate(key="table_of_contents", default="Table of Contents", language_strings=language_strings) }}
-
    + <{{list_element}}> {%- for h1 in page.toc -%}
  • {{ h1.title }} {%- if h1.children -%} -
      + <{{list_element}}> {%- for h2 in h1.children -%}
    • {{ h2.title }}
    • {%- endfor -%} -
    + {%- endif -%}
  • {%- endfor -%} -
+
@@ -107,6 +114,28 @@ {%- include "partials/statements.html" -%} + + {%- if page.extra.toc and config.extra.toc.inline-%} +

{{ macros_translate::translate(key="table_of_contents", default="Table of Contents", language_strings=language_strings) }}

+ + <{{list_element}} role="list"> + {%- for h1 in page.toc -%} +
  • + {{ h1.title }} + {%- if h1.children -%} + <{{list_element}} role="list"> + {%- for h2 in h1.children -%} +
  • + {{ h2.title }} +
  • + {%- endfor -%} + + {%- endif -%} + + {%- endfor -%} + + {%- endif -%} + {{ page.content | safe }}