Added support for setting table of contents title via mkdocs.yml

This commit is contained in:
squidfunk 2021-10-27 19:01:47 +02:00
parent 8f382d9799
commit 4bdfef47eb
3 changed files with 28 additions and 4 deletions

View File

@ -213,6 +213,19 @@ markdown_extensions:
The following configuration options are supported: The following configuration options are supported:
`title`{ #toc-title }
: :octicons-milestone-24: Default: _automatically set_ This option sets the
title of the table of contents navigation in the right sidebar, which is
normally automatically sourced from the translations for the [site language]
as set in `mkdocs.yml`:
``` yaml
markdown_extensions:
- toc:
title: On this page
```
`permalink`{ #toc-permalink } `permalink`{ #toc-permalink }
: :octicons-milestone-24: Default: `false` This option adds an anchor link : :octicons-milestone-24: Default: `false` This option adds an anchor link
@ -301,6 +314,7 @@ own risk.
[Table of Contents]: https://python-markdown.github.io/extensions/toc/ [Table of Contents]: https://python-markdown.github.io/extensions/toc/
[Table of Contents support]: https://github.com/squidfunk/mkdocs-material/releases/tag/0.1.0 [Table of Contents support]: https://github.com/squidfunk/mkdocs-material/releases/tag/0.1.0
[site language]: ../changing-the-language.md#site-language
[Slugs]: https://facelessuser.github.io/pymdown-extensions/extras/slugs/ [Slugs]: https://facelessuser.github.io/pymdown-extensions/extras/slugs/
### Tables ### Tables

View File

@ -2,7 +2,11 @@
This file was automatically generated - do not edit This file was automatically generated - do not edit
-#} -#}
{% import "partials/language.html" as lang with context %} {% import "partials/language.html" as lang with context %}
<nav class="md-nav md-nav--secondary" aria-label="{{ lang.t('toc.title') }}"> {% set title = title | default(lang.t("toc.title")) %}
{% if "toc" in config.mdx_configs and config.mdx_configs.toc.title %}
{% set title = config.mdx_configs.toc.title %}
{% endif %}
<nav class="md-nav md-nav--secondary" aria-label="{{ title }}">
{% set toc = page.toc %} {% set toc = page.toc %}
{% set first = toc | first %} {% set first = toc | first %}
{% if first and first.level == 1 %} {% if first and first.level == 1 %}
@ -11,7 +15,7 @@
{% if toc %} {% if toc %}
<label class="md-nav__title" for="__toc"> <label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span> <span class="md-nav__icon md-icon"></span>
{{ lang.t("toc.title") }} {{ title }}
</label> </label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
{% for toc_item in toc %} {% for toc_item in toc %}

View File

@ -22,8 +22,14 @@
{% import "partials/language.html" as lang with context %} {% import "partials/language.html" as lang with context %}
<!-- Determine title -->
{% set title = title | default(lang.t("toc.title")) %}
{% if "toc" in config.mdx_configs and config.mdx_configs.toc.title %}
{% set title = config.mdx_configs.toc.title %}
{% endif %}
<!-- Table of contents --> <!-- Table of contents -->
<nav class="md-nav md-nav--secondary" aria-label="{{ lang.t('toc.title') }}"> <nav class="md-nav md-nav--secondary" aria-label="{{ title }}">
{% set toc = page.toc %} {% set toc = page.toc %}
<!-- <!--
@ -41,7 +47,7 @@
{% if toc %} {% if toc %}
<label class="md-nav__title" for="__toc"> <label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span> <span class="md-nav__icon md-icon"></span>
{{ lang.t("toc.title") }} {{ title }}
</label> </label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
{% for toc_item in toc %} {% for toc_item in toc %}