Skip to content

Commit 4bdfef4

Browse files
committed
Added support for setting table of contents title via mkdocs.yml
1 parent 8f382d9 commit 4bdfef4

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

Diff for: docs/setup/extensions/python-markdown.md

+14
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ markdown_extensions:
213213

214214
The following configuration options are supported:
215215

216+
`title`{ #toc-title }
217+
218+
: :octicons-milestone-24: Default: _automatically set_ – This option sets the
219+
title of the table of contents navigation in the right sidebar, which is
220+
normally automatically sourced from the translations for the [site language]
221+
as set in `mkdocs.yml`:
222+
223+
``` yaml
224+
markdown_extensions:
225+
- toc:
226+
title: On this page
227+
```
228+
216229
`permalink`{ #toc-permalink }
217230

218231
: :octicons-milestone-24: Default: `false` – This option adds an anchor link
@@ -301,6 +314,7 @@ own risk.
301314

302315
[Table of Contents]: https://python-markdown.github.io/extensions/toc/
303316
[Table of Contents support]: https://github.com/squidfunk/mkdocs-material/releases/tag/0.1.0
317+
[site language]: ../changing-the-language.md#site-language
304318
[Slugs]: https://facelessuser.github.io/pymdown-extensions/extras/slugs/
305319

306320
### Tables

Diff for: material/partials/toc.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
This file was automatically generated - do not edit
33
-#}
44
{% import "partials/language.html" as lang with context %}
5-
<nav class="md-nav md-nav--secondary" aria-label="{{ lang.t('toc.title') }}">
5+
{% set title = title | default(lang.t("toc.title")) %}
6+
{% if "toc" in config.mdx_configs and config.mdx_configs.toc.title %}
7+
{% set title = config.mdx_configs.toc.title %}
8+
{% endif %}
9+
<nav class="md-nav md-nav--secondary" aria-label="{{ title }}">
610
{% set toc = page.toc %}
711
{% set first = toc | first %}
812
{% if first and first.level == 1 %}
@@ -11,7 +15,7 @@
1115
{% if toc %}
1216
<label class="md-nav__title" for="__toc">
1317
<span class="md-nav__icon md-icon"></span>
14-
{{ lang.t("toc.title") }}
18+
{{ title }}
1519
</label>
1620
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
1721
{% for toc_item in toc %}

Diff for: src/partials/toc.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222

2323
{% import "partials/language.html" as lang with context %}
2424

25+
<!-- Determine title -->
26+
{% set title = title | default(lang.t("toc.title")) %}
27+
{% if "toc" in config.mdx_configs and config.mdx_configs.toc.title %}
28+
{% set title = config.mdx_configs.toc.title %}
29+
{% endif %}
30+
2531
<!-- Table of contents -->
26-
<nav class="md-nav md-nav--secondary" aria-label="{{ lang.t('toc.title') }}">
32+
<nav class="md-nav md-nav--secondary" aria-label="{{ title }}">
2733
{% set toc = page.toc %}
2834

2935
<!--
@@ -41,7 +47,7 @@
4147
{% if toc %}
4248
<label class="md-nav__title" for="__toc">
4349
<span class="md-nav__icon md-icon"></span>
44-
{{ lang.t("toc.title") }}
50+
{{ title }}
4551
</label>
4652
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
4753
{% for toc_item in toc %}

0 commit comments

Comments
 (0)