How to make nav recognize the title of a template

171 Views Asked by At

If nav is not set in mkdocs.yml, navigation is created automatically. The string is determined by the following priority

  1. the title of each page (h1 string starting with #)
  2. the file name

I would like to display the h1 string in the navigation even if the template contains it, but it does not work. I use mkdocs-macros-plugin as a template. Any suggestions on what to do?


Reproduction example

[packages]
mkdocs = "==1.1"
mkdocs-macros-plugin = "==0.7.0"
docs/
└── index.md
templates/
└── template.md
mkdocs.yml

mkdocs.yml

plugins:
  - search
  - macros:
      include_dir: templates

templates/template.md

# AAAA

~~~

docs/index.md

{% include "template.md" %}

The navigation obtained in this setup is

index

I want the following navigation.

AAAA
1

There are 1 best solutions below

0
On

I am the author of mkdocs-macros. This is an issue that is not as simple as it seems. First of all, I suggest that you update to the latest version of mkdocs (>=1.5) and mkdocs-macros (>=1.1), to see if there is there is any difference in behavior.

Then, if there is no improvement, I suggest you to open an issue on github's repository for mkdocs-macros, to see what could be done about it.