mirror of
https://github.com/mkdocs/mkdocs.git
synced 2026-04-12 07:06:28 +07:00
1006 lines
54 KiB
HTML
1006 lines
54 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<meta name="author" content="MkDocs Team">
|
|
<link rel="canonical" href="https://www.mkdocs.org/user-guide/configuration/">
|
|
<link rel="shortcut icon" href="../../img/favicon.ico">
|
|
<title>Configuration - MkDocs</title>
|
|
<link href="../../css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="../../css/font-awesome.min.css" rel="stylesheet">
|
|
<link href="../../css/base.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/github.min.css">
|
|
<link href="../../assets/_mkdocstrings.css" rel="stylesheet">
|
|
<link href="../../css/extra.css" rel="stylesheet">
|
|
|
|
<script src="../../js/jquery-1.10.2.min.js" defer></script>
|
|
<script src="../../js/bootstrap.min.js" defer></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/languages/yaml.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/languages/django.min.js"></script>
|
|
<script>hljs.initHighlightingOnLoad();</script>
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-274394082"></script>
|
|
<script>
|
|
window.dataLayer = window.dataLayer || [];
|
|
function gtag(){dataLayer.push(arguments);}
|
|
gtag('js', new Date());
|
|
|
|
gtag('config', 'G-274394082');
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="navbar fixed-top navbar-expand-lg navbar-dark bg-primary">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="../..">MkDocs</a>
|
|
<!-- Expander button -->
|
|
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar-collapse">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
|
|
<!-- Expanded navigation -->
|
|
<div id="navbar-collapse" class="navbar-collapse collapse">
|
|
<!-- Main navigation -->
|
|
<ul class="nav navbar-nav">
|
|
<li class="navitem">
|
|
<a href="../.." class="nav-link">Home</a>
|
|
</li>
|
|
<li class="navitem">
|
|
<a href="../../getting-started/" class="nav-link">Getting Started</a>
|
|
</li>
|
|
<li class="dropdown active">
|
|
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">User Guide <b class="caret"></b></a>
|
|
<ul class="dropdown-menu">
|
|
|
|
<li>
|
|
<a href="../" class="dropdown-item">User Guide</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../installation/" class="dropdown-item">Installation</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../writing-your-docs/" class="dropdown-item">Writing Your Docs</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../choosing-your-theme/" class="dropdown-item">Choosing Your Theme</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../customizing-your-theme/" class="dropdown-item">Customizing Your Theme</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../localizing-your-theme/" class="dropdown-item">Localizing Your Theme</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="./" class="dropdown-item active">Configuration</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../cli/" class="dropdown-item">Command Line Interface</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../deploying-your-docs/" class="dropdown-item">Deploying Your Docs</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li class="dropdown">
|
|
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Developer Guide <b class="caret"></b></a>
|
|
<ul class="dropdown-menu">
|
|
|
|
<li>
|
|
<a href="../../dev-guide/" class="dropdown-item">Developer Guide</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../../dev-guide/themes/" class="dropdown-item">Themes</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../../dev-guide/translations/" class="dropdown-item">Translations</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../../dev-guide/plugins/" class="dropdown-item">Plugins</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../../dev-guide/api/" class="dropdown-item">API Reference</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li class="dropdown">
|
|
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">About <b class="caret"></b></a>
|
|
<ul class="dropdown-menu">
|
|
|
|
<li>
|
|
<a href="../../about/release-notes/" class="dropdown-item">Release Notes</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../../about/contributing/" class="dropdown-item">Contributing</a>
|
|
</li>
|
|
|
|
<li>
|
|
<a href="../../about/license/" class="dropdown-item">License</a>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<ul class="nav navbar-nav ml-auto">
|
|
<li class="nav-item">
|
|
<a href="#" class="nav-link" data-toggle="modal" data-target="#mkdocs_search_modal">
|
|
<i class="fa fa-search"></i> Search
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a rel="prev" href="../localizing-your-theme/" class="nav-link">
|
|
<i class="fa fa-arrow-left"></i> Previous
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a rel="next" href="../cli/" class="nav-link">
|
|
Next <i class="fa fa-arrow-right"></i>
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a href="https://github.com/mkdocs/mkdocs/blob/master/docs/user-guide/configuration.md" class="nav-link"><i class="fa fa-github"></i> Edit on GitHub</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-md-3"><div class="navbar-light navbar-expand-md bs-sidebar hidden-print affix" role="complementary">
|
|
<div class="navbar-header">
|
|
<button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target="#toc-collapse" title="Table of Contents">
|
|
<span class="fa fa-angle-down"></span>
|
|
</button>
|
|
</div>
|
|
|
|
|
|
<div id="toc-collapse" class="navbar-collapse collapse card bg-secondary">
|
|
<ul class="nav flex-column">
|
|
|
|
<li class="nav-item" data-level="1"><a href="#configuration" class="nav-link">Configuration</a>
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item" data-level="2"><a href="#introduction" class="nav-link">Introduction</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#project-information" class="nav-link">Project information</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#documentation-layout" class="nav-link">Documentation layout</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#build-directories" class="nav-link">Build directories</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#preview-controls" class="nav-link">Preview controls</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#live-reloading" class="nav-link">Live Reloading</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#formatting-options" class="nav-link">Formatting options</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#environment-variables" class="nav-link">Environment Variables</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item" data-level="2"><a href="#configuration-inheritance" class="nav-link">Configuration Inheritance</a>
|
|
<ul class="nav flex-column">
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div></div>
|
|
<div class="col-md-9" role="main">
|
|
|
|
<h1 id="configuration">Configuration<a class="headerlink" href="#configuration" title="Permanent link"></a></h1>
|
|
<p>Guide to all available configuration settings.</p>
|
|
<hr />
|
|
<h2 id="introduction">Introduction<a class="headerlink" href="#introduction" title="Permanent link"></a></h2>
|
|
<p>Project settings are configured by default using a YAML configuration file in
|
|
the project directory named <code>mkdocs.yml</code>. You can specify another path for it
|
|
by using the <code>-f</code>/<code>--config-file</code> option (see <code>mkdocs build --help</code>).</p>
|
|
<p>As a minimum, this configuration file must contain the <code>site_name</code>. All other settings are optional.</p>
|
|
<h2 id="project-information">Project information<a class="headerlink" href="#project-information" title="Permanent link"></a></h2>
|
|
<h3 id="site_name">site_name<a class="headerlink" href="#site_name" title="Permanent link"></a></h3>
|
|
<p>This is a <strong>required setting</strong>, and should be a string that is used as the main
|
|
title for the project documentation. For example:</p>
|
|
<pre class="highlight"><code class="language-yaml">site_name: Marshmallow Generator</code></pre>
|
|
<p>When rendering the theme this setting will be passed as the <code>site_name</code> context
|
|
variable.</p>
|
|
<h3 id="site_url">site_url<a class="headerlink" href="#site_url" title="Permanent link"></a></h3>
|
|
<p>Set the canonical URL of the site. This will add a <code>link</code> tag with the
|
|
<code>canonical</code> URL to the <code>head</code> section of each HTML page. If the 'root' of the
|
|
MkDocs site will be within a subdirectory of a domain, be sure to include that
|
|
subdirectory in the setting (<code>https://example.com/foo/</code>).</p>
|
|
<p>This setting is also used for <code>mkdocs serve</code>: the server will be mounted onto a
|
|
path taken from the path component of the URL, e.g. <code>some/page.md</code> will be
|
|
served from <code>http://127.0.0.1:8000/foo/some/page/</code> to mimic the expected remote
|
|
layout.</p>
|
|
<p><strong>default</strong>: <code>null</code></p>
|
|
<h3 id="repo_url">repo_url<a class="headerlink" href="#repo_url" title="Permanent link"></a></h3>
|
|
<p>When set, provides a link to your repository (GitHub, Bitbucket, GitLab, ...)
|
|
on each page.</p>
|
|
<pre class="highlight"><code class="language-yaml">repo_url: https://github.com/example/repository/</code></pre>
|
|
<p><strong>default</strong>: <code>null</code></p>
|
|
<h3 id="repo_name">repo_name<a class="headerlink" href="#repo_name" title="Permanent link"></a></h3>
|
|
<p>When set, provides the name for the link to your repository on each page.</p>
|
|
<p><strong>default</strong>: <code>'GitHub'</code>, <code>'Bitbucket'</code> or <code>'GitLab'</code> if the <code>repo_url</code> matches
|
|
those domains, otherwise the hostname from the <code>repo_url</code>.</p>
|
|
<h3 id="edit_uri">edit_uri<a class="headerlink" href="#edit_uri" title="Permanent link"></a></h3>
|
|
<p>The path from the base <code>repo_url</code> to the docs directory when directly viewing a
|
|
page, accounting for specifics of the repository host (e.g. GitHub, Bitbucket,
|
|
etc), the branch, and the docs directory itself. MkDocs concatenates <code>repo_url</code>
|
|
and <code>edit_uri</code>, and appends the input path of the page.</p>
|
|
<p>When set, and if your theme supports it, provides a link directly to the page in
|
|
your source repository. This makes it easier to find and edit the source for the
|
|
page. If <code>repo_url</code> is not set, this option is ignored. On some themes, setting
|
|
this option may cause an edit link to be used in place of a repository link.
|
|
Other themes may show both links.</p>
|
|
<p>The <code>edit_uri</code> supports query ('?') and fragment ('#') characters. For
|
|
repository hosts that use a query or a fragment to access the files, the
|
|
<code>edit_uri</code> might be set as follows. (Note the <code>?</code> and <code>#</code> in the URI...)</p>
|
|
<pre class="highlight"><code class="language-yaml"># Query string example
|
|
edit_uri: '?query=root/path/docs/'</code></pre>
|
|
<pre class="highlight"><code class="language-yaml"># Hash fragment example
|
|
edit_uri: '#root/path/docs/'</code></pre>
|
|
<p>For other repository hosts, simply specify the relative path to the docs
|
|
directory.</p>
|
|
<pre class="highlight"><code class="language-yaml"># Query string example
|
|
edit_uri: root/path/docs/</code></pre>
|
|
<p>For example, having this config:</p>
|
|
<pre class="highlight"><code class="language-yaml">repo_url: https://example.com/project/repo
|
|
edit_uri: blob/main/docs/</code></pre>
|
|
<p>means that a page named 'foo/bar.md' will have its edit link lead to:<br />
|
|
<a href="https://example.com/project/repo/blob/main/docs/foo/bar.md">https://example.com/project/repo/blob/main/docs/foo/bar.md</a></p>
|
|
<p><code>edit_uri</code> can actually be just an absolute URL, not necessarily relative to <code>repo_url</code>, so this can achieve the same result:</p>
|
|
<pre class="highlight"><code class="language-yaml">edit_uri: https://example.com/project/repo/blob/main/docs/</code></pre>
|
|
<p>For more flexibility, see <a href="#edit_uri_template">edit_uri_template</a> below.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>
|
|
On a few known hosts (specifically GitHub, Bitbucket and GitLab), the
|
|
<code>edit_uri</code> is derived from the 'repo_url' and does not need to be set
|
|
manually. Simply defining a <code>repo_url</code> will automatically populate the
|
|
<code>edit_uri</code> configs setting.</p>
|
|
<p>For example, for a GitHub- or GitLab-hosted repository, the <code>edit_uri</code>
|
|
would be automatically set as <code>edit/master/docs/</code> (Note the <code>edit</code> path
|
|
and <code>master</code> branch).</p>
|
|
<p>For a Bitbucket-hosted repository, the equivalent <code>edit_uri</code> would be
|
|
automatically set as <code>src/default/docs/</code> (note the <code>src</code> path and <code>default</code>
|
|
branch).</p>
|
|
<p>To use a different URI than the default (for example a different branch),
|
|
simply set the <code>edit_uri</code> to your desired string. If you do not want any
|
|
"edit URL link" displayed on your pages, then set <code>edit_uri</code> to an empty
|
|
string to disable the automatic setting.</p>
|
|
</div>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning</p>
|
|
<p>
|
|
On GitHub and GitLab, the default "edit" path (<code>edit/master/docs/</code>) opens
|
|
the page in the online editor. This functionality requires that the user
|
|
have and be logged in to a GitHub/GitLab account. Otherwise, the user will
|
|
be redirected to a login/signup page. Alternatively, use the "blob" path
|
|
(<code>blob/master/docs/</code>) to open a read-only view, which supports anonymous
|
|
access.</p>
|
|
</div>
|
|
<p><strong>default</strong>: <code>edit/master/docs/</code> for GitHub and GitLab repos or
|
|
<code>src/default/docs/</code> for a Bitbucket repo, if <code>repo_url</code> matches those domains,
|
|
otherwise <code>null</code></p>
|
|
<h3 id="edit_uri_template">edit_uri_template<a class="headerlink" href="#edit_uri_template" title="Permanent link"></a></h3>
|
|
<p>The more flexible variant of <a href="#edit_uri">edit_uri</a>. These two are equivalent:</p>
|
|
<pre class="highlight"><code class="language-yaml">edit_uri: 'blob/main/docs/'
|
|
edit_uri_template: 'blob/main/docs/{path}'</code></pre>
|
|
<p>(they are also mutually exclusive -- don't specify both).</p>
|
|
<p>Starting from here, you can change the positioning or formatting of the path, in case the default behavior of appending the path isn't enough.</p>
|
|
<p>The contents of <code>edit_uri_template</code> are normal <a href="https://docs.python.org/3/library/string.html#formatstrings">Python format strings</a>, with only these fields available:</p>
|
|
<ul>
|
|
<li><code>{path}</code>, e.g. <code>foo/bar.md</code></li>
|
|
<li><code>{path_noext}</code>, e.g. <code>foo/bar</code></li>
|
|
</ul>
|
|
<p>And the conversion flag <code>!q</code> is available, to percent-encode the field:</p>
|
|
<ul>
|
|
<li><code>{path!q}</code>, e.g. <code>foo%2Fbar.md</code></li>
|
|
</ul>
|
|
<details class="note">
|
|
<summary>Suggested useful configurations:</summary>
|
|
<ul>
|
|
<li>
|
|
<p>GitHub Wiki:<br />
|
|
(e.g. <code>https://github.com/project/repo/wiki/foo/bar/_edit</code>)</p>
|
|
<pre class="highlight"><code class="language-yaml">repo_url: 'https://github.com/project/repo/wiki'
|
|
edit_uri_template: '{path_noext}/_edit'</code></pre>
|
|
</li>
|
|
<li>
|
|
<p>BitBucket editor:<br />
|
|
(e.g. <code>https://bitbucket.org/project/repo/src/master/docs/foo/bar.md?mode=edit</code>)</p>
|
|
<pre class="highlight"><code class="language-yaml">repo_url: 'https://bitbucket.org/project/repo/'
|
|
edit_uri_template: 'src/master/docs/{path}?mode=edit'</code></pre>
|
|
</li>
|
|
<li>
|
|
<p>GitLab Static Site Editor:<br />
|
|
(e.g. <code>https://gitlab.com/project/repo/-/sse/master/docs%2Ffoo%2bar.md</code>)</p>
|
|
<pre class="highlight"><code class="language-yaml">repo_url: 'https://gitlab.com/project/repo'
|
|
edit_uri_template: '-/sse/master/docs%2F{path!q}'</code></pre>
|
|
</li>
|
|
<li>
|
|
<p>GitLab Web IDE:<br />
|
|
(e.g. <code>https://gitlab.com/-/ide/project/repo/edit/master/-/docs/foo/bar.md</code>)</p>
|
|
<pre class="highlight"><code class="language-yaml">edit_uri_template: 'https://gitlab.com/-/ide/project/repo/edit/master/-/docs/{path}'</code></pre>
|
|
</li>
|
|
</ul>
|
|
</details>
|
|
<p><strong>default</strong>: <code>null</code></p>
|
|
<h3 id="site_description">site_description<a class="headerlink" href="#site_description" title="Permanent link"></a></h3>
|
|
<p>Set the site description. This will add a meta tag to the generated HTML header.</p>
|
|
<p><strong>default</strong>: <code>null</code></p>
|
|
<h3 id="site_author">site_author<a class="headerlink" href="#site_author" title="Permanent link"></a></h3>
|
|
<p>Set the name of the author. This will add a meta tag to the generated HTML
|
|
header.</p>
|
|
<p><strong>default</strong>: <code>null</code></p>
|
|
<h3 id="copyright">copyright<a class="headerlink" href="#copyright" title="Permanent link"></a></h3>
|
|
<p>Set the copyright information to be included in the documentation by the theme.</p>
|
|
<p><strong>default</strong>: <code>null</code></p>
|
|
<h3 id="remote_branch">remote_branch<a class="headerlink" href="#remote_branch" title="Permanent link"></a></h3>
|
|
<p>Set the remote branch to commit to when using <code>gh-deploy</code> to deploy to GitHub
|
|
Pages. This option can be overridden by a command line option in <code>gh-deploy</code>.</p>
|
|
<p><strong>default</strong>: <code>gh-pages</code></p>
|
|
<h3 id="remote_name">remote_name<a class="headerlink" href="#remote_name" title="Permanent link"></a></h3>
|
|
<p>Set the remote name to push to when using <code>gh-deploy</code> to deploy to GitHub Pages.
|
|
This option can be overridden by a command line option in <code>gh-deploy</code>.</p>
|
|
<p><strong>default</strong>: <code>origin</code></p>
|
|
<h2 id="documentation-layout">Documentation layout<a class="headerlink" href="#documentation-layout" title="Permanent link"></a></h2>
|
|
<h3 id="nav">nav<a class="headerlink" href="#nav" title="Permanent link"></a></h3>
|
|
<p>This setting is used to determine the format and layout of the global navigation
|
|
for the site. A minimal navigation configuration could look like this:</p>
|
|
<pre class="highlight"><code class="language-yaml">nav:
|
|
- 'index.md'
|
|
- 'about.md'</code></pre>
|
|
<p>All paths in the navigation configuration must be relative to the
|
|
<a href="#docs_dir"><code>docs_dir</code></a> configuration option. See the section on <a href="../writing-your-docs/#configure-pages-and-navigation">configuring
|
|
pages and navigation</a> for a more detailed breakdown, including how to create
|
|
sub-sections.</p>
|
|
<p>Navigation items may also include links to external sites. While titles are
|
|
optional for internal links, they are required for external links. An external
|
|
link may be a full URL or a relative URL. Any path which is not found in the
|
|
files is assumed to be an external link. See the section about [Meta-Data] on
|
|
how MkDocs determines the page title of a document.</p>
|
|
<pre class="highlight"><code class="language-yaml">nav:
|
|
- Introduction: 'index.md'
|
|
- 'about.md'
|
|
- 'Issue Tracker': 'https://example.com/'</code></pre>
|
|
<p>In the above example, the first two items point to local files while the third
|
|
points to an external site.</p>
|
|
<p>However, sometimes the MkDocs site is hosted in a subdirectory of a project's
|
|
site and you may want to link to other parts of the same site without including
|
|
the full domain. In that case, you may use an appropriate relative URL.</p>
|
|
<pre class="highlight"><code class="language-yaml">site_url: https://example.com/foo/
|
|
|
|
nav:
|
|
- Home: '../'
|
|
- 'User Guide': 'user-guide.md'
|
|
- 'Bug Tracker': '/bugs/'</code></pre>
|
|
<p>In the above example, two different styles of external links are used. First,
|
|
note that the <code>site_url</code> indicates that the MkDocs site is hosted in the <code>/foo/</code>
|
|
subdirectory of the domain. Therefore, the <code>Home</code> navigation item is a relative
|
|
link that steps up one level to the server root and effectively points to
|
|
<code>https://example.com/</code>. The <code>Bug Tracker</code> item uses an absolute path from the
|
|
server root and effectively points to <code>https://example.com/bugs/</code>. Of course, the
|
|
<code>User Guide</code> points to a local MkDocs page.</p>
|
|
<p><strong>default</strong>: By default <code>nav</code> will contain an alphanumerically sorted, nested
|
|
list of all the Markdown files found within the <code>docs_dir</code> and its
|
|
sub-directories. Index files will always be listed first within a sub-section.</p>
|
|
<h2 id="build-directories">Build directories<a class="headerlink" href="#build-directories" title="Permanent link"></a></h2>
|
|
<h3 id="theme">theme<a class="headerlink" href="#theme" title="Permanent link"></a></h3>
|
|
<p>Sets the theme and theme specific configuration of your documentation site.
|
|
May be either a string or a set of key/value pairs.</p>
|
|
<p>If a string, it must be the string name of a known installed theme. For a list
|
|
of available themes visit <a href="../choosing-your-theme/">Choosing Your Theme</a>.</p>
|
|
<p>An example set of key/value pairs might look something like this:</p>
|
|
<pre class="highlight"><code class="language-yaml">theme:
|
|
name: mkdocs
|
|
locale: en
|
|
custom_dir: my_theme_customizations/
|
|
static_templates:
|
|
- sitemap.html
|
|
include_sidebar: false</code></pre>
|
|
<p>If a set of key/value pairs, the following nested keys can be defined:</p>
|
|
<div class="admonition block">
|
|
<p class="admonition-title">Block</p>
|
|
<h4 id="name">
|
|
name<a class="headerlink" href="#name" title="Permanent link"></a></h4>
|
|
<p>The string name of a known installed theme. For a list of available themes
|
|
visit <a href="../choosing-your-theme/">Choosing Your Theme</a>.</p>
|
|
<h4 id="locale">locale<a class="headerlink" href="#locale" title="Permanent link"></a></h4>
|
|
<p>A code representing the language of your site. See <a href="../localizing-your-theme/">Localizing your theme</a>
|
|
for details.</p>
|
|
<h4 id="custom_dir">custom_dir<a class="headerlink" href="#custom_dir" title="Permanent link"></a></h4>
|
|
<p>A directory containing a custom theme. This can either be a relative
|
|
directory, in which case it is resolved relative to the directory containing
|
|
your configuration file or it can be an absolute directory path from the
|
|
root of your local file system.</p>
|
|
<p>See <a href="../customizing-your-theme/#using-the-theme_dir">Customizing Your Theme</a> for details if you would like to tweak an
|
|
existing theme.</p>
|
|
<p>See the <a href="../../dev-guide/themes/">Theme Developer Guide</a> if you would like to build your own theme
|
|
from the ground up.</p>
|
|
<h4 id="static_templates">static_templates<a class="headerlink" href="#static_templates" title="Permanent link"></a></h4>
|
|
<p>A list of templates to render as static pages. The templates must be located
|
|
in either the theme's template directory or in the <code>custom_dir</code> defined in
|
|
the theme configuration.</p>
|
|
<h4 id="theme-specific-keywords">(theme specific keywords)<a class="headerlink" href="#theme-specific-keywords" title="Permanent link"></a></h4>
|
|
<p>Any additional keywords supported by the theme can also be defined. See the
|
|
documentation for the theme you are using for details.</p>
|
|
</div>
|
|
<p><strong>default</strong>: <code>'mkdocs'</code></p>
|
|
<h3 id="docs_dir">docs_dir<a class="headerlink" href="#docs_dir" title="Permanent link"></a></h3>
|
|
<p>The directory containing the documentation source markdown files. This can
|
|
either be a relative directory, in which case it is resolved relative to the
|
|
directory containing your configuration file, or it can be an absolute directory
|
|
path from the root of your local file system.</p>
|
|
<p><strong>default</strong>: <code>'docs'</code></p>
|
|
<h3 id="site_dir">site_dir<a class="headerlink" href="#site_dir" title="Permanent link"></a></h3>
|
|
<p>The directory where the output HTML and other files are created. This can either
|
|
be a relative directory, in which case it is resolved relative to the directory
|
|
containing your configuration file, or it can be an absolute directory path from
|
|
the root of your local file system.</p>
|
|
<p><strong>default</strong>: <code>'site'</code></p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>
|
|
If you are using source code control you will normally want to ensure that
|
|
your <em>build output</em> files are not committed into the repository, and only
|
|
keep the <em>source</em> files under version control. For example, if using <code>git</code>
|
|
you might add the following line to your <code>.gitignore</code> file:</p>
|
|
<pre class="highlight"><code class="language-text">site/</code></pre>
|
|
<p>If you're using another source code control tool, you'll want to check its
|
|
documentation on how to ignore specific directories.</p>
|
|
</div>
|
|
<h3 id="extra_css">extra_css<a class="headerlink" href="#extra_css" title="Permanent link"></a></h3>
|
|
<p>Set a list of CSS files in your <code>docs_dir</code> to be included by the theme. For
|
|
example, the following example will include the extra.css file within the
|
|
css subdirectory in your <a href="#docs_dir">docs_dir</a>.</p>
|
|
<pre class="highlight"><code class="language-yaml">extra_css:
|
|
- css/extra.css
|
|
- css/second_extra.css</code></pre>
|
|
<p><strong>default</strong>: <code>[]</code> (an empty list).</p>
|
|
<h3 id="extra_javascript">extra_javascript<a class="headerlink" href="#extra_javascript" title="Permanent link"></a></h3>
|
|
<p>Set a list of JavaScript files in your <code>docs_dir</code> to be included by the theme.
|
|
See the example in <a href="#extra_css">extra_css</a> for usage.</p>
|
|
<p><strong>default</strong>: <code>[]</code> (an empty list).</p>
|
|
<h3 id="extra_templates">extra_templates<a class="headerlink" href="#extra_templates" title="Permanent link"></a></h3>
|
|
<p>Set a list of templates in your <code>docs_dir</code> to be built by MkDocs. To see more
|
|
about writing templates for MkDocs read the documentation about [custom themes]
|
|
and specifically the section about the [available variables] to
|
|
templates. See the example in <a href="#extra_css">extra_css</a> for usage.</p>
|
|
<p><strong>default</strong>: <code>[]</code> (an empty list).</p>
|
|
<h3 id="extra">extra<a class="headerlink" href="#extra" title="Permanent link"></a></h3>
|
|
<p>A set of key-value pairs, where the values can be any valid YAML construct, that
|
|
will be passed to the template. This allows for great flexibility when creating
|
|
custom themes.</p>
|
|
<p>For example, if you are using a theme that supports displaying the project
|
|
version, you can pass it to the theme like this:</p>
|
|
<pre class="highlight"><code class="language-yaml">extra:
|
|
version: 1.0</code></pre>
|
|
<p><strong>default</strong>: By default <code>extra</code> will be an empty key-value mapping.</p>
|
|
<h2 id="preview-controls">Preview controls<a class="headerlink" href="#preview-controls" title="Permanent link"></a></h2>
|
|
<h2 id="live-reloading">Live Reloading<a class="headerlink" href="#live-reloading" title="Permanent link"></a></h2>
|
|
<h3 id="watch">watch<a class="headerlink" href="#watch" title="Permanent link"></a></h3>
|
|
<p>Determines additional directories to watch when running <code>mkdocs serve</code>.
|
|
Configuration is a YAML list.</p>
|
|
<pre class="highlight"><code class="language-yaml">watch:
|
|
- directory_a
|
|
- directory_b</code></pre>
|
|
<p>Allows a custom default to be set without the need to pass it through the <code>-w</code>/<code>--watch</code>
|
|
option every time the <code>mkdocs serve</code> command is called.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>
|
|
The paths provided via the configuration file are relative to the configuration file.</p>
|
|
<p>The paths provided via the <code>-w</code>/<code>--watch</code> CLI parameters are not.</p>
|
|
</div>
|
|
<h3 id="use_directory_urls">use_directory_urls<a class="headerlink" href="#use_directory_urls" title="Permanent link"></a></h3>
|
|
<p>This setting controls the style used for linking to pages within the
|
|
documentation.</p>
|
|
<p>The following table demonstrates how the URLs used on the site differ when
|
|
setting <code>use_directory_urls</code> to <code>true</code> or <code>false</code>.</p>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Source file</th>
|
|
<th>use_directory_urls: true</th>
|
|
<th>use_directory_urls: false</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>index.md</td>
|
|
<td>/</td>
|
|
<td>/index.html</td>
|
|
</tr>
|
|
<tr>
|
|
<td>api-guide.md</td>
|
|
<td>/api-guide/</td>
|
|
<td>/api-guide.html</td>
|
|
</tr>
|
|
<tr>
|
|
<td>about/license.md</td>
|
|
<td>/about/license/</td>
|
|
<td>/about/license.html</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>The default style of <code>use_directory_urls: true</code> creates more user friendly URLs,
|
|
and is usually what you'll want to use.</p>
|
|
<p>The alternate style can be useful if you want your documentation to remain
|
|
properly linked when opening pages directly from the file system, because it
|
|
creates links that point directly to the target <em>file</em> rather than the target
|
|
<em>directory</em>.</p>
|
|
<p><strong>default</strong>: <code>true</code></p>
|
|
<h3 id="strict">strict<a class="headerlink" href="#strict" title="Permanent link"></a></h3>
|
|
<p>Determines how warnings are handled. Set to <code>true</code> to halt processing when a
|
|
warning is raised. Set to <code>false</code> to print a warning and continue processing.</p>
|
|
<p>This is also available as a command line flag: <code>--strict</code>.</p>
|
|
<p><strong>default</strong>: <code>false</code></p>
|
|
<h3 id="dev_addr">dev_addr<a class="headerlink" href="#dev_addr" title="Permanent link"></a></h3>
|
|
<p>Determines the address used when running <code>mkdocs serve</code>. Must be of the format
|
|
<code>IP:PORT</code>.</p>
|
|
<p>Allows a custom default to be set without the need to pass it through the
|
|
<code>--dev-addr</code> option every time the <code>mkdocs serve</code> command is called.</p>
|
|
<p><strong>default</strong>: <code>'127.0.0.1:8000'</code></p>
|
|
<p>See also: <a href="#site_url">site_url</a>.</p>
|
|
<h2 id="formatting-options">Formatting options<a class="headerlink" href="#formatting-options" title="Permanent link"></a></h2>
|
|
<h3 id="markdown_extensions">markdown_extensions<a class="headerlink" href="#markdown_extensions" title="Permanent link"></a></h3>
|
|
<p>MkDocs uses the <a href="https://python-markdown.github.io/">Python Markdown</a> library to translate Markdown files
|
|
into HTML. Python Markdown supports a variety of <a href="https://python-markdown.github.io/extensions/">extensions</a>
|
|
that customize how pages are formatted. This setting lets you enable a list of
|
|
extensions beyond the ones that MkDocs uses by default (<code>meta</code>, <code>toc</code>, <code>tables</code>,
|
|
and <code>fenced_code</code>).</p>
|
|
<p>For example, to enable the <a href="https://python-markdown.github.io/extensions/smarty/">SmartyPants typography extension</a>, use:</p>
|
|
<pre class="highlight"><code class="language-yaml">markdown_extensions:
|
|
- smarty</code></pre>
|
|
<p>Some extensions provide configuration options of their own. If you would like to
|
|
set any configuration options, then you can nest a key/value mapping
|
|
(<code>option_name: option value</code>) of any options that a given extension supports.
|
|
See the documentation for the extension you are using to determine what options
|
|
they support.</p>
|
|
<p>For example, to enable permalinks in the (included) <code>toc</code> extension, use:</p>
|
|
<pre class="highlight"><code class="language-yaml">markdown_extensions:
|
|
- toc:
|
|
permalink: True</code></pre>
|
|
<p>Note that a colon (<code>:</code>) must follow the extension name (<code>toc</code>) and then on a new
|
|
line the option name and value must be indented and separated by a colon. If you
|
|
would like to define multiple options for a single extension, each option must be
|
|
defined on a separate line:</p>
|
|
<pre class="highlight"><code class="language-yaml">markdown_extensions:
|
|
- toc:
|
|
permalink: True
|
|
separator: "_"</code></pre>
|
|
<p>Add an additional item to the list for each extension. If you have no
|
|
configuration options to set for a specific extension, then simply omit options
|
|
for that extension:</p>
|
|
<pre class="highlight"><code class="language-yaml">markdown_extensions:
|
|
- smarty
|
|
- toc:
|
|
permalink: True
|
|
- sane_lists</code></pre>
|
|
<p>In the above examples, each extension is a list item (starts with a <code>-</code>). As an
|
|
alternative, key/value pairs can be used instead. However, in that case an empty
|
|
value must be provided for extensions for which no options are defined.
|
|
Therefore, the last example above could also be defined as follows:</p>
|
|
<pre class="highlight"><code class="language-yaml">markdown_extensions:
|
|
smarty: {}
|
|
toc:
|
|
permalink: True
|
|
sane_lists: {}</code></pre>
|
|
<p>This alternative syntax is required if you intend to override some options via
|
|
<a href="#configuration-inheritance">inheritance</a>.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">See Also:</p>
|
|
<p>The Python-Markdown documentation provides a <a href="https://python-markdown.github.io/extensions/">list of extensions</a>
|
|
which are available out-of-the-box. For a list of configuration options
|
|
available for a given extension, see the documentation for that extension.</p>
|
|
<p>You may also install and use various third party extensions (<a href="https://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensions">Python-Markdown wiki</a>, <a href="https://github.com/mkdocs/best-of-mkdocs">Best-of-MkDocs</a>). Consult
|
|
the documentation provided by those extensions for installation instructions
|
|
and available configuration options.</p>
|
|
</div>
|
|
<p><strong>default</strong>: <code>[]</code> (an empty list).</p>
|
|
<h3 id="hooks">hooks<a class="headerlink" href="#hooks" title="Permanent link"></a></h3>
|
|
<div class="admonition new">
|
|
<p class="admonition-title">New in version 1.4</p>
|
|
</div>
|
|
<p>A list of paths to Python scripts (relative to <code>mkdocs.yml</code>) that are loaded and used as <a href="#plugins">plugin</a> instances.</p>
|
|
<p>For example:</p>
|
|
<pre class="highlight"><code class="language-yaml">hooks:
|
|
- my_hooks.py</code></pre>
|
|
<p>Then the file <em>my_hooks.py</em> can contain any <a href="../../dev-guide/plugins/#events">plugin event handlers</a> (without <code>self</code>), e.g.:</p>
|
|
<pre class="highlight"><code class="language-python">def on_page_markdown(markdown, **kwargs):
|
|
return markdown.replace('a', 'z')</code></pre>
|
|
<details class="example">
|
|
<summary>Advanced example:</summary>
|
|
<p>This produces warnings based on the Markdown content (and warnings are fatal in <a href="#strict">strict</a> mode):</p>
|
|
<pre class="highlight"><code class="language-python">import logging, re
|
|
import mkdocs.plugins
|
|
|
|
log = logging.getLogger('mkdocs')
|
|
|
|
@mkdocs.plugins.event_priority(-50)
|
|
def on_page_markdown(markdown, page, **kwargs):
|
|
path = page.file.src_uri
|
|
for m in re.finditer(r'\bhttp://[^) ]+', markdown):
|
|
log.warning(f"Documentation file '{path}' contains a non-HTTPS link: {m[0]}")</code></pre>
|
|
</details>
|
|
<p>This does not enable any new abilities compared to <a href="../../dev-guide/plugins/">plugins</a>, it only simplifies one-off usages, as these don't need to be <em>installed</em> like plugins do.</p>
|
|
<p>Note that for <code>mkdocs serve</code> the hook module will <em>not</em> be reloaded on each build.</p>
|
|
<p>You might have seen this feature in the <a href="https://github.com/aklajnert/mkdocs-simple-hooks">mkdocs-simple-hooks plugin</a>. If using standard method names, it can be directly replaced, e.g.:</p>
|
|
<pre class="highlight"><code class="language-diff">-plugins:
|
|
- - mkdocs-simple-hooks:
|
|
- hooks:
|
|
- on_page_markdown: 'my_hooks:on_page_markdown'
|
|
+hooks:
|
|
+ - my_hooks.py</code></pre>
|
|
<h3 id="plugins">plugins<a class="headerlink" href="#plugins" title="Permanent link"></a></h3>
|
|
<p>A list of plugins (with optional configuration settings) to use when building
|
|
the site. See the <a href="../../dev-guide/plugins/">Plugins</a> documentation for full details.</p>
|
|
<p>If the <code>plugins</code> config setting is defined in the <code>mkdocs.yml</code> config file, then
|
|
any defaults (such as <code>search</code>) are ignored and you need to explicitly re-enable
|
|
the defaults if you would like to continue using them:</p>
|
|
<pre class="highlight"><code class="language-yaml">plugins:
|
|
- search
|
|
- your_other_plugin</code></pre>
|
|
<p>To define options for a given plugin, use a nested set of key/value pairs:</p>
|
|
<pre class="highlight"><code class="language-yaml">plugins:
|
|
- search
|
|
- your_other_plugin:
|
|
option1: value
|
|
option2: other value</code></pre>
|
|
<p>In the above examples, each plugin is a list item (starts with a <code>-</code>). As an
|
|
alternative, key/value pairs can be used instead. However, in that case an empty
|
|
value must be provided for plugins for which no options are defined. Therefore,
|
|
the last example above could also be defined as follows:</p>
|
|
<pre class="highlight"><code class="language-yaml">plugins:
|
|
search: {}
|
|
your_other_plugin:
|
|
option1: value
|
|
option2: other value</code></pre>
|
|
<p>This alternative syntax is required if you intend to override some options via
|
|
<a href="#configuration-inheritance">inheritance</a>.</p>
|
|
<p>To completely disable all plugins, including any defaults, set the <code>plugins</code>
|
|
setting to an empty list:</p>
|
|
<pre class="highlight"><code class="language-yaml">plugins: []</code></pre>
|
|
<p><strong>default</strong>: <code>['search']</code> (the "search" plugin included with MkDocs).</p>
|
|
<h4 id="search">Search<a class="headerlink" href="#search" title="Permanent link"></a></h4>
|
|
<p>A search plugin is provided by default with MkDocs which uses <a href="https://lunrjs.com/">lunr.js</a> as a
|
|
search engine. The following config options are available to alter the behavior
|
|
of the search plugin:</p>
|
|
<h5 id="separator"><strong>separator</strong><a class="headerlink" href="#separator" title="Permanent link"></a></h5>
|
|
<p>A regular expression which matches the characters used as word separators when
|
|
building the index. By default whitespace and the hyphen (<code>-</code>) are used. To add
|
|
the dot (<code>.</code>) as a word separator you might do this:</p>
|
|
<pre class="highlight"><code class="language-yaml">plugins:
|
|
- search:
|
|
separator: '[\s\-\.]+'</code></pre>
|
|
<p><strong>default</strong>: <code>'[\s\-]+'</code></p>
|
|
<h5 id="min_search_length"><strong>min_search_length</strong><a class="headerlink" href="#min_search_length" title="Permanent link"></a></h5>
|
|
<p>An integer value that defines the minimum length for a search query. By default
|
|
searches shorter than 3 chars in length are ignored as search result quality with
|
|
short search terms are poor. However, for some use cases (such as documentation
|
|
about Message Queues which might generate searches for 'MQ') it may be preferable
|
|
to set a shorter limit.</p>
|
|
<pre class="highlight"><code class="language-yaml">plugins:
|
|
- search:
|
|
min_search_length: 2</code></pre>
|
|
<p><strong>default</strong>: 3</p>
|
|
<h5 id="lang"><strong>lang</strong><a class="headerlink" href="#lang" title="Permanent link"></a></h5>
|
|
<p>A list of languages to use when building the search index as identified by their
|
|
<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1</a> language codes. With <a href="https://github.com/MihaiValentin/lunr-languages#lunr-languages-----">Lunr Languages</a>, the following languages are
|
|
supported:</p>
|
|
<ul>
|
|
<li><code>ar</code>: Arabic</li>
|
|
<li><code>da</code>: Danish</li>
|
|
<li><code>nl</code>: Dutch</li>
|
|
<li><code>en</code>: English</li>
|
|
<li><code>fi</code>: Finnish</li>
|
|
<li><code>fr</code>: French</li>
|
|
<li><code>de</code>: German</li>
|
|
<li><code>hu</code>: Hungarian</li>
|
|
<li><code>it</code>: Italian</li>
|
|
<li><code>ja</code>: Japanese</li>
|
|
<li><code>no</code>: Norwegian</li>
|
|
<li><code>pt</code>: Portuguese</li>
|
|
<li><code>ro</code>: Romanian</li>
|
|
<li><code>ru</code>: Russian</li>
|
|
<li><code>es</code>: Spanish</li>
|
|
<li><code>sv</code>: Swedish</li>
|
|
<li><code>th</code>: Thai</li>
|
|
<li><code>tr</code>: Turkish</li>
|
|
<li><code>vi</code>: Vietnamese</li>
|
|
</ul>
|
|
<p>You may <a href="https://github.com/MihaiValentin/lunr-languages/blob/master/CONTRIBUTING.md">contribute additional languages</a>.</p>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning</p>
|
|
<p>
|
|
While search does support using multiple languages together, it is best not
|
|
to add additional languages unless you really need them. Each additional
|
|
language adds significant bandwidth requirements and uses more browser
|
|
resources. Generally, it is best to keep each instance of MkDocs to a single
|
|
language.</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>
|
|
Lunr Languages does not currently include support for Chinese or other Asian
|
|
languages. However, some users have reported decent results using Japanese.</p>
|
|
</div>
|
|
<p><strong>default</strong>: The value of <code>theme.locale</code> if set, otherwise <code>[en]</code>.</p>
|
|
<h5 id="prebuild_index"><strong>prebuild_index</strong><a class="headerlink" href="#prebuild_index" title="Permanent link"></a></h5>
|
|
<p>Optionally generates a pre-built index of all pages, which provides some
|
|
performance improvements for larger sites. Before enabling, confirm that the
|
|
theme you are using explicitly supports using a prebuilt index (the builtin
|
|
themes do). Set to <code>true</code> to enable.</p>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning</p>
|
|
<p>
|
|
This option requires that <a href="https://nodejs.org/">Node.js</a> be installed and the command <code>node</code> be
|
|
on the system path. If the call to <code>node</code> fails for any reason, a warning
|
|
is issued and the build continues uninterrupted. You may use the <code>--strict</code>
|
|
flag when building to cause such a failure to raise an error instead.</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>
|
|
On smaller sites, using a pre-built index is not recommended as it creates a
|
|
significant increase is bandwidth requirements with little to no noticeable
|
|
improvement to your users. However, for larger sites (hundreds of pages),
|
|
the bandwidth increase is relatively small and your users will notice a
|
|
significant improvement in search performance.</p>
|
|
</div>
|
|
<p><strong>default</strong>: <code>False</code></p>
|
|
<h5 id="indexing"><strong>indexing</strong><a class="headerlink" href="#indexing" title="Permanent link"></a></h5>
|
|
<p>Configures what strategy the search indexer will use when building the index
|
|
for your pages. This property is particularly useful if your project is large
|
|
in scale, and the index takes up an enormous amount of disk space.</p>
|
|
<pre class="highlight"><code class="language-yaml">plugins:
|
|
- search:
|
|
indexing: 'full'</code></pre>
|
|
<h6 id="options">Options<a class="headerlink" href="#options" title="Permanent link"></a></h6>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Option</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><code>full</code></td>
|
|
<td>Indexes the title, section headings, and full text of each page.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>sections</code></td>
|
|
<td>Indexes the title and section headings of each page.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>titles</code></td>
|
|
<td>Indexes only the title of each page.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p><strong>default</strong>: <code>full</code></p>
|
|
<h2 id="environment-variables">Environment Variables<a class="headerlink" href="#environment-variables" title="Permanent link"></a></h2>
|
|
<p>In most cases, the value of a configuration option is set directly in the
|
|
configuration file. However, as an option, the value of a configuration option
|
|
may be set to the value of an environment variable using the <code>!ENV</code> tag. For
|
|
example, to set the value of the <code>site_name</code> option to the value of the
|
|
variable <code>SITE_NAME</code> the YAML file may contain the following:</p>
|
|
<pre class="highlight"><code class="language-yaml">site_name: !ENV SITE_NAME</code></pre>
|
|
<p>If the environment variable is not defined, then the configuration setting
|
|
would be assigned a <code>null</code> (or <code>None</code> in Python) value. A default value can be
|
|
defined as the last value in a list. Like this:</p>
|
|
<pre class="highlight"><code class="language-yaml">site_name: !ENV [SITE_NAME, 'My default site name']</code></pre>
|
|
<p>Multiple fallback variables can be used as well. Note that the last value is
|
|
not an environment variable, but must be a value to use as a default if none
|
|
of the specified environment variables are defined.</p>
|
|
<pre class="highlight"><code class="language-yaml">site_name: !ENV [SITE_NAME, OTHER_NAME, 'My default site name']</code></pre>
|
|
<p>Simple types defined within an environment variable such as string, bool,
|
|
integer, float, datestamp and null are parsed as if they were defined directly
|
|
in the YAML file, which means that the value will be converted to the
|
|
appropriate type. However, complex types such as lists and key/value pairs
|
|
cannot be defined within a single environment variable.</p>
|
|
<p>For more details, see the <a href="https://github.com/waylan/pyyaml-env-tag">pyyaml_env_tag</a>
|
|
project.</p>
|
|
<h2 id="configuration-inheritance">Configuration Inheritance<a class="headerlink" href="#configuration-inheritance" title="Permanent link"></a></h2>
|
|
<p>Generally, a single file would hold the entire configuration for a site.
|
|
However, some organizations may maintain multiple sites which all share a common
|
|
configuration across them. Rather than maintaining separate configurations for
|
|
each, the common configuration options can be defined in a parent configuration
|
|
file which each site's primary configuration file inherits.</p>
|
|
<p>To define the parent for a configuration file, set the <code>INHERIT</code> (all caps) key
|
|
to the path of the parent file. The path must be relative to the location of the
|
|
primary file.</p>
|
|
<p>For configuration options to be merged with a parent configuration, those
|
|
options must be defined as key/value pairs. Specifically, the
|
|
<a href="#markdown_extensions">markdown_extensions</a> and <a href="#plugins">plugins</a> options must use the alternative syntax
|
|
which does not use list items (lines which start with <code>-</code>).</p>
|
|
<p>For example, suppose the common (parent) configuration is defined in <code>base.yml</code>:</p>
|
|
<pre class="highlight"><code class="language-yaml">theme:
|
|
name: mkdocs
|
|
locale: en
|
|
highlightjs: true
|
|
|
|
markdown_extensions:
|
|
toc:
|
|
permalink: true
|
|
admonition: {}</code></pre>
|
|
<p>Then, for the "foo" site, the primary configuration file would be defined at
|
|
<code>foo/mkdocs.yml</code>:</p>
|
|
<pre class="highlight"><code class="language-yml">INHERIT: ../base.yml
|
|
site_name: Foo Project
|
|
site_url: https://example.com/foo</code></pre>
|
|
<p>When running <code>mkdocs build</code>, the file at <code>foo/mkdocs.yml</code> would be passed in as
|
|
the configuration file. MkDocs will then parse that file, retrieve and parse the
|
|
parent file <code>base.yml</code> and deep merge the two. This would result in MkDocs
|
|
receiving the following merged configuration:</p>
|
|
<pre class="highlight"><code class="language-yaml">site_name: Foo Project
|
|
site_url: https://example.com/foo
|
|
|
|
theme:
|
|
name: mkdocs
|
|
locale: en
|
|
highlightjs: true
|
|
|
|
markdown_extensions:
|
|
toc:
|
|
permalink: true
|
|
admonition: {}</code></pre>
|
|
<p>Deep merging allows you to add and/or override various values in your primary
|
|
configuration file. For example, suppose for one site you wanted to add support
|
|
for definition lists, use a different symbol for permalinks, and define a
|
|
different separator. In that site's primary configuration file you could do:</p>
|
|
<pre class="highlight"><code class="language-yaml">INHERIT: ../base.yml
|
|
site_name: Bar Project
|
|
site_url: https://example.com/bar
|
|
|
|
markdown_extensions:
|
|
def_list: {}
|
|
toc:
|
|
permalink:
|
|
separator: "_"</code></pre>
|
|
<p>In that case, the above configuration would be deep merged with <code>base.yml</code> and
|
|
result in the following configuration:</p>
|
|
<pre class="highlight"><code class="language-yaml">site_name: Bar Project
|
|
site_url: https://example.com/bar
|
|
|
|
theme:
|
|
name: mkdocs
|
|
locale: en
|
|
highlightjs: true
|
|
|
|
markdown_extensions:
|
|
def_list: {}
|
|
toc:
|
|
permalink:
|
|
separator: "_"
|
|
admonition: {}</code></pre>
|
|
<p>Notice that the <code>admonition</code> extension was retained from the parent
|
|
configuration, the <code>def_list</code> extension was added, the value of
|
|
<code>toc.permalink</code> was replaced, and the value of <code>toc.separator</code> was added.</p>
|
|
<p>You can replace or merge the value of any key. However, any non-key is always
|
|
replaced. Therefore, you cannot append items to a list. You must redefine the
|
|
entire list.</p>
|
|
<p>As the <a href="#nav">nav</a> configuration is made up of nested lists, this means that you
|
|
cannot merge navigation items. Of course, you can replace the entire <code>nav</code>
|
|
configuration with a new one. However, it is generally expected that the entire
|
|
navigation would be defined in the primary configuration file for a project.</p>
|
|
<div class="admonition warning">
|
|
<p class="admonition-title">Warning</p>
|
|
<p>
|
|
As a reminder, all path based configuration options must be relative to the
|
|
primary configuration file and MkDocs does not alter the paths when merging.
|
|
Therefore, defining paths in a parent file which is inherited by multiple
|
|
different sites may not work as expected. It is generally best to define
|
|
path based options in the primary configuration file only.</p>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="col-md-12">
|
|
<hr>
|
|
<p>Copyright © 2014 <a href="https://twitter.com/starletdreaming">Tom Christie</a>, Maintained by the <a href="/about/release-notes/#maintenance-team">MkDocs Team</a>.</p>
|
|
<p>Documentation built with <a href="https://www.mkdocs.org/">MkDocs</a>.</p>
|
|
</footer>
|
|
<script>
|
|
var base_url = "../..",
|
|
shortcuts = {"help": 191, "next": 78, "previous": 80, "search": 83};
|
|
</script>
|
|
<script src="../../js/base.js" defer></script>
|
|
<script src="../../search/main.js" defer></script>
|
|
|
|
<div class="modal" id="mkdocs_search_modal" tabindex="-1" role="dialog" aria-labelledby="searchModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h4 class="modal-title" id="searchModalLabel">Search</h4>
|
|
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>From here you can search these documents. Enter your search terms below.</p>
|
|
<form>
|
|
<div class="form-group">
|
|
<input type="search" class="form-control" placeholder="Search..." id="mkdocs-search-query" title="Type search term here">
|
|
</div>
|
|
</form>
|
|
<div id="mkdocs-search-results" data-no-results-text="No results found"></div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div><div class="modal" id="mkdocs_keyboard_modal" tabindex="-1" role="dialog" aria-labelledby="keyboardModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h4 class="modal-title" id="keyboardModalLabel">Keyboard Shortcuts</h4>
|
|
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th style="width: 20%;">Keys</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="help shortcut"><kbd>?</kbd></td>
|
|
<td>Open this help</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="next shortcut"><kbd>n</kbd></td>
|
|
<td>Next page</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="prev shortcut"><kbd>p</kbd></td>
|
|
<td>Previous page</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="search shortcut"><kbd>s</kbd></td>
|
|
<td>Search</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="modal-footer">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|