Debian Codegraph @

docs/user-guide/configuration.md

raw
1 # Configuration
2
3 Guide to all available configuration settings.
4
5 ---
6
7 ## Introduction
8
9 Project settings are configured by default using a YAML configuration file in
10 the project directory named `mkdocs.yml`. You can specify another path for it
11 by using the `-f`/`--config-file` option (see `mkdocs build --help`).
12
13 At a minimum, this configuration file must contain the `site_name`. All other settings are optional.
14
15 ## Project information
16
17 ### site_name
18
19 This is a **required setting**, and should be a string that is used as the main
20 title for the project documentation. For example:
21
22 ```yaml
23 site_name: Marshmallow Generator
24 ```
25
26 When rendering the theme this setting will be passed as the `site_name` context
27 variable.
28
29 ### site_url
30
31 Set the canonical URL of the site. This will add a `link` tag with the
32 `canonical` URL to the `head` section of each HTML page. If the 'root' of the
33 MkDocs site will be within a subdirectory of a domain, be sure to include that
34 subdirectory in the setting (`https://example.com/foo/`).
35
36 This setting is also used for `mkdocs serve`: the server will be mounted onto a
37 path taken from the path component of the URL, e.g. `some/page.md` will be
38 served from `http://127.0.0.1:8000/foo/some/page/` to mimic the expected remote
39 layout.
40
41 **default**: `null`
42
43 ### repo_url
44
45 When set, provides a link to your repository (GitHub, Bitbucket, GitLab, ...)
46 on each page.
47
48 ```yaml
49 repo_url: https://github.com/example/repository/
50 ```
51
52 **default**: `null`
53
54 ### repo_name
55
56 When set, provides the name for the link to your repository on each page.
57
58 **default**: `'GitHub'`, `'Bitbucket'` or `'GitLab'` if the `repo_url` matches
59 those domains, otherwise the hostname from the `repo_url`.
60
61 ### edit_uri
62
63 The path from the base `repo_url` to the docs directory when directly viewing a
64 page, accounting for specifics of the repository host (e.g. GitHub, Bitbucket,
65 etc), the branch, and the docs directory itself. MkDocs concatenates `repo_url`
66 and `edit_uri`, and appends the input path of the page.
67
68 When set, and if your theme supports it, provides a link directly to the page in
69 your source repository. This makes it easier to find and edit the source for the
70 page. If `repo_url` is not set, this option is ignored. On some themes, setting
71 this option may cause an edit link to be used in place of a repository link.
72 Other themes may show both links.
73
74 The `edit_uri` supports query ('?') and fragment ('#') characters. For
75 repository hosts that use a query or a fragment to access the files, the
76 `edit_uri` might be set as follows. (Note the `?` and `#` in the URI...)
77
78 ```yaml
79 # Query string example
80 edit_uri: '?query=root/path/docs/'
81 ```
82
83 ```yaml
84 # Hash fragment example
85 edit_uri: '#root/path/docs/'
86 ```
87
88 For other repository hosts, simply specify the relative path to the docs
89 directory.
90
91 ```yaml
92 # Query string example
93 edit_uri: root/path/docs/
94 ```
95
96 For example, having this config:
97
98 ```yaml
99 repo_url: https://example.com/project/repo
100 edit_uri: blob/main/docs/
101 ```
102
103 means that a page named 'foo/bar.md' will have its edit link lead to:
104 <https://example.com/project/repo/blob/main/docs/foo/bar.md>
105
106 `edit_uri` can actually be just an absolute URL, not necessarily relative to `repo_url`, so this can achieve the same result:
107
108 ```yaml
109 edit_uri: https://example.com/project/repo/blob/main/docs/
110 ```
111
112 For more flexibility, see [edit_uri_template](#edit_uri_template) below.
113
114 > NOTE:
115 > On a few known hosts (specifically GitHub, Bitbucket and GitLab), the
116 > `edit_uri` is derived from the 'repo_url' and does not need to be set
117 > manually. Simply defining a `repo_url` will automatically populate the
118 > `edit_uri` configs setting.
119 >
120 > For example, for a GitHub- or GitLab-hosted repository, the `edit_uri`
121 > would be automatically set as `edit/master/docs/` (Note the `edit` path
122 > and `master` branch).
123 >
124 > For a Bitbucket-hosted repository, the equivalent `edit_uri` would be
125 > automatically set as `src/default/docs/` (note the `src` path and `default`
126 > branch).
127 >
128 > To use a different URI than the default (for example a different branch),
129 > simply set the `edit_uri` to your desired string. If you do not want any
130 > "edit URL link" displayed on your pages, then set `edit_uri` to an empty
131 > string to disable the automatic setting.
132
133 WARNING:
134 On GitHub and GitLab, the default "edit" path (`edit/master/docs/`) opens
135 the page in the online editor. This functionality requires that the user
136 have and be logged in to a GitHub/GitLab account. Otherwise, the user will
137 be redirected to a login/signup page. Alternatively, use the "blob" path
138 (`blob/master/docs/`) to open a read-only view, which supports anonymous
139 access.
140
141 **default**: `edit/master/docs/` for GitHub and GitLab repos or
142 `src/default/docs/` for a Bitbucket repo, if `repo_url` matches those domains,
143 otherwise `null`
144
145 ### edit_uri_template
146
147 The more flexible variant of [edit_uri](#edit_uri). These two are equivalent:
148
149 ```yaml
150 edit_uri: 'blob/main/docs/'
151 edit_uri_template: 'blob/main/docs/{path}'
152 ```
153
154 (they are also mutually exclusive -- don't specify both).
155
156 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.
157
158 The contents of `edit_uri_template` are normal [Python format strings](https://docs.python.org/3/library/string.html#formatstrings), with only these fields available:
159
160 * `{path}`, e.g. `foo/bar.md`
161 * `{path_noext}`, e.g. `foo/bar`
162
163 And the conversion flag `!q` is available, to percent-encode the field:
164
165 * `{path!q}`, e.g. `foo%2Fbar.md`
166
167 >? NOTE: **Suggested useful configurations:**
168 >
169 > * GitHub Wiki:
170 > (e.g. `https://github.com/project/repo/wiki/foo/bar/_edit`)
171 >
172 > ```yaml
173 > repo_url: 'https://github.com/project/repo/wiki'
174 > edit_uri_template: '{path_noext}/_edit'
175 > ```
176 >
177 > * BitBucket editor:
178 > (e.g. `https://bitbucket.org/project/repo/src/master/docs/foo/bar.md?mode=edit`)
179 >
180 > ```yaml
181 > repo_url: 'https://bitbucket.org/project/repo/'
182 > edit_uri_template: 'src/master/docs/{path}?mode=edit'
183 > ```
184 >
185 > * GitLab Static Site Editor:
186 > (e.g. `https://gitlab.com/project/repo/-/sse/master/docs%2Ffoo%2bar.md`)
187 >
188 > ```yaml
189 > repo_url: 'https://gitlab.com/project/repo'
190 > edit_uri_template: '-/sse/master/docs%2F{path!q}'
191 > ```
192 >
193 > * GitLab Web IDE:
194 > (e.g. `https://gitlab.com/-/ide/project/repo/edit/master/-/docs/foo/bar.md`)
195 >
196 > ```yaml
197 > edit_uri_template: 'https://gitlab.com/-/ide/project/repo/edit/master/-/docs/{path}'
198 > ```
199
200 **default**: `null`
201
202 ### site_description
203
204 Set the site description. This will add a meta tag to the generated HTML header.
205
206 **default**: `null`
207
208 ### site_author
209
210 Set the name of the author. This will add a meta tag to the generated HTML
211 header.
212
213 **default**: `null`
214
215 ### copyright
216
217 Set the copyright information to be included in the documentation by the theme.
218
219 **default**: `null`
220
221 ### remote_branch
222
223 Set the remote branch to commit to when using `gh-deploy` to deploy to GitHub
224 Pages. This option can be overridden by a command line option in `gh-deploy`.
225
226 **default**: `gh-pages`
227
228 ### remote_name
229
230 Set the remote name to push to when using `gh-deploy` to deploy to GitHub Pages.
231 This option can be overridden by a command line option in `gh-deploy`.
232
233 **default**: `origin`
234
235 ## Documentation layout
236
237 ### nav
238
239 This setting is used to determine the format and layout of the global navigation
240 for the site. A minimal navigation configuration could look like this:
241
242 ```yaml
243 nav:
244 - 'index.md'
245 - 'about.md'
246 ```
247
248 All paths in the navigation configuration must be relative to the
249 [`docs_dir`](#docs_dir) configuration option. See the section on [configuring
250 pages and navigation] for a more detailed breakdown, including how to create
251 sub-sections.
252
253 Navigation items may also include links to external sites. While titles are
254 optional for internal links, they are required for external links. An external
255 link may be a full URL or a relative URL. Any path which is not found in the
256 files is assumed to be an external link. See the section about [Meta-Data] on
257 how MkDocs determines the page title of a document.
258
259 ```yaml
260 nav:
261 - Introduction: 'index.md'
262 - 'about.md'
263 - 'Issue Tracker': 'https://example.com/'
264 ```
265
266 In the above example, the first two items point to local files while the third
267 points to an external site.
268
269 However, sometimes the MkDocs site is hosted in a subdirectory of a project's
270 site and you may want to link to other parts of the same site without including
271 the full domain. In that case, you may use an appropriate relative URL.
272
273 ```yaml
274 site_url: https://example.com/foo/
275
276 nav:
277 - Home: '../'
278 - 'User Guide': 'user-guide.md'
279 - 'Bug Tracker': '/bugs/'
280 ```
281
282 In the above example, two different styles of external links are used. First,
283 note that the `site_url` indicates that the MkDocs site is hosted in the `/foo/`
284 subdirectory of the domain. Therefore, the `Home` navigation item is a relative
285 link that steps up one level to the server root and effectively points to
286 `https://example.com/`. The `Bug Tracker` item uses an absolute path from the
287 server root and effectively points to `https://example.com/bugs/`. Of course, the
288 `User Guide` points to a local MkDocs page.
289
290 **default**: By default `nav` will contain an alphanumerically sorted, nested
291 list of all the Markdown files found within the `docs_dir` and its
292 sub-directories. Index files will always be listed first within a sub-section.
293
294 ### exclude_docs
295
296 NEW: **New in version 1.5.**
297
298 > DANGER: **Changed in version 1.6:**
299 >
300 > This config no longer applies the "drafts" functionality for `mkdocs serve`. If you have draft documents that you want available in "serve" and not "build", replace `exclude_docs` with the new [`draft_docs`](#draft_docs) config option.
301
302 This config defines patterns of files (under [`docs_dir`](#docs_dir)) to not be picked up into the built site.
303
304 Example:
305
306 ```yaml
307 exclude_docs: |
308 api-config.json # A file with this name anywhere.
309 /requirements.txt # Top-level "docs/requirements.txt".
310 *.py # Any file with this extension anywhere.
311 !/foo/example.py # But keep this particular file.
312 ```
313
314 This follows the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format).
315
316 The following defaults are always implicitly prepended - to exclude dot-files (and directories) as well as the top-level `templates` directory:
317
318 ```yaml
319 exclude_docs: |
320 .*
321 /templates/
322 ```
323
324 So, in order to really start this config fresh, you'd need to specify a negated version of these entries first.
325
326 Otherwise you could for example opt only certain dot-files back into the site:
327
328 ```yaml
329 exclude_docs: |
330 !.assets # Don't exclude '.assets' although all other '.*' are excluded
331 ```
332
333 ### draft_docs
334
335 NEW: **New in version 1.6.**
336
337 This config defines patterns of files (under [`docs_dir`](#docs_dir)) to be treated as a draft. Draft files are available during `mkdocs serve` and include a "DRAFT" mark but will not be included in the build. To prevent this effect and make "serve" behave the same as "build", you can run `mkdocs serve --clean`.
338
339 Example:
340
341 ```yaml
342 draft_docs: |
343 drafts/ # A "drafts" directory anywhere.
344 _unpublished.md # A md file ending in _unpublished.md
345 !/foo_unpublished.md # But keep this particular file.
346 ```
347
348 This follows the [.gitignore pattern format](https://git-scm.com/docs/gitignore#_pattern_format).
349
350 ### not_in_nav
351
352 NEW: **New in version 1.5.**
353
354 > NEW: **New in version 1.6:**
355 >
356 > If the [`nav`](#nav) config is not specified at all, pages specified in this config will now be excluded from the inferred navigation.
357
358 If you want to include some docs into the site but intentionally exclude them from the nav, normally MkDocs warns about this.
359
360 Adding such patterns of files (relative to [`docs_dir`](#docs_dir)) into the `not_in_nav` config will prevent such warnings.
361
362 Example:
363
364 ```yaml
365 nav:
366 - Foo: foo.md
367 - Bar: bar.md
368
369 not_in_nav: |
370 /private.md
371 ```
372
373 As the previous option, this follows the .gitignore pattern format.
374
375 NOTE: Adding a given file to [`exclude_docs`](#exclude_docs) takes precedence over and implies `not_in_nav`.
376
377 ### validation
378
379 NEW: **New in version 1.5.**
380
381 Configure the strictness of MkDocs' diagnostic messages when validating links to documents.
382
383 This is a tree of configs, and for each one the value can be one of the three: `warn`, `info`, `ignore`. Which cause a logging message of the corresponding severity to be produced. The `warn` level is, of course, intended for use with `mkdocs build --strict` (where it becomes an error), which you can employ in continuous testing.
384
385 The config `validation.links.absolute_links` additionally has a special value `relative_to_docs`, for [validation of absolute links](#validation-of-absolute-links).
386
387 >? EXAMPLE: **Defaults of this config as of MkDocs 1.6:**
388 >
389 > ```yaml
390 > validation:
391 > nav:
392 > omitted_files: info
393 > not_found: warn
394 > absolute_links: info
395 > links:
396 > not_found: warn
397 > anchors: info
398 > absolute_links: info
399 > unrecognized_links: info
400 > ```
401 >
402 > (Note: you shouldn't copy this whole example, because it only duplicates the defaults. Only individual items that differ should be set.)
403
404 The defaults of some of the behaviors already differ from MkDocs 1.4 and below - they were ignored before.
405
406 >? EXAMPLE: **Configure MkDocs 1.6 to behave like MkDocs 1.4 and below (reduce strictness):**
407 >
408 > ```yaml
409 > validation:
410 > absolute_links: ignore
411 > unrecognized_links: ignore
412 > anchors: ignore
413 > ```
414 <!-- -->
415 >! EXAMPLE: **Recommended settings for most sites (maximal strictness):**
416 >
417 > ```yaml
418 > validation:
419 > omitted_files: warn
420 > absolute_links: warn # Or 'relative_to_docs' - new in MkDocs 1.6
421 > unrecognized_links: warn
422 > anchors: warn # New in MkDocs 1.6
423 > ```
424
425 Note how in the above examples we omitted the 'nav' and 'links' keys. Here `absolute_links:` means setting both `nav: absolute_links:` and `links: absolute_links:`.
426
427 Full list of values and examples of log messages that they can hide or make more prominent:
428
429 * `validation.nav.omitted_files`
430 * > The following pages exist in the docs directory, but are not included in the "nav" configuration: ...
431 * `validation.nav.not_found`
432 * > A reference to 'foo/bar.md' is included in the 'nav' configuration, which is not found in the documentation files.
433 * > A reference to 'foo/bar.md' is included in the 'nav' configuration, but this file is excluded from the built site.
434 * `validation.nav.absolute_links`
435 * > An absolute path to '/foo/bar.html' is included in the 'nav' configuration, which presumably points to an external resource.
436 <!-- -->
437 * `validation.links.not_found`
438 * > Doc file 'example.md' contains a link '../foo/bar.md', but the target is not found among documentation files.
439 * > Doc file 'example.md' contains a link to 'foo/bar.md' which is excluded from the built site.
440 * `validation.links.anchors`
441 * > Doc file 'example.md' contains a link '../foo/bar.md#some-heading', but the doc 'foo/bar.md' does not contain an anchor '#some-heading'.
442 * > Doc file 'example.md' contains a link '#some-heading', but there is no such anchor on this page.
443 * `validation.links.absolute_links`
444 * > Doc file 'example.md' contains an absolute link '/foo/bar.html', it was left as is. Did you mean 'foo/bar.md'?
445 * `validation.links.unrecognized_links`
446 * > Doc file 'example.md' contains an unrecognized relative link '../foo/bar/', it was left as is. Did you mean 'foo/bar.md'?
447 * > Doc file 'example.md' contains an unrecognized relative link 'mail\@example.com', it was left as is. Did you mean 'mailto:mail\@example.com'?
448
449 #### Validation of absolute links
450
451 NEW: **New in version 1.6.**
452
453 > Historically, within Markdown, MkDocs only recognized **relative** links that lead to another physical `*.md` document (or media file). This is a good convention to follow because then the source pages are also freely browsable without MkDocs, for example on GitHub. Whereas absolute links were left unmodified (making them often not work as expected) or, more recently, warned against. If you dislike having to always use relative links, now you can opt into absolute links and have them work correctly.
454
455 If you set the setting `validation.links.absolute_links` to the new value `relative_to_docs`, all Markdown links starting with `/` will be understood as being relative to the `docs_dir` root. The links will then be validated for correctness according to all the other rules that were already working for relative links in prior versions of MkDocs. For the HTML output, these links will still be turned relative so that the site still works reliably.
456
457 So, now any document (e.g. "dir1/foo.md") can link to the document "dir2/bar.md" as `[link](/dir2/bar.md)`, in addition to the previously only correct way `[link](../dir2/bar.md)`.
458
459 You have to enable the setting, though. The default is still to just skip the link.
460
461 > EXAMPLE: **Settings to recognize absolute links and validate them:**
462 >
463 > ```yaml
464 > validation:
465 > links:
466 > absolute_links: relative_to_docs
467 > anchors: warn
468 > unrecognized_links: warn
469 > ```
470
471 ## Build directories
472
473 ### theme
474
475 Sets the theme and theme specific configuration of your documentation site.
476 May be either a string or a set of key/value pairs.
477
478 If a string, it must be the string name of a known installed theme. For a list
479 of available themes visit [Choosing Your Theme].
480
481 An example set of key/value pairs might look something like this:
482
483 ```yaml
484 theme:
485 name: mkdocs
486 locale: en
487 custom_dir: my_theme_customizations/
488 static_templates:
489 - sitemap.html
490 include_sidebar: false
491 ```
492
493 If a set of key/value pairs, the following nested keys can be defined:
494
495 > BLOCK:
496 >
497 > #### name
498 >
499 > The string name of a known installed theme. For a list of available themes
500 > visit [Choosing Your Theme].
501 >
502 > #### locale
503 >
504 > A code representing the language of your site. See [Localizing your theme]
505 > for details.
506 >
507 > #### custom_dir
508 >
509 > A directory containing a custom theme. This can either be a relative
510 > directory, in which case it is resolved relative to the directory containing
511 > your configuration file or it can be an absolute directory path from the
512 > root of your local file system.
513 >
514 > See [Customizing Your Theme][theme_dir] for details if you would like to tweak an
515 > existing theme.
516 >
517 > See the [Theme Developer Guide] if you would like to build your own theme
518 > from the ground up.
519 >
520 > #### static_templates
521 >
522 > A list of templates to render as static pages. The templates must be located
523 > in either the theme's template directory or in the `custom_dir` defined in
524 > the theme configuration.
525 >
526 > #### (theme specific keywords)
527 >
528 > Any additional keywords supported by the theme can also be defined. See the
529 > documentation for the theme you are using for details.
530
531 **default**: `'mkdocs'`
532
533 ### docs_dir
534
535 The directory containing the documentation source markdown files. This can
536 either be a relative directory, in which case it is resolved relative to the
537 directory containing your configuration file, or it can be an absolute directory
538 path from the root of your local file system.
539
540 **default**: `'docs'`
541
542 ### site_dir
543
544 The directory where the output HTML and other files are created. This can either
545 be a relative directory, in which case it is resolved relative to the directory
546 containing your configuration file, or it can be an absolute directory path from
547 the root of your local file system.
548
549 **default**: `'site'`
550
551 > NOTE:
552 > If you are using source code control you will normally want to ensure that
553 > your *build output* files are not committed into the repository, and only
554 > keep the *source* files under version control. For example, if using `git`
555 > you might add the following line to your `.gitignore` file:
556 >
557 > ```text
558 > site/
559 > ```
560 >
561 > If you're using another source code control tool, you'll want to check its
562 > documentation on how to ignore specific directories.
563
564 ### extra_css
565
566 Set a list of CSS files (relative to `docs_dir`) to be included by the theme, typically as `<link>` tags.
567
568 Example:
569
570 ```yaml
571 extra_css:
572 - css/extra.css
573 - css/second_extra.css
574 ```
575
576 **default**: `[]` (an empty list).
577
578 ### extra_javascript
579
580 Set a list of JavaScript files in your `docs_dir` to be included by the theme, as `<script>` tags.
581
582 > NEW: **Changed in version 1.5:**
583 >
584 > Older versions of MkDocs supported only a plain list of strings, but now several additional config keys are available: `type`, `async`, `defer`.
585
586 See the examples and what they produce:
587
588 ```yaml
589 extra_javascript:
590 - some_plain_javascript.js # <script src="some_plain_javascript.js"></script>
591 # New behavior in MkDocs 1.5:
592 - implicitly_as_module.mjs # <script src="implicitly_as_module.mjs" type="module"></script>
593 # Config keys only supported since MkDocs 1.5:
594 - path: explicitly_as_module.mjs # <script src="explicitly_as_module.mjs" type="module"></script>
595 type: module
596 - path: deferred_plain.js # <script src="deferred_plain.js" defer></script>
597 defer: true
598 - path: scripts/async_module.mjs # <script src="scripts/async_module.mjs" type="module" async></script>
599 type: module
600 async: true
601 ```
602
603 So, each item can be either:
604
605 * a plain string, or
606 * a mapping that has the required `path` key and 3 optional keys `type` (string), `async` (boolean), `defer` (boolean).
607
608 Only the plain string variant detects the `.mjs` extension and adds `type="module"`, otherwise `type: module` must be written out regardless of extension.
609
610 **default**: `[]` (an empty list).
611
612 NOTE: `*.js` and `*.css` files, just like any other type of file, are always copied from `docs_dir` into the site's deployed copy, regardless if they're linked to the pages via the above configs or not.
613
614 ### extra_templates
615
616 Set a list of templates in your `docs_dir` to be built by MkDocs. To see more
617 about writing templates for MkDocs read the documentation about [custom themes]
618 and specifically the section about the [available variables] to
619 templates. See the example in [extra_css] for usage.
620
621 **default**: `[]` (an empty list).
622
623 ### extra
624
625 A set of key-value pairs, where the values can be any valid YAML construct, that
626 will be passed to the template. This allows for great flexibility when creating
627 custom themes.
628
629 For example, if you are using a theme that supports displaying the project
630 version, you can pass it to the theme like this:
631
632 ```yaml
633 extra:
634 version: 1.0
635 ```
636
637 **default**: By default `extra` will be an empty key-value mapping.
638
639 ## Preview controls
640
641 ## Live Reloading
642
643 ### watch
644
645 Determines additional directories to watch when running `mkdocs serve`.
646 Configuration is a YAML list.
647
648 ```yaml
649 watch:
650 - directory_a
651 - directory_b
652 ```
653
654 Allows a custom default to be set without the need to pass it through the `-w`/`--watch`
655 option every time the `mkdocs serve` command is called.
656
657 > NOTE:
658 > The paths provided via the configuration file are relative to the configuration file.
659 >
660 > The paths provided via the `-w`/`--watch` CLI parameters are not.
661
662 ### use_directory_urls
663
664 This setting controls the directory structure of the generated documentation, and thereby the URL format used for linking to pages.
665
666 The following tables demonstrate how the directory structure and URLs used on the site differ when
667 setting `use_directory_urls` to `true` or `false`.
668
669 **`use_directory_urls: false`**
670
671 This setting is needed when the documentation is hosted on systems that can't
672 access the file `X/index.html` when given the URL `X`. When set to `false`,
673 no additional `X` directory is created, and the file is simply stored as `X.html`.
674 Links are created that point directly to the target *file* rather than a target
675 *directory*.
676
677 Source file | Generated File | URL Format
678 ---------------- | ------------------ | -------------------
679 index.md | index.html | /index.html
680 api-guide.md | api-guide.html | /api-guide.html
681 about/license.md | about/license.html | /about/license.html
682
683 For example, this needs to be set to `false` when:
684
685 * opening pages directly from the file system
686 * publishing the documentation to a static S3 website.
687
688 **`use_directory_urls: true`**
689
690 The default style of `use_directory_urls: true` creates more user friendly URLs,
691 and is usually what you'll want to use.
692
693 Source file | Generated File | URL Format
694 ---------------- | ------------------------- | --------------
695 index.md | /index.html | /
696 api-guide.md | /api-guide/index.html | /api-guide/
697 about/license.md | /about/license/index.html | /about/license
698
699 **default**: `true`
700
701 ### strict
702
703 Determines how warnings are handled. Set to `true` to halt processing when a
704 warning is raised. Set to `false` to print a warning and continue processing.
705
706 This is also available as a command line flag: `--strict`.
707
708 **default**: `false`
709
710 ### dev_addr
711
712 Determines the address used when running `mkdocs serve`. Must be of the format
713 `IP:PORT`.
714
715 Allows a custom default to be set without the need to pass it through the
716 `--dev-addr` option every time the `mkdocs serve` command is called.
717
718 **default**: `'127.0.0.1:8000'`
719
720 See also: [site_url](#site_url).
721
722 ## Formatting options
723
724 ### markdown_extensions
725
726 MkDocs uses the [Python Markdown][pymkd] library to translate Markdown files
727 into HTML. Python Markdown supports a variety of [extensions][pymdk-extensions]
728 that customize how pages are formatted. This setting lets you enable a list of
729 extensions beyond the ones that MkDocs uses by default (`meta`, `toc`, `tables`,
730 and `fenced_code`).
731
732 For example, to enable the [SmartyPants typography extension][smarty], use:
733
734 ```yaml
735 markdown_extensions:
736 - smarty
737 ```
738
739 Some extensions provide configuration options of their own. If you would like to
740 set any configuration options, then you can nest a key/value mapping
741 (`option_name: option value`) of any options that a given extension supports.
742 See the documentation for the extension you are using to determine what options
743 they support.
744
745 For example, to enable permalinks in the (included) `toc` extension, use:
746
747 ```yaml
748 markdown_extensions:
749 - toc:
750 permalink: true
751 ```
752
753 Note that a colon (`:`) must follow the extension name (`toc`) and then on a new
754 line the option name and value must be indented and separated by a colon. If you
755 would like to define multiple options for a single extension, each option must be
756 defined on a separate line:
757
758 ```yaml
759 markdown_extensions:
760 - toc:
761 permalink: true
762 separator: "_"
763 ```
764
765 Add an additional item to the list for each extension. If you have no
766 configuration options to set for a specific extension, then simply omit options
767 for that extension:
768
769 ```yaml
770 markdown_extensions:
771 - smarty
772 - toc:
773 permalink: true
774 - sane_lists
775 ```
776
777 > NOTE: **Dynamic config values.**
778 >
779 > To dynamically configure the extensions, you can get the config values from [environment variables](#environment-variables) or [obtain paths](#paths-relative-to-the-current-file-or-site) of the currently rendered Markdown file or the overall MkDocs site.
780
781 In the above examples, each extension is a list item (starts with a `-`). As an
782 alternative, key/value pairs can be used instead. However, in that case an empty
783 value must be provided for extensions for which no options are defined.
784 Therefore, the last example above could also be defined as follows:
785
786 ```yaml
787 markdown_extensions:
788 smarty: {}
789 toc:
790 permalink: true
791 sane_lists: {}
792 ```
793
794 This alternative syntax is required if you intend to override some options via
795 [inheritance].
796
797 > NOTE: **More extensions.**
798 >
799 > The Python-Markdown documentation provides a [list of extensions][exts]
800 > which are available out-of-the-box. For a list of configuration options
801 > available for a given extension, see the documentation for that extension.
802 >
803 > You may also install and use various third party extensions ([Python-Markdown wiki], [MkDocs project catalog][catalog]). Consult
804 > the documentation provided by those extensions for installation instructions
805 > and available configuration options.
806
807 **default**: `[]` (an empty list).
808
809 ### hooks
810
811 NEW: **New in version 1.4.**
812
813 A list of paths to Python scripts (relative to `mkdocs.yml`) that are loaded and used as [plugin](#plugins) instances.
814
815 For example:
816
817 ```yaml
818 hooks:
819 - my_hooks.py
820 ```
821
822 Then the file `my_hooks.py` can contain any [plugin event handlers](../dev-guide/plugins.md#events) (without `self`), e.g.:
823
824 ```python
825 def on_page_markdown(markdown, **kwargs):
826 return markdown.replace('a', 'z')
827 ```
828
829 >? EXAMPLE: **Advanced example:**
830 >
831 > This produces warnings based on the Markdown content (and warnings are fatal in [strict](#strict) mode):
832 >
833 > ```python
834 > import logging, re
835 > import mkdocs.plugins
836 >
837 > log = logging.getLogger('mkdocs')
838 >
839 > @mkdocs.plugins.event_priority(-50)
840 > def on_page_markdown(markdown, page, **kwargs):
841 > path = page.file.src_uri
842 > for m in re.finditer(r'\bhttp://[^) ]+', markdown):
843 > log.warning(f"Documentation file '{path}' contains a non-HTTPS link: {m[0]}")
844 > ```
845
846 This does not enable any new abilities compared to [plugins][], it only simplifies one-off usages, as these don't need to be *installed* like plugins do.
847
848 Note that for `mkdocs serve` the hook module will *not* be reloaded on each build.
849
850 You might have seen this feature in the [mkdocs-simple-hooks plugin](https://github.com/aklajnert/mkdocs-simple-hooks). If using standard method names, it can be directly replaced, e.g.:
851
852 ```diff
853 -plugins:
854 - - mkdocs-simple-hooks:
855 - hooks:
856 - on_page_markdown: 'my_hooks:on_page_markdown'
857 +hooks:
858 + - my_hooks.py
859 ```
860
861 > NEW: **New in MkDocs 1.6.**
862 >
863 > If a hook file has a file `foo.py` adjacent to it, it can use the normal Python syntax `import foo` to access its functions.
864 >
865 > In older versions of MkDocs, a workaround was necessary to make this work - adding the path to `sys.path`.
866
867 ### plugins
868
869 A list of plugins (with optional configuration settings) to use when building
870 the site. See the [Plugins] documentation for full details.
871
872 **default**: `['search']` (the "search" plugin included with MkDocs).
873
874 If the `plugins` config setting is defined in the `mkdocs.yml` config file, then
875 any defaults (such as `search`) are ignored and you need to explicitly re-enable
876 the defaults if you would like to continue using them:
877
878 ```yaml
879 plugins:
880 - search
881 - your_other_plugin
882 ```
883
884 To define options for a given plugin, use a nested set of key/value pairs:
885
886 ```yaml
887 plugins:
888 - search
889 - your_other_plugin:
890 option1: value
891 option2: other value
892 ```
893
894 To completely disable all plugins, including any defaults, set the `plugins`
895 setting to an empty list:
896
897 ```yaml
898 plugins: []
899 ```
900
901 #### `enabled` option
902
903 > NEW: **New in MkDocs 1.6.**
904 >
905 > Each plugin has its own options keys. However MkDocs also ensures that each plugin has the `enabled` boolean option. This can be used to conditionally enable a particular plugin, as in the following example:
906 >
907 > ```yaml
908 > plugins:
909 > - search
910 > - code-validator:
911 > enabled: !ENV [LINT, false]
912 > ```
913 >
914 > See: [Environment variables](#environment-variables)
915
916 #### Alternate syntax
917
918 In the above examples, each plugin is a list item (starts with a `-`). As an
919 alternative, key/value pairs can be used instead. However, in that case an empty
920 value must be provided for plugins for which no options are defined. Therefore,
921 the last example above could also be defined as follows:
922
923 ```yaml
924 plugins:
925 search: {}
926 your_other_plugin:
927 option1: value
928 option2: other value
929 ```
930
931 This alternative syntax is required if you intend to override some options via
932 [inheritance].
933
934 #### Search
935
936 A search plugin is provided by default with MkDocs which uses [lunr.js] as a
937 search engine. The following config options are available to alter the behavior
938 of the search plugin:
939
940 ##### **separator**
941
942 A regular expression which matches the characters used as word separators when
943 building the index. By default whitespace and the hyphen (`-`) are used. To add
944 the dot (`.`) as a word separator you might do this:
945
946 ```yaml
947 plugins:
948 - search:
949 separator: '[\s\-\.]+'
950 ```
951
952 **default**: `'[\s\-]+'`
953
954 ##### **min_search_length**
955
956 An integer value that defines the minimum length for a search query. By default
957 searches shorter than 3 chars in length are ignored as search result quality with
958 short search terms are poor. However, for some use cases (such as documentation
959 about Message Queues which might generate searches for 'MQ') it may be preferable
960 to set a shorter limit.
961
962 ```yaml
963 plugins:
964 - search:
965 min_search_length: 2
966 ```
967
968 **default**: 3
969
970 ##### **lang**
971
972 A list of languages to use when building the search index as identified by their
973 [ISO 639-1] language codes. With [Lunr Languages], the following languages are
974 supported:
975
976 * `ar`: Arabic
977 * `da`: Danish
978 * `nl`: Dutch
979 * `en`: English
980 * `fi`: Finnish
981 * `fr`: French
982 * `de`: German
983 * `hu`: Hungarian
984 * `it`: Italian
985 * `ja`: Japanese
986 * `no`: Norwegian
987 * `pt`: Portuguese
988 * `ro`: Romanian
989 * `ru`: Russian
990 * `es`: Spanish
991 * `sv`: Swedish
992 * `th`: Thai
993 * `tr`: Turkish
994 * `vi`: Vietnamese
995
996 You may [contribute additional languages].
997
998 WARNING:
999 While search does support using multiple languages together, it is best not
1000 to add additional languages unless you really need them. Each additional
1001 language adds significant bandwidth requirements and uses more browser
1002 resources. Generally, it is best to keep each instance of MkDocs to a single
1003 language.
1004
1005 NOTE:
1006 Lunr Languages does not currently include support for Chinese or other Asian
1007 languages. However, some users have reported decent results using Japanese.
1008
1009 **default**: The value of `theme.locale` if set, otherwise `[en]`.
1010
1011 ##### **prebuild_index**
1012
1013 Optionally generates a pre-built index of all pages, which provides some
1014 performance improvements for larger sites. Before enabling, confirm that the
1015 theme you are using explicitly supports using a prebuilt index (the builtin
1016 themes do). Set to `true` to enable.
1017
1018 WARNING:
1019 This option requires that [Node.js] be installed and the command `node` be
1020 on the system path. If the call to `node` fails for any reason, a warning
1021 is issued and the build continues uninterrupted. You may use the `--strict`
1022 flag when building to cause such a failure to raise an error instead.
1023
1024 NOTE:
1025 On smaller sites, using a pre-built index is not recommended as it creates a
1026 significant increase is bandwidth requirements with little to no noticeable
1027 improvement to your users. However, for larger sites (hundreds of pages),
1028 the bandwidth increase is relatively small and your users will notice a
1029 significant improvement in search performance.
1030
1031 **default**: `False`
1032
1033 ##### **indexing**
1034
1035 Configures what strategy the search indexer will use when building the index
1036 for your pages. This property is particularly useful if your project is large
1037 in scale, and the index takes up an enormous amount of disk space.
1038
1039 ```yaml
1040 plugins:
1041 - search:
1042 indexing: 'full'
1043 ```
1044
1045 ###### Options
1046
1047 Option | Description
1048 ------ | -----------
1049 `full` | Indexes the title, section headings, and full text of each page.
1050 `sections` | Indexes the title and section headings of each page.
1051 `titles` | Indexes only the title of each page.
1052
1053 **default**: `full`
1054
1055 ## Special YAML tags
1056
1057 ### Environment variables
1058
1059 In most cases, the value of a configuration option is set directly in the
1060 configuration file. However, as an option, the value of a configuration option
1061 may be set to the value of an environment variable using the `!ENV` tag. For
1062 example, to set the value of the `site_name` option to the value of the
1063 variable `SITE_NAME` the YAML file may contain the following:
1064
1065 ```yaml
1066 site_name: !ENV SITE_NAME
1067 ```
1068
1069 If the environment variable is not defined, then the configuration setting
1070 would be assigned a `null` (or `None` in Python) value. A default value can be
1071 defined as the last value in a list. Like this:
1072
1073 ```yaml
1074 site_name: !ENV [SITE_NAME, 'My default site name']
1075 ```
1076
1077 Multiple fallback variables can be used as well. Note that the last value is
1078 not an environment variable, but must be a value to use as a default if none
1079 of the specified environment variables are defined.
1080
1081 ```yaml
1082 site_name: !ENV [SITE_NAME, OTHER_NAME, 'My default site name']
1083 ```
1084
1085 Simple types defined within an environment variable such as string, bool,
1086 integer, float, datestamp and null are parsed as if they were defined directly
1087 in the YAML file, which means that the value will be converted to the
1088 appropriate type. However, complex types such as lists and key/value pairs
1089 cannot be defined within a single environment variable.
1090
1091 For more details, see the [pyyaml_env_tag](https://github.com/waylan/pyyaml-env-tag)
1092 project.
1093
1094 ### Paths relative to the current file or site
1095
1096 NEW: **New in version 1.5.**
1097
1098 Some Markdown extensions can benefit from knowing the path of the Markdown file that's currently being processed, or just the root path of the current site. For that, the special tag `!relative` can be used in most contexts within the config file, though the only known usecases are within [`markdown_extensions`](#markdown_extensions).
1099
1100 Examples of the possible values are:
1101
1102 ```yaml
1103 - !relative # Relative to the directory of the current Markdown file
1104 - !relative $docs_dir # Path of the docs_dir
1105 - !relative $config_dir # Path of the directory that contains the main mkdocs.yml
1106 - !relative $config_dir/some/child/dir # Some subdirectory of the root config directory
1107 ```
1108
1109 (Here, `$docs_dir` and `$config_dir` are currently the *only* special prefixes that are recognized.)
1110
1111 Example:
1112
1113 ```yaml
1114 markdown_extensions:
1115 - pymdownx.snippets:
1116 base_path: !relative # Relative to the current Markdown file
1117 ```
1118
1119 This allows the [pymdownx.snippets] extension to include files relative to the current Markdown file, which without this tag it would have no way of knowing.
1120
1121 > NOTE: Even for the default case, any extension's base path is technically the *current working directory* although the assumption is that it's the *directory of mkdocs.yml*. So even if you don't want the paths to be relative, to improve the default behavior, always prefer to use this idiom:
1122 >
1123 > ```yaml
1124 > markdown_extensions:
1125 > - pymdownx.snippets:
1126 > base_path: !relative $config_dir # Relative to the root directory with mkdocs.yml
1127 > ```
1128
1129 ## Configuration Inheritance
1130
1131 Generally, a single file would hold the entire configuration for a site.
1132 However, some organizations may maintain multiple sites which all share a common
1133 configuration across them. Rather than maintaining separate configurations for
1134 each, the common configuration options can be defined in a parent configuration
1135 file which each site's primary configuration file inherits.
1136
1137 To define the parent for a configuration file, set the `INHERIT` (all caps) key
1138 to the path of the parent file. The path must be relative to the location of the
1139 primary file.
1140
1141 For configuration options to be merged with a parent configuration, those
1142 options must be defined as key/value pairs. Specifically, the
1143 [markdown_extensions] and [plugins](#plugins) options must use the alternative syntax
1144 which does not use list items (lines which start with `-`).
1145
1146 For example, suppose the common (parent) configuration is defined in `base.yml`:
1147
1148 ```yaml
1149 theme:
1150 name: mkdocs
1151 locale: en
1152 highlightjs: true
1153
1154 markdown_extensions:
1155 toc:
1156 permalink: true
1157 admonition: {}
1158 ```
1159
1160 Then, for the "foo" site, the primary configuration file would be defined at
1161 `foo/mkdocs.yml`:
1162
1163 ```yml
1164 INHERIT: ../base.yml
1165 site_name: Foo Project
1166 site_url: https://example.com/foo
1167 ```
1168
1169 When running `mkdocs build`, the file at `foo/mkdocs.yml` would be passed in as
1170 the configuration file. MkDocs will then parse that file, retrieve and parse the
1171 parent file `base.yml` and deep merge the two. This would result in MkDocs
1172 receiving the following merged configuration:
1173
1174 ```yaml
1175 site_name: Foo Project
1176 site_url: https://example.com/foo
1177
1178 theme:
1179 name: mkdocs
1180 locale: en
1181 highlightjs: true
1182
1183 markdown_extensions:
1184 toc:
1185 permalink: true
1186 admonition: {}
1187 ```
1188
1189 Deep merging allows you to add and/or override various values in your primary
1190 configuration file. For example, suppose for one site you wanted to add support
1191 for definition lists, use a different symbol for permalinks, and define a
1192 different separator. In that site's primary configuration file you could do:
1193
1194 ```yaml
1195 INHERIT: ../base.yml
1196 site_name: Bar Project
1197 site_url: https://example.com/bar
1198
1199 markdown_extensions:
1200 def_list: {}
1201 toc:
1202 permalink: 
1203 separator: "_"
1204 ```
1205
1206 In that case, the above configuration would be deep merged with `base.yml` and
1207 result in the following configuration:
1208
1209 ```yaml
1210 site_name: Bar Project
1211 site_url: https://example.com/bar
1212
1213 theme:
1214 name: mkdocs
1215 locale: en
1216 highlightjs: true
1217
1218 markdown_extensions:
1219 def_list: {}
1220 toc:
1221 permalink: 
1222 separator: "_"
1223 admonition: {}
1224 ```
1225
1226 Notice that the `admonition` extension was retained from the parent
1227 configuration, the `def_list` extension was added, the value of
1228 `toc.permalink` was replaced, and the value of `toc.separator` was added.
1229
1230 You can replace or merge the value of any key. However, any non-key is always
1231 replaced. Therefore, you cannot append items to a list. You must redefine the
1232 entire list.
1233
1234 As the [nav] configuration is made up of nested lists, this means that you
1235 cannot merge navigation items. Of course, you can replace the entire `nav`
1236 configuration with a new one. However, it is generally expected that the entire
1237 navigation would be defined in the primary configuration file for a project.
1238
1239 WARNING:
1240 As a reminder, all path based configuration options must be relative to the
1241 primary configuration file and MkDocs does not alter the paths when merging.
1242 Therefore, defining paths in a parent file which is inherited by multiple
1243 different sites may not work as expected. It is generally best to define
1244 path based options in the primary configuration file only.
1245
1246 The inheritance can also be used as a quick way to override keys on the command line - by using stdin as the config file. For example:
1247
1248 ```bash
1249 echo '{INHERIT: mkdocs.yml, site_name: "Renamed site"}' | mkdocs build -f -
1250 ```
1251
1252 [Theme Developer Guide]: ../dev-guide/themes.md
1253 [custom themes]: ../dev-guide/themes.md
1254 [available variables]: ../dev-guide/themes.md#template-variables
1255 [pymdk-extensions]: https://python-markdown.github.io/extensions/
1256 [pymkd]: https://python-markdown.github.io/
1257 [smarty]: https://python-markdown.github.io/extensions/smarty/
1258 [exts]: https://python-markdown.github.io/extensions/
1259 [Python-Markdown wiki]: https://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensions
1260 [catalog]: https://github.com/mkdocs/catalog
1261 [configuring pages and navigation]: writing-your-docs.md#configure-pages-and-navigation
1262 [Meta-Data]: writing-your-docs.md#meta-data
1263 [theme_dir]: customizing-your-theme.md#using-the-theme-custom_dir
1264 [choosing your theme]: choosing-your-theme.md
1265 [Localizing your theme]: localizing-your-theme.md
1266 [extra_css]: #extra_css
1267 [Plugins]: ../dev-guide/plugins.md
1268 [lunr.js]: https://lunrjs.com/
1269 [ISO 639-1]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
1270 [Lunr Languages]: https://github.com/MihaiValentin/lunr-languages#lunr-languages-----
1271 [contribute additional languages]: https://github.com/MihaiValentin/lunr-languages/blob/master/CONTRIBUTING.md
1272 [Node.js]: https://nodejs.org/
1273 [markdown_extensions]: #markdown_extensions
1274 [nav]: #nav
1275 [inheritance]: #configuration-inheritance
1276 [pymdownx.snippets]: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/