-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Currently, in addition to building (Markdown) pages via main.html, we have hardcoded provisions for theme templates to build 404.html, search.html, and sitemap.xml. However, there is no way for a theme to provide any additional pages (sitemap.html or Sphinx's genindex.html).
We do have the extra_templates config setting, but that specifically assumes the template files are in the docs_dir, not at a path in the Jinja environment (they go through mkdocs.commands.build.build_extra_templates() rather than mkdocs.commands.build.build_template()).
In the work on Plugins (#206), a plugin can alter the config and add an additional directory to the Jinja Environment. That same plugin can also add a hook which explicitly calls mkdocs.commands.build.build_template() with a template in its template dir (that's how I implemented search as a plugin). However, themes have no way to alter the config.
To allow something like this, we need some way to allow configuration for themes. I see a few possibilities:
-
The theme could include a config file which defines specific variables. For example an
extra_templatesvariable could include a list of additional templates to pass throughbuild_template. As prior art, Sphinx themes provide for aconfig.inifile in their root dir. We might want to use a.ymlfile instead to match our config file format. Or we could use Python in the required__init__.pyfile. -
We could allow nested config settings in
mkdocs.yml. Following existing conventions, perhaps something like:theme: themename: - extra_templates: [sitemap.html] - include_sidebar: false
-
A combination of the two. The theme author could define some defaults and the user could override them. This would also make a great way for themes to define optional behavior (
include_sidebarwhich defaults toTruebut the user can set toFalse).
Yes, we have the extra config setting. While that is already used by third party themes to enable/disable theme features, the theme has to provide for the setting not being defined at all. And extra does not provide a way for a theme to pass more templates through build_template.
If we just want to allow a theme to pass more pages through build_template, then option 1 makes the most sense to me. But personally, I would prefer option 3. Option 2 would work, but the user would need to explicitly set each setting before it would be defined at all.