diff --git a/.editorconfig b/.editorconfig index eaff74302..4ae0589a6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -30,10 +30,6 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -# Markdown -[*.md] -trim_trailing_whitespace = false - # Python [*.py] indent_style = space diff --git a/Dockerfile b/Dockerfile index 9481ff466..5cd127a1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,11 +60,8 @@ RUN \ pip install --no-cache-dir . \ && \ if [ "${WITH_PLUGINS}" = "true" ]; then \ - pip install --no-cache-dir \ - "mkdocs-minify-plugin~=0.7" \ - "mkdocs-redirects~=1.2" \ - "pillow~=9.4" \ - "cairosvg~=2.6"; \ + pip install --no-cache-dir mkdocs-material[recommended] \ + pip install --no-cache-dir mkdocs-material[imaging]; \ fi \ && \ if [ -e user-requirements.txt ]; then \ diff --git a/docs/blog/posts/blog-support-just-landed.md b/docs/blog/posts/blog-support-just-landed.md index 6b65a7048..47a2733f8 100644 --- a/docs/blog/posts/blog-support-just-landed.md +++ b/docs/blog/posts/blog-support-just-landed.md @@ -168,9 +168,9 @@ In velit purus, dictum quis neque nec, molestie viverra risus. Nam pellentesque tellus id elit ultricies, vel finibus erat cursus. ``` -1. If you mark a post as a [draft], a red marker appears next to the post date - on index pages. When the site is built, drafts are not included in the - output. [This behavior can be changed], e.g. for rendering drafts when +1. If you mark a post as a [draft], a red marker appears next to the post date + on index pages. When the site is built, drafts are not included in the + output. [This behavior can be changed], e.g. for rendering drafts when building deploy previews. When you spin up the [live preview server], you should be greeted by your first @@ -233,7 +233,7 @@ Some ideas already proposed by users: part of a series, a list with links to all other posts should be included in the post's content. -- __Author indexes__: Besides [archive] and [category] indexes, authors should +- __Author indexes__: Besides [archive] and [category] indexes, authors should be able to create per-author indexes, which list all posts linked to an author. Additionally, a profile should be created for each author and linked from posts. diff --git a/docs/blog/posts/chinese-search-support.md b/docs/blog/posts/chinese-search-support.md index cf675cd61..4f06371e4 100644 --- a/docs/blog/posts/chinese-search-support.md +++ b/docs/blog/posts/chinese-search-support.md @@ -3,25 +3,25 @@ date: 2022-05-05 authors: [squidfunk] title: Chinese search support description: > - Insiders adds Chinese language support for the built-in search plugin – a + Insiders adds Chinese language support for the built-in search plugin – a feature that has been requested many times categories: - Search links: - blog/posts/search-better-faster-smaller.md - - setup/setting-up-site-search.md#chinese-language-support + - plugins/search.md#segmentation - insiders/index.md#how-to-become-a-sponsor --- # Chinese search support – 中文搜索​支持 -__Insiders adds experimental Chinese language support for the [built-in search +__Insiders adds experimental Chinese language support for the [built-in search plugin] – a feature that has been requested for a long time given the large number of Chinese users.__ After the United States and Germany, the third-largest country of origin of Material for MkDocs users is China. For a long time, the [built-in search plugin] -didn't allow for proper segmentation of Chinese characters, mainly due to +didn't allow for proper segmentation of Chinese characters, mainly due to missing support in [lunr-languages] which is used for search tokenization and stemming. The latest Insiders release adds long-awaited Chinese language support for the built-in search plugin, something that has been requested by many users. @@ -49,8 +49,8 @@ through the segmenter. You can install [jieba] with: pip install jieba ``` -The next step is only required if you specified the [`separator`][separator] -configuration in `mkdocs.yml`. Text is segmented with [zero-width whitespace] +The next step is only required if you specified the [`separator`][separator] +configuration in `mkdocs.yml`. Text is segmented with [zero-width whitespace] characters, so it renders exactly the same in the search modal. Adjust `mkdocs.yml` so that the [`separator`][separator] includes the `\u200b` character: @@ -65,14 +65,14 @@ That's all that is necessary. ## Usage -If you followed the instructions in the configuration guide, Chinese words will +If you followed the instructions in the configuration guide, Chinese words will now be tokenized using [jieba]. Try searching for -[:octicons-search-24: 支持][q=支持] to see how it integrates with the +[:octicons-search-24: 支持][q=支持] to see how it integrates with the built-in search plugin. --- -Note that this is an experimental feature, and I, @squidfunk, am not +Note that this is an experimental feature, and I, @squidfunk, am not proficient in Chinese (yet?). If you find a bug or think something can be improved, please [open an issue]. diff --git a/docs/blog/posts/excluding-content-from-search.md b/docs/blog/posts/excluding-content-from-search.md index 6c7b0d7b5..d84ef54c1 100644 --- a/docs/blog/posts/excluding-content-from-search.md +++ b/docs/blog/posts/excluding-content-from-search.md @@ -119,7 +119,7 @@ search: exclude: true --- -# Document title +# Page title ... ``` @@ -133,7 +133,7 @@ filtered by the search plugin before the page is rendered: === ":octicons-file-code-16: `docs/page.md`" ``` markdown - # Document title + # Page title ## Section 1 @@ -173,7 +173,7 @@ supported by the [Attribute Lists] extension: === ":octicons-file-code-16: `docs/page.md`" ``` markdown - # Document title + # Page title The content of this block is included diff --git a/docs/blog/posts/search-better-faster-smaller.md b/docs/blog/posts/search-better-faster-smaller.md index a6375d867..430be9cc5 100644 --- a/docs/blog/posts/search-better-faster-smaller.md +++ b/docs/blog/posts/search-better-faster-smaller.md @@ -176,10 +176,10 @@ which creates and manages the [lunr] search index. When search is initialized, the following steps are taken: [^1]: - Prior to :octicons-tag-24: 5.0.0, search was carried out in the main thread - which locked up the browser, rendering it unusable. This problem was first - reported in #904 and, after some back and forth, fixed and released in - :octicons-tag-24: 5.0.0. + Prior to , search was carried out in the main + thread which locked up the browser, rendering it unusable. This problem was + first reported in #904 and, after some back and forth, fixed and released in + . 1. __Linking sections with pages__: The search index is parsed, and each section is linked to its parent page. The parent page itself is _not @@ -196,7 +196,7 @@ the following steps are taken: > can achieve with a tokenizer that is capable of separating strings with > lookahead. -1. __Indexing__: As a final step, each section is indexed. When querying the +3. __Indexing__: As a final step, each section is indexed. When querying the index, if a search query includes one of the tokens as returned by step 2., the section is considered to be part of the search result and passed to the main thread. diff --git a/docs/browser-support.md b/docs/browser-support.md index 06ad4eb12..2ccbbb8f0 100644 --- a/docs/browser-support.md +++ b/docs/browser-support.md @@ -64,6 +64,4 @@ the following older browser versions might work with some additional effort: - :fontawesome-brands-internet-explorer: __Internet Explorer__ - no support, mainly due to missing support for [custom properties]. The last version of Material for MkDocs to support Internet Explorer is - [:octicons-tag-24: 4.6.3][IE support]. - - [IE support]: https://github.com/squidfunk/mkdocs-material/releases/tag/4.6.3 + . diff --git a/docs/contributing/reporting-a-bug.md b/docs/contributing/reporting-a-bug.md index 812c98838..5602bd7b7 100644 --- a/docs/contributing/reporting-a-bug.md +++ b/docs/contributing/reporting-a-bug.md @@ -148,7 +148,7 @@ summary of the issue, so the impact and severity of the bug you want to report can be inferred from the title. | | Example | -| -------- | -------- | +| -------- | -------- | | :material-check:{ style="color: #4DB6AC" } __Clear__ | Built-in `typeset` plugin changes precedence of nav title over `h1` | :material-close:{ style="color: #EF5350" } __Wordy__ | The built-in `typeset` plugin changes the precedence of the nav title over the document headline | :material-close:{ style="color: #EF5350" } __Unclear__ | Title does not work @@ -235,17 +235,17 @@ make it easier for us maintainers to improve the documentation. ### Reproduction A minimal reproduction is at the heart of every well-written bug report, as -it allows us maintainers to quickly recreate the necessary conditions to inspect -the bug and quickly find its root cause. It's a proven fact that issues with -concise and small reproductions can be fixed much faster. +it allows us maintainers to instantly recreate the necessary conditions to +inspect the bug to quickly find its root cause. It's a proven fact that issues +with concise and small reproductions can be fixed much faster. [:material-bug:  Create a reproduction][Create reproduction]{ .md-button .md-button--primary } --- -After you have created the reproduction, you should have a .zip file, ideally not -larger than 1 MB. Just drag and drop the .zip file into this field, which will -automatically upload it to GitHub. +After you have created the reproduction, you should have a `.zip` file, ideally +not larger than 1 MB. Just drag and drop the `.zip` file into this field, which +will automatically upload it to GitHub. > __Why we need this__: if an issue contains no minimal reproduction or just > a link to a repository with thousands of files, the maintainers would need to @@ -259,7 +259,7 @@ automatically upload it to GitHub. process. The reason is that the reproduction which is automatically produced by the [built-in info plugin] contains all of the necessary environment information that is often forgotten to be included. - + Additionally, there are many non-technical users of Material for MkDocs that have trouble creating repositories. @@ -301,7 +301,7 @@ only relevant when the bug you are reporting does not involve a crash when Thanks for following the guide and creating a high-quality and complete bug report – you are almost done. This section ensures that you have read this guide -and have worked to the best of your knowledge to provide us with everything we +and have worked to the best of your knowledge to provide us with everything we need to know to help you. __We'll take it from here.__ diff --git a/docs/conventions.md b/docs/conventions.md new file mode 100644 index 000000000..6b341fcce --- /dev/null +++ b/docs/conventions.md @@ -0,0 +1,88 @@ +# Conventions + +This section explains several conventions used in this documentation. + +## Symbols + +This documentation use some symbols for illustration purposes. Before you read +on, please make sure you've made yourself familiar with the following list of +conventions: + +### – Sponsors only { data-toc-label="Sponsors only" } + +The pumping heart symbol denotes that a specific feature or behavior is only +available to sponsors via [Insiders]. Make sure that you have access to +[Insiders] if you want to use the feature. + +### – Version { data-toc-label="Version" } + +The tag symbol in conjunction with a version number denotes when a specific +feature or behavior was added. Make sure you're at least on this version +if you want to use it. + +### – Version (Insiders) { data-toc-label="Version (Insiders)" } + +The tag symbol with a heart in conjunction with a version number denotes that a +specific feature or behavior was added to the [Insiders] version of Material for +MkDocs. + +### – Default value { #default data-toc-label="Default value" } + +Some properties in `mkdocs.yml` have default values for when the author does not +explicitly define them. The default value of the property is always included. + +#### – Default value is computed { #default data-toc-label="is computed" } + +Some default values are not set to static values but computed form other values, +like the site language, repository provider, or other settings. + +#### – Default value is empty { #default data-toc-label="is empty" } + +Some properties do not contain default values. This means that the functionality +that is associated with them is not available unless explicitly enabled. + +### – Metadata property { #metadata data-toc-label="Metadata property" } + +This symbol denotes that the thing described is a metadata property, which can +be used in Markdown documents as part of the front matter definition. + +### – Optional feature { #feature data-toc-label="Optional feature" } + +Most of the features are hidden behind feature flags, which means they must +be explicitly enabled via `mkdocs.yml`. This allows for the existence of +potentially orthogonal features. + +### – Experimental { data-toc-label="Experimental" } + +Some newer features are still considered experimental, which means the ymight +(although rarely) change at any time, including their complete removal (which +hasn't happened yet). + +### – Plugin { data-toc-label="Plugin" } + +Several features are implemented through MkDocs excellent plugin architecture, +some of which are built-in and distributed with Material for MkDocs, so no +installation is required. + +### – Markdown extension { data-toc-label="Markdown extension" } + +This symbol denotes that the thing described is a Markdown extension, which can +be enabled in `mkdocs.yml` and adds additional functionality to the Markdown +parser. + +### – Required value { #required data-toc-label="Required value" } + +Some (very few in fact) properties or settings are required, which means the +authors must explicitly define them. + +### – Customization { #customization data-toc-label="Customization" } + +This symbol denotes that the thing described is a customization that must be +added by the author. + +### – Utility { data-toc-label="Utility" } + +Besides plugins, there are some utilities that build on top of MkDocs in order +to provide extended functionality, like for example support for versioning. + + [Insiders]: insiders/index.md diff --git a/docs/creating-your-site.md b/docs/creating-your-site.md index 0a9d14138..dd6d6fee9 100644 --- a/docs/creating-your-site.md +++ b/docs/creating-your-site.md @@ -1,6 +1,6 @@ # Creating your site -After you've [installed] Material for MkDocs, you can bootstrap your project +After you've [installed] Material for MkDocs, you can bootstrap your project documentation using the `mkdocs` executable. Go to the directory where you want your project to be located and enter: @@ -48,7 +48,7 @@ theme: ???+ tip "Recommended: [configuration validation and auto-complete]" - In order to minimize friction and maximize productivity, Material for MkDocs + In order to minimize friction and maximize productivity, Material for MkDocs provides its own [schema.json][^1] for `mkdocs.yml`. If your editor supports YAML schema validation, it's definitely recommended to set it up: diff --git a/docs/customization.md b/docs/customization.md index bb1a9ce5a..7be12fc8c 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -225,7 +225,7 @@ to make more fundamental changes, it may be necessary to make the adjustments directly in the source of the theme and recompile it. [^1]: - Prior to :octicons-tag-24: 7.0.0 the build was based on Webpack, resulting + Prior to the build was based on Webpack, resulting in occasional broken builds due to incompatibilities with loaders and plugins. Therefore, we decided to swap Webpack for a leaner solution which is now based on [RxJS] as the application itself. This allowed for the diff --git a/docs/guides/creating-a-reproduction.md b/docs/guides/creating-a-reproduction.md index d61094aaf..d7a4faab9 100644 --- a/docs/guides/creating-a-reproduction.md +++ b/docs/guides/creating-a-reproduction.md @@ -1,8 +1,8 @@ # Creating a reproduction -A reproduction is a simplified version of a bug that demonstrates the specific -scenario in which the bug occurred. It includes all necessary minimal settings -and instructions and should be as simple as possible while still demonstrating +A reproduction is a simplified version of a bug that demonstrates the specific +scenario in which the bug occurred. It includes all necessary minimal settings +and instructions and should be as simple as possible while still demonstrating the issue. ## Guide @@ -87,7 +87,7 @@ inside it. Next: bug, create only the necessary amount of Markdown documents. __Repeat this step until the bug you want to report can be observed.__ -4. As a last step, before packing everything into a .zip file, double-check +4. As a last step, before packing everything into a `.zip` file, double-check all settings and documents if they are essential to the reproduction, which means that the bug does not occur when they are omitted. Remove all non-essential lines and files. @@ -95,11 +95,11 @@ inside it. Next: [bug reporting guide]: ../contributing/reporting-a-bug.md#upgrade-to-latest-version [minimal configuration]: ../creating-your-site.md#minimal-configuration -### Creating a .zip file +### Creating a `.zip` file Material for MkDocs 9.0.0 includes a new plugin solely intended to create reproductions for bug reports. When the built-in info plugin is enabled, MkDocs -will add all relevant files to a .zip, print a summary to the terminal and +will add all relevant files to a `.zip`, print a summary to the terminal and exit. Add the following lines to `mkdocs.yml`: ``` yaml diff --git a/docs/insiders/getting-started.md b/docs/insiders/getting-started.md index cd5341e78..d178e640a 100644 --- a/docs/insiders/getting-started.md +++ b/docs/insiders/getting-started.md @@ -6,7 +6,7 @@ title: Getting started with Insiders Material for MkDocs Insiders is a compatible drop-in replacement for Material for MkDocs, and can be installed similarly using [`pip`][pip], -[`docker`][docker] or [`git`][git]. Note that in order to access the Insiders +[`docker`][docker] or [`git`][git]. Note that in order to access the Insiders repository, you need to [become an eligible sponsor] of @squidfunk on GitHub. [pip]: #with-pip @@ -18,7 +18,7 @@ repository, you need to [become an eligible sponsor] of @squidfunk on GitHub. After you've been added to the list of collaborators and accepted the repository invitation, the next step is to create a [personal access token] for -your GitHub account in order to access the Insiders repository programmatically +your GitHub account in order to access the Insiders repository programmatically (from the command line or GitHub Actions workflows): 1. Go to https://github.com/settings/tokens @@ -66,7 +66,7 @@ comfortable self-hosting: 6. Install [Pull App] on your fork to stay in-sync with upstream The [`publish`][publish] workflow[^5] is automatically run when a new tag -(release) is created. When a new Insiders version is released on the upstream +(release) is created. When a new Insiders version is released on the upstream repository, the [Pull App] will create a pull request with the changes and pull in the new tag, which is picked up by the [`publish`][publish] workflow that builds and publishes the Docker image automatically to your private @@ -155,7 +155,33 @@ pip install --upgrade git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-materi When you're using built-in plugins that are solely available via Insiders, outside contributors won't be able to build your documentation project on their local machine. This is the reason why we developed the [built-in group plugin] -that allows to conditionally load plugins. +that allows to conditionally load plugins: + +``` yaml +plugins: + - search + - social + + # CI=1 mkdocs build + - group: + enabled: !ENV CI + plugins: + - git-revision-date-localized + - git-committers + + # INSIDERS=1 mkdocs build + - group: + enabled: !ENV INSIDERS + plugins: + - optimize + - privacy +``` + +Of course, you can also enable both groups with: + +``` +CI=1 INSIDERS=1 mkdocs build +``` [^1]: Previously we recommended to use [configuration inheritance] to work around @@ -164,63 +190,5 @@ that allows to conditionally load plugins. your project with the community edition and Insiders version of Material for MkDocs. - [built-in group plugin]: #built-in-group-plugin + [built-in group plugin]: ../plugins/group.md [configuration inheritance]: https://www.mkdocs.org/user-guide/configuration/#configuration-inheritance - -### Built-in group plugin - -[:octicons-tag-24: 9.3.0][Group plugin support] · -:octicons-cpu-24: Plugin · -:octicons-beaker-24: Experimental - -The built-in group plugin adds support for conditionally loading plugins based -on environments. This makes enabling and disabling of multiple plugins much -simpler, as you can group them into logical units and enable or disable them -with an [environment variable]: - -``` yaml -plugins: - - group: - enabled: !ENV CI - plugins: - - optimize - - minify -``` - -[`enabled`](#+group.enabled){ #+group.enabled } - -: :octicons-milestone-24: Default: `false` – This option specifies whether - the plugin is enabled when building your project. By default, the plugin is - disabled, so you can use an [environment variable]: - - ``` yaml - plugins: - - group: - enabled: !ENV CI - ``` - - Now, If you invoke MkDocs with that environment variable (or export the - environment variable before invoking MkDocs), the plugin will be enabled: - - ``` sh - CI=true mkdocs build - ``` - -[`plugins`](#+group.plugins){ #+group.plugins } - -: :octicons-milestone-24: Default: _none_ – This option specifies the plugins - that the group plugin should load when enabled. Note that the plugins must - be specified as a list, even if there's only one plugin: - - ``` yaml - plugins: - - group: - plugins: - - optimize - - minify - ``` - - The syntax is exactly the same as for all other plugins. - - [Group plugin support]: https://github.com/squidfunk/mkdocs-material/releases/tag/9.3.0 - [environment variable]: https://www.mkdocs.org/user-guide/configuration/#environment-variables diff --git a/docs/philosophy.md b/docs/philosophy.md index 13960e962..cff6baaff 100644 --- a/docs/philosophy.md +++ b/docs/philosophy.md @@ -13,12 +13,12 @@ discusses the [conventions] used in this documentation. a professional static site in minutes. No need to know HTML,CSS or JavaScript – let Material for MkDocs do the heavy lifting for you. -- __Works on all devices__: Serve your documentation with confidence – the - underlying layout automatically adapts to perfectly fit the available screen +- __Works on all devices__: Serve your documentation with confidence – the + underlying layout automatically adapts to perfectly fit the available screen estate, no matter the type or size of the viewing device. - __Made to measure__: Change the colors, fonts, language, icons, logo and much - more with a few lines of configuration. Material for MkDocs can be easily + more with a few lines of configuration. Material for MkDocs can be easily extended and provides tons of options to alter appearance and behavior. - __Fast and lightweight__: Don't let your users wait – get incredible value @@ -33,62 +33,3 @@ discusses the [conventions] used in this documentation. - __Open Source__: Trust 20,000+ users – choose a mature and well-funded solution built with state-of-the-art Open Source technologies. Keep ownership of your content without fear of vendor lock-in. Licensed under MIT. - -## Conventions - -### Symbols - -This documentation use some symbols for illustration purposes. Before you read -on, please make sure you've made yourself familiar with the following list of -conventions: - -[:octicons-heart-fill-24:{ .mdx-heart }   Insiders][Insiders]{ .mdx-insiders } - -: Some features are not yet available in the community edition, but only as - part of the Insiders build of Material for MkDocs. Please consult the - [Insiders] guide to learn how to get access. - -:octicons-tag-24:   __{x.x.x}__ - -: The tag icon in conjunction with a version number denotes when a specific - feature or behavior was added. Make sure you're at least on this version - if you want to use it. - -:octicons-file-code-24:   __{file.ext}__ - -: The source file icon together with a file name is sometimes used in code - examples which span multiple files. The file name (or path) always starts - from the location of `mkdocs.yml`. - -:octicons-milestone-24:   __Default__: _value_ - -: Some properties in `mkdocs.yml` have default values for when the author - does not explicitly define them. The default value of the property is always - included. - -:octicons-unlock-24:   __Feature flag__ - -: Most of the features are hidden behind feature flags, which means they must - be explicitly enabled via `mkdocs.yml`. This allows for the existence of - potentially orthogonal features. - -:octicons-beaker-24:   __Experimental__ - -: Some newer features are still considered experimental, which means they - might (although rarely) change at any time, including their complete removal - (which hasn't happened yet). - - -:octicons-cpu-24:   __Plugin__ - -: Several features are implemented through MkDocs excellent plugin - architecture, some of which are built-in and distributed with Material for - MkDocs, so no installation is required. - -:octicons-package-24:   __Utility__ - -: Besides plugins, there are some utilities that build on top of MkDocs in - order to provide extended functionality, like for example support for - versioning. - - [Insiders]: insiders/index.md diff --git a/docs/plugins/blog.md b/docs/plugins/blog.md new file mode 100644 index 000000000..901e37473 --- /dev/null +++ b/docs/plugins/blog.md @@ -0,0 +1,1460 @@ +--- +title: Built-in blog plugin +icon: material/newspaper-variant-outline +--- + +# Built-in blog plugin + +The blog plugin makes it very easy to build a blog, either as a sidecar to +your documentation or as the main thing. Focus on your content while the plugin +does all the heavy lifting, generating a view of all latest posts, [archive] and +[category] pages, configurable [pagination] and much more. + + [archive]: #archive + [category]: #categories + [pagination]: #pagination + +## Objective + +### How it works + +The plugin scans the configured [`posts` directory][config.post_dir] for +`.md` files from which paginated views[^1] are automatically generated. If not +configured otherwise, the plugin expects that your project has the following +directory layout, and will create any missing directories or files for you: + + [^1]: + Views are pages that are automatically generated, i.e., the entry point to + your blog listing all latest posts, as well as [archive] and [category] + pages that list all posts associated with them through [metadata] in + chronological order. + +``` { .sh .no-copy } +. +├─ docs/ +│ └─ blog/ +│ ├─ posts/ +│ └─ index.md +└─ mkdocs.yml +``` + +The `index.md` file in the [`blog` directory][config.blog_dir] is the entry +point to your blog – a paginated view listing all posts in reverse chronological +order. Besides that, the plugin supports automatically creating [archive] and +[category] pages that list a subset of posts for a time interval or category. + +[Post URLs][config.post_url_format] are completely configurable, no matter if +you want your URLs to include the post's date or not. Rendered dates always +display in the locale of the [site language] of your project. Like in other +static blog frameworks, posts can be annotated with a variety of [metadata], +allowing for easy integration with other [built-in plugins], e.g., the +[social] and [tags] plugin. + +Posts can be organized in nested folders with a directory layout that suits your +specific needs, and can make use of all components and syntax that Material for +MkDocs offers, including [admonitions], [annotations], [code blocks], +[content tabs], [diagrams], [icons], [math], and more. + + [metadata]: #metadata + [built-in plugins]: index.md + [social]: social.md + [tags]: tags.md + [admonitions]: ../reference/admonitions.md + [annotations]: ../reference/annotations.md + [code blocks]: ../reference/code-blocks.md + [content tabs]: ../reference/content-tabs.md + [diagrams]: ../reference/diagrams.md + [icons]: ../reference/icons-emojis.md + [math]: ../reference/math.md + +### When to use it + +If you want to add a blog to your project, or migrate from another blog +framework to Material for MkDocs because of its excellent technical writing +capabilities, this plugin is a great choice, as it integrates perfectly with +many other built-in plugins: + +
+ +- :material-file-tree:   __[Built-in meta plugin][meta]__ + + --- + + The meta plugin makes it easy to apply [metadata] to a subset of posts, + including authors, tags, categories, draft status, as well as social card + layouts. + + --- + + __Simpler organization, categorization and management of post metadata__ + +- :material-share-circle:   __[Built-in social plugin][social]__ + + --- + + The social plugin automatically generates beautiful and customizable + social cards for each post and page, showing as previews on social media. + + --- + + __Links to your blog render beautiful social cards when shared on social + media__ + +- :material-rabbit:   __[Built-in optimize plugin][optimize]__ + + --- + + The optimize plugin automatically identifies and optimizes all media files + that you reference in your project by using compression and conversion + techniques. + + --- + + __Your blog loads faster as smaller images are served to your users__ + +- :material-tag-text:   __[Built-in tags plugin][tags]__ + + --- + + The tags plugin allows to categorize posts alongside with pages in your + project, to improve their discoverability and connect posts to your + documentation. + + --- + + __Your documentation's tag system integrates with your blog__ + +
+ + [meta]: meta.md + [social]: social.md + [optimize]: optimize.md + [tags]: tags.md + +## Configuration + + + + + + +As with all [built-in plugins], getting started with the blog plugin is +straightforward. Just add the following lines to `mkdocs.yml`, and you can +start writing your first post: + +``` yaml +plugins: + - blog +``` + +The blog plugin is built into Material for MkDocs and doesn't need to be +installed. + + [blog]: blog.md + [built-in plugins]: index.md + +### General + +The following settings are available: + +--- + +#### + + + + +Use this setting to enable or disable the plugin when [building your project]. +It's normally not necessary to specify this setting, but if you want to disable +the plugin, use: + +``` yaml +plugins: + - blog: + enabled: false +``` + + [building your project]: ../creating-your-site.md#building-your-site + +--- + +#### + + + + +Use this setting to change the path where your blog is located in the +[`docs` directory][mkdocs.docs_dir]. The path is included in the generated +URLs as a prefix for all posts and views. You can change it with: + +=== "Documentation + Blog" + + ``` yaml + plugins: + - blog: + blog_dir: blog + ``` + +=== "Blog only" + + ``` yaml + plugins: + - blog: + blog_dir: . + ``` + +The provided path is resolved from the [`docs` directory][mkdocs.docs_dir]. + +--- + +#### + + + + +Use this setting to leverage the table of contents to display post titles in +views. The value of this setting is inherited by [`archive_toc`] +[config.archive_toc] and [`categories_toc`][config.categories_toc], +unless they are explicitly set: + +``` yaml +plugins: + - blog: + blog_toc: true +``` + +### Posts + +The following settings are available for posts: + +--- + +#### + + + + +Use this setting to change the folder where your posts are located. It's +normally not necessary to change this setting, but if you want to rename the +folder or change its file system location, use: + +``` yaml +plugins: + - blog: + post_dir: "{blog}/articles" +``` + +Note that the [`posts` directory][config.post_dir] is solely used for post +organization – it is not included in post URLs, since they are automatically +and comfortably generated by this plugin. + +The following placeholders are available: + +- `blog` – [`blog` directory][config.blog_dir] + +The provided path is resolved from the [`docs` directory][mkdocs.docs_dir]. + +--- + +#### + + + + +Use this setting to change the date format of posts. This plugin uses [babel] +to render dates in the configured [site language]. You can use [babel]'s +[pattern syntax] or the following shortcodes: + +=== "Monday, January 31, 2023" + + ``` yaml + plugins: + - blog: + post_date_format: full + ``` + +=== "January 31, 2023" + + ``` yaml + plugins: + - blog: + post_date_format: long + ``` + +=== "Jan 31, 2023" + + ``` yaml + plugins: + - blog: + post_date_format: medium + ``` + +=== "1/31/22" + + ``` yaml + plugins: + - blog: + post_date_format: short + ``` + +Note that depending on the [site language], results might look different for +other languages. + + [babel]: https://pypi.org/project/Babel/ + [site language]: ../setup/changing-the-language.md#site-language + [pattern syntax]: https://babel.pocoo.org/en/latest/dates.html#pattern-syntax + +--- + +#### + + + + +Use this setting to change the date format used in post URLs. The format string +must adhere to [babel]'s [pattern syntax] and should not contain whitespace. +Some popular choices: + +=== ":material-link: blog/2023/01/31/:material-dots-horizontal:/" + + ``` yaml + plugins: + - blog: + post_url_date_format: yyyy/MM/dd + ``` + +=== ":material-link: blog/2023/01/:material-dots-horizontal:/" + + ``` yaml + plugins: + - blog: + post_url_date_format: yyyy/MM + ``` + +=== ":material-link: blog/2023/:material-dots-horizontal:/" + + ``` yaml + plugins: + - blog: + post_url_date_format: yyyy + ``` + +If you want to remove the date from post URLs, e.g., when your blog features +mostly evergreen content, you can remove the `date` placeholder from the +[`post_url_format`][config.post_url_format] format string. + +--- + +#### + + + + +Use this setting to change the format string that is used when generating post +URLs. You can freely combine placeholders, and join them with slashes or other +characters: + +=== ":material-link: blog/2023/:material-dots-horizontal:/" + + ``` yaml + plugins: + - blog: + post_url_format: "{date}/{slug}" + ``` + +=== ":material-link: blog/:material-dots-horizontal:/" + + ``` yaml + plugins: + - blog: + post_url_format: "{slug}" + ``` + +The following placeholders are available: + +- `categories` – Post categories, slugified with [`categories_slugify`][config.categories_slugify] +- `date` – Post date, formatted with [`post_url_date_format`][config.post_url_date_format] +- `slug` – Post title, slugified with [`post_slugify`][config.post_slugify], or explicitly set via [`slug`][meta.slug] metadata property +- `file` – Post filename without `.md` file extension + +If you remove the `date` placeholder, make sure that post URLs don't collide +with URLs of other pages hosted under the [`blog` directory][config.blog_dir], +as this leads to undefined behavior. + +--- + +#### + + + + +Use this setting to set an upper bound for the number of categories included in +post URLs if the `categories` placeholder is part of [`post_url_format`] +[config.post_url_format] and the post defines categories: + +``` yaml +plugins: + - blog: + post_url_format: "{categories}/{slug}" + post_url_max_categories: 2 +``` + +If more than one category is given, they are joined with `/` after slugifying. + +--- + +#### + + + + +Use this setting to change the function to use for generating URL-compatible +slugs from post titles. [Python Markdown Extensions] comes with a Unicode-aware +[`slugify`][pymdownx.slugs.slugify] function: + +=== "Unicode" + + ``` yaml + plugins: + - blog: + post_slugify: !!python/object/apply:pymdownx.slugs.slugify + kwds: + case: lower + ``` + +=== "Unicode, case-sensitive" + + ``` yaml + plugins: + - blog: + post_slugify: !!python/object/apply:pymdownx.slugs.slugify + ``` + +When your project features non-European languages, it's advisable to use this +configuration. Of course, you can also provide a custom slugification function +for more granular control. + + [toc.slugify]: https://github.com/Python-Markdown/markdown/blob/1337d0891757e192165668d2606db36cf08e65a9/markdown/extensions/toc.py#L26-L33 + [pymdownx.slugs.slugify]: https://github.com/facelessuser/pymdown-extensions/blob/01c91ce79c91304c22b4e3d7a9261accc931d707/pymdownx/slugs.py#L59-L65 + [Python Markdown Extensions]: https://facelessuser.github.io/pymdown-extensions/extras/slugs/ + +--- + +#### + + + + +Use this setting to change the separator that is passed to the slugification +function set as part of [`post_slugify`][config.post_slugify]. While the default +is a hyphen, it can be set to any string, e.g., `_`: + +``` yaml +plugins: + - blog: + post_slugify_separator: _ +``` + +--- + +#### + + + + +By default, the plugin makes post excerpts optional. When a post doesn't define +an excerpt, views include the entire post. This setting can be used to make +post excerpts required: + +=== "Optional" + + ``` yaml + plugins: + - blog: + post_excerpt: optional + ``` + +=== "Required" + + ``` yaml + plugins: + - blog: + post_excerpt: required + ``` + +When post excerpts are required, posts without excerpt separators raise an +error. Thus, this setting is useful when you want to make sure that all posts +have excerpts defined. + +--- + +#### + + + + +Use this setting to set an upper bound for the number of authors rendered in +post excerpts. While each post may be written by multiple authors, this setting +allows to limit the display to just a few or even a single author, or disable +authors in post excerpts: + +=== "Render up to 2 authors" + + ``` yaml + plugins: + - blog: + post_excerpt_max_authors: 2 + ``` + +=== "Disable authors" + + ``` yaml + plugins: + - blog: + post_excerpt_max_authors: 0 + ``` + +This only applies to post excerpts in views. Posts always render all authors. + +--- + +#### + + + + +Use this setting to set an upper bound for the number of categories rendered in +post excerpts. While each post may be assigned to multiple categories, this +setting allows to limit the display to just a few or even a single category, or +disable categories in post excerpts: + +=== "Render up to 2 categories" + + ``` yaml + plugins: + - blog: + post_excerpt_max_categories: 2 + ``` + +=== "Disable categories" + + ``` yaml + plugins: + - blog: + post_excerpt_max_categories: 0 + ``` + +This only applies to post excerpts in views. Posts always render all categories. + +--- + +#### + + + + +Use this setting to set the separator the plugin will look for in a post's +content when generating post excerpts. All content __before__ the separator is +considered to be part of the excerpt: + +``` yaml +plugins: + - blog: + post_excerpt_separator: +``` + +It is common practice to use an HTML comment as a separator. + +--- + +#### + + + + +Use this setting to control whether the plugin should automatically compute the +reading time of a post, which is then rendered in post excerpts, as well as in +posts themselves: + +``` yaml +plugins: + - blog: + post_readtime: false +``` + +--- + +#### + + + + +Use this setting to change the number of words that a reader is expected to read +per minute when computing the reading time of a post. If you want to fine-tune +it, use: + +``` yaml +plugins: + - blog: + post_readtime_words_per_minute: 300 +``` + +A reading time of 265 words per minute is considered to be the +[average reading time of an adult]. + + [average reading time of an adult]: https://help.medium.com/hc/en-us/articles/214991667-Read-time + +### Archive + +The following settings are available for archive pages: + +--- + +#### + + + + +Use this setting to enable or disable archive pages. An archive page shows all +posts for a specific interval (e.g. year, month, etc.) in reverse order. If you +want to disable archive pages, use: + +``` yaml +plugins: + - blog: + archive: false +``` + +--- + +#### + + + + +Use this setting to change the title of the archive section the plugin adds to +the navigation. If this setting is omitted, it's sourced from the translations. +If you want to change it, use: + +``` yaml +plugins: + - blog: + archive_name: Archive +``` + +--- + +#### + + + + +Use this setting to change the date format used for archive page titles. The +format string must adhere to [babel]'s [pattern syntax]. Some popular choices: + +=== "2023" + + ``` yaml + plugins: + - blog: + archive_date_format: yyyy + ``` + +=== "January 2023" + + ``` yaml + plugins: + - blog: + archive_date_format: MMMM yyyy + ``` + +Note that depending on the [site language], results might look different for +other languages. + +--- + +#### + + + + +Use this setting to change the date format used for archive page URLs. The +format string must adhere to [babel]'s [pattern syntax] and should not contain +whitespace. Some popular choices: + +=== ":material-link: blog/archive/2023/" + + ``` yaml + plugins: + - blog: + archive_url_date_format: yyyy + ``` + +=== ":material-link: blog/archive/2023/01/" + + ``` yaml + plugins: + - blog: + archive_url_date_format: yyyy/MM + ``` + +--- + +#### + + + + +Use this setting to change the format string that is used when generating +archive page URLs. You can freely combine placeholders, and join them with +slashes or other characters: + +=== ":material-link: blog/archive/2023/" + + ``` yaml + plugins: + - blog: + archive_url_format: "archive/{date}" + ``` + +=== ":material-link: blog/2023/" + + ``` yaml + plugins: + - blog: + archive_url_format: "{date}" + ``` + +The following placeholders are available: + +- `date` – Archive date, formatted with [`archive_url_date_format`][config.archive_url_date_format] + +--- + +#### + + + + +Use this setting to leverage the table of contents to display post titles on all +archive pages. The value of this setting is inherited from [`blog_toc`] +[config.blog_toc], unless its explicitly set: + +``` yaml +plugins: + - blog: + archive_toc: true +``` + +### Categories + +The following settings are available for category pages: + +--- + +#### + + + + +Use this setting to enable or disable category pages. A category page shows all +posts for a specific category in reverse chronological order. If you want to +disable category pages, use: + +``` yaml +plugins: + - blog: + categories: false +``` + +--- + +#### + + + + +Use this setting to change the title of the category section the plugin adds to +the navigation. If this setting is omitted, it's sourced from the translations. +If you want to change it, use: + +``` yaml +plugins: + - blog: + categories_name: Categories +``` + +--- + +#### + + + + +Use this setting to change the format string that is used when generating +category page URLs. You can freely combine placeholders, and join them with +slashes or other characters: + +=== ":material-link: blog/category/:material-dots-horizontal:/" + + ``` yaml + plugins: + - blog: + categories_url_format: "category/{slug}" + ``` + +=== ":material-link: blog/:material-dots-horizontal:/" + + ``` yaml + plugins: + - blog: + categories_url_format: "{slug}" + ``` + +The following placeholders are available: + +- `slug` – Category, slugified with [`categories_slugify`][config.categories_slugify] + +--- + +#### + + + + +Use this setting to change the function to use for generating URL-compatible +slugs from categories. [Python Markdown Extensions] comes with a Unicode-aware +[`slugify`][pymdownx.slugs.slugify] function: + +=== "Unicode" + + ``` yaml + plugins: + - blog: + categories_slugify: !!python/object/apply:pymdownx.slugs.slugify + kwds: + case: lower + ``` + +=== "Unicode, case-sensitive" + + ``` yaml + plugins: + - blog: + categories_slugify: !!python/object/apply:pymdownx.slugs.slugify + ``` +When your project features non-European languages, it's advisable to use this +configuration. + +--- + +#### + + + + +Use this setting to change the separator that is passed to the slugification +function set as part of [`categories_slugify`][config.categories_slugify]. While +the default is a hyphen, it can be set to any string, e.g., `_`: + +``` yaml +plugins: + - blog: + categories_slugify_separator: _ +``` + +--- + +#### + + + + +The plugin allows to check categories against a predefined list, in order to +catch typos or make sure that categories are not arbitrarily added. Specify the +categories you want to allow with: + +``` yaml +plugins: + - blog: + categories_allowed: + - Search + - Performance +``` + +The plugin stops the build if a post references a category that is not part of +this list. Posts can be assigned to categories by using the [`categories`] +[meta.categories] metadata property. + +--- + +#### + + + + +Use this setting to leverage the table of contents to display post titles on all +category pages. The value of this setting is inherited from [`blog_toc`] +[config.blog_toc], unless its explicitly set: + +``` yaml +plugins: + - blog: + categories_toc: true +``` + +### Pagination + +The following settings are available for pagination: + +--- + +#### + + + + +Use this setting to enable or disable pagination in views – generated pages +that show posts or subsets of posts in reverse chronological order. If you want +to disable pagination, use: + +``` yaml +plugins: + - blog: + pagination: false +``` + +--- + +#### + + + + +Use this setting to change the number of posts rendered per page. If you have +rather long post excerpts, it can be a good idea to reduce the number of posts +per page: + +``` yaml +plugins: + - blog: + pagination_per_page: 5 +``` + +--- + +#### + + + + +Use this setting to change the format string that is used when generating +paginated view URLs. You can freely combine placeholders, and join them with +slashes or other characters: + +=== ":material-link: blog/page/n/" + + ``` yaml + plugins: + - blog: + pagination_url_format: "page/{page}" + ``` + +=== ":material-link: blog/n/" + + ``` yaml + plugins: + - blog: + pagination_url_format: "{page}" + ``` + +The following placeholders are available: + +- `page` – Page number + +--- + +#### + + + + +The plugin uses the [paginate] module to generate the pagination markup using a +special syntax. Use this setting to customize how pagination is constructed. +Some popular choices: + +=== "1 2 3 .. n" + + ``` yaml + plugins: + - blog: + pagination_format: "~2~" + ``` + +=== "1 2 3 .. n :material-chevron-right: :material-chevron-double-right:" + + ``` yaml + plugins: + - blog: + pagination_format: "$link_first $link_previous ~2~ $link_next $link_last" + ``` + +=== "1 :material-chevron-right:" + + ``` yaml + plugins: + - blog: + pagination_format: "$link_previous $page $link_next" + ``` + +The following placeholders are supported by [paginate]: + +- `#!css $first_page` – Number of first reachable page +- `#!css $last_page` – Number of last reachable page +- `#!css $page` – Number of currently selected page +- `#!css $page_count` – Number of reachable pages +- `#!css $items_per_page` – Maximal number of items per page +- `#!css $first_item` – Index of first item on the current page +- `#!css $last_item` – Index of last item on the current page +- `#!css $item_count` – Total number of items +- `#!css $link_first` – Link to first page (unless on first page) +- `#!css $link_last` – Link to last page (unless on last page) +- `#!css $link_previous` – Link to previous page (unless on first page) +- `#!css $link_next` – Link to next page (unless on last page) + + [paginate]: https://pypi.org/project/paginate/ + +--- + +#### + + + + +Use this setting to control whether pagination should be automatically disabled +when the view only consists of a single page. If you want to always render +pagination, use: + +``` yaml +plugins: + - blog: + pagination_if_single_page: true +``` + +--- + +#### + + + + +Use this setting to enable or disable persistence of content, i.e., if paginated +views should also display the content of their containing view. If you want to +enable this behavior, use: + +``` yaml +plugins: + - blog: + pagination_keep_content: true +``` + +### Authors + +The following settings are available for authors: + +--- + +#### + + + + +Use this setting to enable or disable post authors. If this setting is enabled, +the plugin will look for a file named [`.authors.yml`][config.authors_file] and +render authors in posts and views. Disable this behavior with: + +``` yaml +plugins: + - blog: + authors: false +``` + +--- + +#### + + + + +Use this setting to change the path of the file where the author information for +your posts resides. It's normally not necessary to change this setting, but if +you need to, use: + +``` yaml +plugins: + - blog: + authors_file: "{blog}/.authors.yml" +``` + +The following placeholders are available: + +- `blog` – [`blog` directory][config.blog_dir] + +The provided path is resolved from the [`docs` directory][mkdocs.docs_dir]. + +!!! info "Format of author information" + + The `.authors.yml` file must adhere to the following format: + + ``` yaml title=".authors.yml" + authors: + : + name: string # Author name + description: string # Author description + avatar: url # Author avatar + ``` + + Note that `` must be set to an identifier for associating authors + with posts, e.g., a GitHub username like `squidfunk`. This identifier can + then be used in the [`authors`][meta.authors] metadata property of + a post. Multiple authors are supported. As an example, see + [the `.authors.yml` file][.authors.yml] we're using for our blog. + + [.authors.yml]: https://github.com/squidfunk/mkdocs-material/blob/master/docs/blog/.authors.yml + +### Drafts + +The following settings are available for drafts: + +--- + +#### + + + + +Rendering [draft posts][meta.draft] can be useful in deploy previews. Use this +setting to specify whether the plugin should include posts marked as drafts when +[building your project]: + +=== "Render drafts" + + ``` yaml + plugins: + - blog: + draft: true + ``` + +=== "Don't render drafts" + + ``` yaml + plugins: + - blog: + draft: false + ``` + +--- + +#### + + + + +Use this setting to control whether the plugin should include posts marked as +drafts when [previewing your site]. If you don't wish to include draft posts +when previewing, use: + +``` yaml +plugins: + - blog: + draft_on_serve: false +``` + + [previewing your site]: ../creating-your-site.md#previewing-as-you-write + +--- + +#### + + + + +The plugin can automatically mark posts with future dates as drafts. When the +date is past today, the post is automatically included when +[building your project], unless explicitly marked as draft: + +``` yaml +plugins: + - blog: + draft_if_future_date: true +``` + +## Usage + +### Metadata + +Posts can define a handful of metadata properties that specify how the plugin +renders them, in which views they are integrated, and how they are linked to +each other. The metadata of each post is validated against a schema to allow for +a quicker discovery of syntax errors. + +The following properties are available: + +--- + +#### + + + + + +Use this property to associate a post with [authors] by providing a list of +identifiers as defined in the [`authors_file`][config.authors_file]. If an +author can't be resolved, the plugin will terminate with an error: + +``` yaml +--- +authors: + - squidfunk # (1)! +--- + +# Post title +... +``` + +1. Authors are linked by using their identifiers. As an example, see + [the `.authors.yml` file][.authors.yml] we're using for our blog. + + [authors]: #authors + +--- + +#### + + + + + +Use this property to associate a post with one or more [categories][category], +making the post a part of the generated category page. Categories are defined +as a list of strings (whitespaces are allowed): + +``` yaml +--- +categories: + - Search + - Performance +--- + +# Post title +... +``` + +If you want to prevent accidental typos assigning categories to posts, you +can set a predefined list of allowed categories in `mkdocs.yml` by using +the [`categories_allowed`][config.categories_allowed] setting. + +--- + +#### + + + + + +Use this property to specify a post's date. Note that this property is required, +which means the build fails when it's not set. Additional dates can be set by +using a slightly different syntax: + +=== "Date" + + ``` yaml + --- + date: 2023-01-31 + --- + + # Post title + ... + ``` + +=== "Update date" + + ``` yaml + --- + date: + created: 2023-01-31 # (1)! + updated: 2023-02-01 + --- + + # Post title + ... + ``` + + 1. Each post must have a creation date set. + +=== "Custom date" + + ``` yaml + --- + date: + created: 2023-01-31 + my_custom_date: 2023-02-01 # (1)! + --- + + # Post title + ... + ``` + + 1. The blog plugin validates all dates and allows to format them with + [babel]'s [pattern syntax] in templates. When using theme extension, + authors can add custom dates to templates. + + This was first requested in #5733. + +The following date formats are supported: + +- `2023-01-31` +- `2023-01-31T12:00:00` + +--- + +#### + + + + + +Use this property to mark a post as draft. The plugin allows to include or +exclude posts marked as drafts when [building your project] using the +[`draft`][config.draft] setting. Mark a post as draft with: + +``` yaml +--- +draft: true +--- + +# Post title +... +``` + +--- + +#### + + + + + + + +Use this property to define a list of links that are rendered in the sidebar of +a post. The property follows the same syntax as [`nav`][mkdocs.nav] in +`mkdocs.yml`, supporting sections and even anchors: + +=== "Links" + + ``` yaml + --- + links: + - setup/setting-up-site-search.md + - insiders/index.md + --- + + # Post title + ... + ``` + +=== "Links with sections" + + ``` yaml + --- + links: + - setup/setting-up-site-search.md + - Insiders: + - insiders/index.md + - insiders/getting-started.md + --- + + # Post title + ... + ``` + +=== "Links with anchors" + + ``` yaml + --- + links: + - setup/setting-up-site-search.md#built-in-search-plugin # (1)! + - Insiders: + - insiders/index.md#how-to-become-a-sponsor + - insiders/getting-started.md#requirements + --- + + # Post title + ... + ``` + + 1. If a link defines an anchor, the plugin resolves the anchor from the + linked page and sets the anchor title as a [subtitle]. + +All relative links are resolved from the [`docs` directory][mkdocs.docs_dir]. + + [subtitle]: ../reference/index.md#setting-the-page-subtitle + +--- + +#### + + + + + +Use this property to explicitly set the reading time of a post in minutes. When +[`post_readtime`][config.post_readtime] is enabled, the plugin computes the +reading time of a post, which can be overridden with: + +``` yaml +--- +readtime: 15 +--- + +# Post title +... +``` + +--- + +#### + + + + + +Use this property to explicitly set the slug of a post. By default, the slug of +a post is automatically computed by the [`post_slugify`][config.post_slugify] +function from the post's title, which can be overridden with: + +``` yaml +--- +slug: help-im-trapped-in-a-universe-factory +--- + +# Post title +... +``` + +Slugs are passed to [`post_url_format`][config.post_url_format]. + +--- + +!!! question "Missing something?" + + When setting up your blog or migrating from another blog framework, you + might discover that you're missing specific functionality – we're happy to + consider adding it to the plugin! You can [open a discussion] to + ask a question, or create a [change request] on our [issue tracker], so we + can find out if it might be a good fit for the plugin. + + [open a discussion]: https://github.com/squidfunk/mkdocs-material/discussions + [change request]: ../contributing/requesting-a-change.md + [issue tracker]: https://github.com/squidfunk/mkdocs-material/issues diff --git a/docs/plugins/group.md b/docs/plugins/group.md new file mode 100644 index 000000000..37b41e11d --- /dev/null +++ b/docs/plugins/group.md @@ -0,0 +1,121 @@ +--- +title: Built-in group plugin +icon: material/format-list-group +--- + +# Built-in group plugin + +The group plugin allows to group plugins into logical units to conditionally +enable or disable them for specific environments with the use of +[environment variables][mkdocs.env], e.g., to only enable a subset of +plugins when [building your project] during continuous integration (CI). + + [building your project]: ../creating-your-site.md#building-your-site + +## Objective + +### How it works + +The plugin conditionally and lazily loads all plugins that are part of a group +if and only if the group is enabled, which means that the plugin doesn't add any +overhead when the group is disabled. It also means that the grouped plugins +only need to be installed when the group is enabled. + +The plugins that are part of the group are executed in the same order as if +they were defined at the top-level in the list of [`plugins`][mkdocs.plugins]. +Thus, order is preserved and deterministic. + +### When to use it + +Whenever you're using multiple plugins that are only required in specific +environments, e.g., when building your project during continuous integration +(CI), the plugin is the perfect utility for making configuration simpler, as it +removes the need for splitting configuration into multiple files. + +It can be used with any built-in or third-party plugin. + +## Configuration + + + + + + +As with all [built-in plugins], getting started with the group plugin is +straightforward. Just add the following lines to `mkdocs.yml`, and start +splitting plugins into logical units: + +``` yaml +plugins: + - group +``` + +The group plugin is built into Material for MkDocs and doesn't need to be +installed. + + [group]: group.md + [built-in plugins]: index.md + +### General + +The following settings are available: + +--- + +#### + + + + +Use this setting to enable or disable the plugin when [building your project]. +The plugin behaves differently than all other built-in plugins – __it is +disabled by default__. To enable a group, use: + +``` yaml +plugins: + - group: + enabled: !ENV CI # (1)! +``` + +1. If you only want to use the group plugin for better organization and + always want to enable the plugins that are part of it, use: + + ``` yaml + plugins: + - group: + enabled: true + ``` + +The decision to disable the plugin by default was made to simplify the usage +of environment variables, as it removes the need to provide a default value for +an environment variable. + +Now, when [building your project], you can enable a group by setting the +[environment variable][mkdocs.env]: + +``` sh +CI=true mkdocs build +``` + + [building your project]: ../creating-your-site.md#building-your-site + +--- + +#### + + + + +Use this setting to list the plugins that are part of the group. The syntax is +exactly the same as for the [`plugins`][mkdocs.plugins] setting, so you can +simply copy the list of plugins that you want to group, e.g: + +``` yaml +plugins: + - group: + plugins: + - optimize + - minify +``` + +The plugins mentioned here are just used for illustration purposes. diff --git a/docs/plugins/index.md b/docs/plugins/index.md new file mode 100644 index 000000000..892441890 --- /dev/null +++ b/docs/plugins/index.md @@ -0,0 +1,246 @@ +# Built-in plugins + +Material for MkDocs started out as a theme for [MkDocs][mkdocs], but has since +evolved into a full-fledged framework for building and maintaining documentation. +The theme is still the core of the project, but it's now accompanied by a +growing number of complementary built-in plugins. + +We strive to make those plugins as modular and generic as possible, so that they +can be used in a wide variety of projects and use cases. By providing useful +default settings, we also try to make them as easy to use as possible, so that +you can get started quickly, tweaking their settings later on. When +developing built-in plugins, we always adhere to the following design principles: + +- **Modularity:** Built-in plugins are designed to be modular, so that they can + be easily combined to implement sophisticated pipelines. For example, the + [offline], [optimize] and [privacy] plugins can be used together to build + truly [offline-capable documentation]. + +- **Interoperability:** Built-in plugins are designed to be as compatible as + possible, so they can be used in combination with other plugins, including + third-party plugins. We strive to make it simple to integrate with the vast + ecosystem that has evolved around [MkDocs][mkdocs]. + +- **Performance:** Built-in plugins are designed to be as fast and + memory-efficient as possible, so that they don't unnecessarily slow down + builds. This is particularly important for large documentation projects with + thousands of pages. + + [mkdocs]: https://www.mkdocs.org/ + [design principles]: ../design-principles.md + [offline-capable documentation]: ../setup/building-for-offline-usage.md + +## Categories + +### Management + +The following plugins greatly improve the authoring experience when working on +documentation projects by providing better management capabilities, from the +management of plugins, multiple projects, and metadata, to the creation of +minimal reproductions for bug reports: + +
+ +- :material-format-list-group:   __[Built-in group plugin][group]__ + + --- + + The group plugin allows to group plugins into logical units to conditionally + enable or disable them for specific environments with the use of + [environment variables][mkdocs.env]. + + --- + + __Optimal management of plugins when building in different environments__ + +- :material-file-tree:   __[Built-in meta plugin][meta]__ + + --- + + The meta plugin makes it easy to manage metadata (front matter) for all + pages in a folder, so a certain subset of pages uses specific tags or a + custom template. + + --- + + __Simpler organization, categorization and management of metadata__ + +- :material-folder-open:   __[Built-in projects plugin][projects]__ + + --- + + The projects plugin allows to split your main project into multiple distinct + projects, build them concurrently and preview them together as one. + + --- + + __Connect multiple projects together, and build them separately or as one__ + +- :material-information:   __[Built-in info plugin][info]__ + + --- + + The info plugin is a small and useful utility that helps to create + self-contained minimal reproductions, so we maintainers can fix reported + bugs more quickly. + + --- + + __Your bug reports are of the highest quality, so we can fix them as fast as + possible__ + + +
+ + [group]: group.md + [info]: info.md + [meta]: meta.md + [projects]: meta.md + +### Optimization + +The following plugins are designed to help you build optimized documentation, +making it more accessible to your users through faster loading times, better +search engine rankings, beautiful preview images on social media, and GDPR +compliance with a few lines of configuration: + +
+ +- :material-share-circle:   __[Built-in social plugin][social]__ + + --- + + The social plugin automatically generates beautiful and customizable + social cards for each page of your documentation, showing as previews on + social media. + + --- + + __Links to your site render beautiful social cards when shared on social + media__ + +- :material-rabbit:   __[Built-in optimize plugin][optimize]__ + + --- + + The optimize plugin automatically identifies and optimizes all media files + that you reference in your project by using compression and conversion + techniques. + + --- + + __Your site loads faster as smaller images are served to your users__ + +- :material-shield-account:   __[Built-in privacy plugin][privacy]__ + + --- + + The privacy plugin downloads external assets automatically for easy + self-hosting, allowing for GDPR compliance with a single line of + configuration. + + --- + + __Your documentation can be made GDPR compliant with minimal effort__ + +- :material-connection:   __[Built-in offline plugin][offline]__ + + --- + + The offline plugin adds support for building [offline-capable documentation], + so you can distribute the [`site` directory][mkdocs.site_dir] as a `.zip` + file that can be downloaded. + + --- + + __Your documentation can work without connectivity to the internet__ + +
+ + [offline]: offline.md + [optimize]: optimize.md + [privacy]: privacy.md + [social]: social.md + +### Content + +The following plugins are designed to help you set up a blog, provide search +functionality to your users, add tags to pages and posts, and use the same +typesetting capabilities in specific parts of the documentation exactly as in +the main content: + +
+ +- :material-newspaper-variant-outline:   __[Built-in blog plugin][blog]__ + + --- + + The blog plugin adds first-class support for blogging to Material for + MkDocs, either as a sidecar to your documentation or as a standalone + installation. + + --- + + __Your blog is built with the same powerful engine as your documentation__ + +- :material-magnify:   __[Built-in search plugin][search]__ + + --- + + The search plugin adds a search bar to the header, allowing users to search + the entire documentation, so it's easier for them to find what they're + looking for. + + --- + + __Your documentation is searchable without any external services, even + offline__ + +- :material-tag-text:   __[Built-in tags plugin][tags]__ + + --- + + The tags plugin adds first-class support for categorizing pages with tags, + adding the ability to group related pages to improve the discovery of + related content. + + --- + + __Your pages are categorized with tags, yielding additional context__ + +- :material-format-title:   __[Built-in typeset plugin][typeset]__ + + --- + + The typeset plugin allows to preserve the enriched presentation of titles + and headlines within the navigation and table of contents. + + --- + + __Sidebars preserve the same formatting as section titles in pages__ + +
+ + [blog]: blog.md + [search]: search.md + [tags]: tags.md + [typeset]: typeset.md + +## Architecture + +### Multiple instances + +Several built-in plugins have support for multiple instances, which means that +they can be used multiple times in the same configuration file, allowing to +fine-tune behavior for separate sections of your project. Currently, the +following plugins have support for multiple instances: + +
+ +- [Built-in blog plugin][blog] +- [Built-in group plugin][group] +- [Built-in optimize plugin][optimize] +- [Built-in privacy plugin][privacy] +- [Built-in social plugin][social] + +
diff --git a/docs/plugins/info.md b/docs/plugins/info.md new file mode 100644 index 000000000..b422daa71 --- /dev/null +++ b/docs/plugins/info.md @@ -0,0 +1,155 @@ +--- +title: Built-in info plugin +icon: material/information +--- + +# Built-in info plugin + +The info plugin is a utility that is solely intended to create self-contained +[minimal reproductions] as `.zip` files when [reporting bugs] or proposing +[change requests], making communication between us maintainers and you much +easier, as we have a common ground to work on. + + [minimal reproductions]: ../guides/creating-a-reproduction.md + [reporting bugs]: ../contributing/reporting-a-bug.md + [change requests]: ../contributing/requesting-a-change.md + +## Objective + +### How it works + +The plugin helps you to prepare a minimal reproduction by collecting the +necessary information about the environment and configuration of your project. +This makes it easier for us to fix bugs, as it requires that you +[upgrade to the latest version] and [remove your customizations]. + +When following these principles, you can be confident that you don't report a +bug that has already been fixed in a subsequent release, or which is caused by +one of your customizations. Even more importantly, you actively help +us to fix the bug as quickly as possible. + +The output of the plugin is a `.zip` file that you can share with us maintainers. + + [Upgrade to the latest version]: ../contributing/reporting-a-bug.md#upgrade-to-latest-version + [Remove your customizations]: ../contributing/reporting-a-bug.md#remove-customizations + + +### When to use it + +Whenever you're [reporting a bug][reporting bugs] or have something to discuss, +like a question or [change request][change requests], you should attach +a small, self-contained minimal reproduction. Runnable examples help to make +communication much more efficient, giving us maintainers more time to benefit +more users by pushing the project forward. Minimal reproductions are mandatory +for bug reports. + +## Configuration + + + + +In order to get started with the built-in info plugin, just add the following +lines to `mkdocs.yml`, and quickly [create a minimal reproduction] to share +with us maintainers: + +``` yaml +plugins: + - info +``` + +The info plugin is built into Material for MkDocs and doesn't need to be +installed. + + [info]: info.md + [create a minimal reproduction]: ../guides/creating-a-reproduction.md + +### General + +The following settings are available: + +--- + +#### + + + + +Use this setting to enable or disable the plugin when [building your project]. +It's normally not necessary to specify this setting, but if you want to disable +the plugin, use: + +``` yaml +plugins: + - info: + enabled: false +``` + + [building your project]: ../creating-your-site.md#building-your-site + +--- + +#### + + + + +Use this setting to control whether the plugin should be enabled when +[previewing your site]. It's normally not necessary to specify this setting, +but if you want to change this behavior, use: + +``` yaml +plugins: + - info: + enabled_on_serve: true +``` + +This setting streamlines the process of creating and inspecting minimal +reproductions, as it allows to quickly iterate on the reproduction without +having to disable the plugin first. + + [previewing your site]: ../creating-your-site.md#previewing-as-you-write + +### Archive + +--- + +#### + + + + +Use this setting to control whether the plugin should create a `.zip` file +from the project or exit after the version check. This setting is solely +intended for debugging the plugin itself: + +``` yaml +plugins: + - info: + archive: false +``` + +--- + +#### + + + + +Use this setting to control whether the plugin should stop creating the `.zip` +file when one of the [requirements] is not satisfied. This setting must only be +used when [reporting a bug][reporting bugs] that is related to a customization +[explicitly mentioned in our documentation]. You can change it with: + +``` yaml +plugins: + - info: + archive_stop_on_violation: false +``` + +If you're using this setting when [reporting a bug][reporting bugs], please +explain why you think it is necessary to include customizations. If you're +unsure, please ask us first by [creating a discussion]. + + [requirements]: #how-it-works + [explicitly mentioned in our documentation]: ?q=%22extends+base%22 + [creating a discussion]: https://github.com/squidfunk/mkdocs-material/discussions diff --git a/docs/plugins/meta.md b/docs/plugins/meta.md new file mode 100644 index 000000000..c754e0010 --- /dev/null +++ b/docs/plugins/meta.md @@ -0,0 +1,195 @@ +--- +title: Built-in meta plugin +icon: material/file-tree +--- + +# Built-in meta plugin + +The meta plugin solves the problem of setting metadata (front matter) for all +pages in a folder, i.e., a subsection of your project, which is particularly +useful to ensure that a certain subset of pages features specific tags, uses a +custom template, or is attributed to an author. + +## Objective + +### How it works + +The plugin scans the [`docs` directory][mkdocs.docs_dir] for `.meta.yml` files, +and recursively merges the contents of those files with the metadata (front +matter) of all pages that are contained in the same folder and all subfolders. +For example, if you want to add the tag Example to +multiple pages, use: + +``` yaml title=".meta.yml" +tags: + - Example +``` + +Now, given the following directory layout, if you store the file in the folder +named `example`, all pages in that folder receive the tag, while all pages +outside of the folder remain unaffected: + +``` { .sh .no-copy hl_lines="4-8" } +. +├─ docs/ +│ ├─ ... +│ ├─ example/ +│ │ ├─ .meta.yml +│ │ ├─ a.md +│ │ ├─ ... +│ │ └─ z.md +│ └─ ... +└─ mkdocs.yml +``` + +When combining metadata, lists and dictionaries are recursively merged, which +means you can append values to a list and add or set specific properties in a +dictionary on arbitrary levels. + +### When to use it + +While the plugin itself doesn't offer much functionality beyond adding and +merging metadata, it is a perfect companion for many of the other built-in +plugins that Material for MkDocs offers. Some of the most powerful combinations +of the meta plugin and other built-in plugins are: + +
+ +- :material-share-circle:   __[Built-in social plugin][social]__ + + --- + + The meta plugin can be used to [change the layout] for social cards or + [change specific layout options] like [background] or [color] + for a subset of pages. + + ``` yaml title=".meta.yml" + social: + cards_layout: default/variant + ``` + +- :material-newspaper-variant-outline:   __[Built-in blog plugin][blog]__ + + --- + + The meta plugin allows to automatically associate blog posts with specific + [authors] and [categories], ensuring that blog posts are always correctly + annotated. + + ``` yaml title=".meta.yml" + authors: + - squidfunk + ``` + +- :material-tag-text:   __[Built-in tags plugin][tags]__ + + --- + + The meta plugin makes it possible to ensure that subsections of your + project are annotated with [specific tags], so they can't be forgotten when + adding pages. + + ``` yaml title=".meta.yml" + tags: + - Example + ``` + +- :material-magnify:   __[Built-in search plugin][search]__ + + --- + + The meta plugin makes it easy to [boost] specific sections in search results + or to [exclude] them entirely from being indexed, giving more granular + control over search. + + ``` yaml title=".meta.yml" + search: + exclude: true + ``` + +
+ + [social]: social.md + [change the layout]: social.md#meta.social.cards_layout + [change specific layout options]: social.md#meta.social.cards_layout_options + [background]: social.md#option.background_color + [color]: social.md#option.color + [blog]: blog.md + [authors]: blog.md#meta.authors + [categories]: blog.md#meta.categories + [tags]: tags.md + [specific tags]: tags.md#meta.tags + [search]: search.md + [exclude]: search.md#meta.search.exclude + [boost]: search.md#meta.search.boost + +## Configuration + + + + + + +As with all [built-in plugins], getting started with the meta plugin is +straightforward. Just add the following lines to `mkdocs.yml`, and start +applying metadata for multiple pages at once: + +``` yaml +plugins: + - meta +``` + +The meta plugin is included with Material for MkDocs and doesn't need to be +installed. + + [meta]: meta.md + [built-in plugins]: index.md + +### General + +The following settings are available: + +--- + +#### + + + + + +Use this setting to enable or disable the plugin when [building your project]. +It's normally not necessary to specify this setting, but if you want to disable +the plugin, use: + +``` yaml +plugins: + - meta: + enabled: false +``` + + [building your project]: ../creating-your-site.md#building-your-site + +### Meta file + +The following settings are available for meta files: + +--- + +#### + + + + + +Use this setting to change the file the plugin will look for when scanning +the [`docs` directory][mkdocs.docs_dir]. It's normally not necessary to change +this setting, but if you want to change it, use: + +``` yaml +plugins: + - meta: + meta_file: .meta.yml +``` + +The provided path is resolved from the [`docs` directory][mkdocs.docs_dir] +recursively. diff --git a/docs/plugins/offline.md b/docs/plugins/offline.md new file mode 100644 index 000000000..6e6b72452 --- /dev/null +++ b/docs/plugins/offline.md @@ -0,0 +1,153 @@ +--- +title: Built-in offline plugin +icon: material/connection +--- + + +# Built-in offline plugin + +[MkDocs][mkdocs] is one of the few frameworks that allow to build offline-capable +documentation that can be directly viewed by the user – no server needed. With +the offline plugin, you can distribute the [`site` directory][mkdocs.site_dir] +as a downloadable `.zip` file while retaining most interactive functionality. + +## Objective + +### How it works + +After [building your project], switch to the [`site` directory][mkdocs.site_dir] +and open `index.html` in your browser – you're now viewing your documentation +from your local file system! Most browsers will denote this by showing `file://` +in the address bar. However, you'll realize that the site search is gone. + +Material for MkDocs offers many interactive features, some of which will not +work from the local file system due to the restrictions of modern browsers. More +specifically and technically, all calls to the [Fetch API] will error with a +message like: + +``` +Cross origin requests are only supported for protocol schemes: http, [...] +``` + +While browsers impose those restriction for security reasons, it reduces the +interactivity of your project. The offline plugin makes sure that site search +keeps working by moving the search index to a JavaScript file, and leveraging +@squidfunk's [iframe-worker] shim. + +Additionally, the plugin automatically disables the +[`use_directory_urls`][mkdocs.use_directory_urls] setting, ensuring that users +can open your documentation directly from the local file system. + +There are some [limitations]. + + [building your project]: ../creating-your-site.md#building-your-site + [Fetch API]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API + [iframe-worker]: https://github.com/squidfunk/iframe-worker + [limitations]: #limitations + +### When to use it + +As the name already indicates, the plugin should only be used when you're +[building your project] for offline distribution. It's also good to know, that +the offline plugin plays nicely with the following other plugins, helping to +create even better offline-capable documentation: + +
+ +- :material-shield-account:   __[Built-in privacy plugin][privacy]__ + + --- + + The privacy plugin makes it easy to use external assets when building for + offline usage, as it automatically downloads them for distribution with + your documentation. + + --- + + __Your documentation can work without connectivity to the internet[^1]__ + +- :material-rabbit:   __[Built-in optimize plugin][optimize]__ + + --- + + The optimize plugin automatically identifies and optimizes all media files + that you reference in your project by using compression and conversion + techniques. + + --- + + __Your documentation can be distributed as a smaller `.zip` download__ + +
+ + [^1]: + You might wonder why the [privacy plugin][privacy] is necessary to build + truly offline-capable documentation with the offline plugin. While it's + certainly possible to also add support for downloading external assets to + the offline plugin, this functionality is already fully implemented in the + privacy plugin and is its very raison d'être. + + Material for MkDocs follows a modular approach for its plugin system – many + of the plugins work perfectly together and enhance each others + functionalities, allowing to solve complex problems with a few lines + of configuration. + + [privacy]: privacy.md + [optimize]: optimize.md + +## Configuration + + + + +As with all [built-in plugins], getting started with the offline plugin is +straightforward. Just add the following lines to `mkdocs.yml`, and start +building offline-capable documentation: + +``` yaml +plugins: + - offline +``` + +The offline plugin is built into Material for MkDocs and doesn't need to be +installed. + + [offline]: offline.md + [built-in plugins]: index.md + +### General + +The following settings are available: + +--- + +#### + + + + +Use this setting to enable or disable the plugin when [building your project]. +If you want to build online- as well as offline-capable documentation, it's a +good idea to use an [environment variable][mkdocs.env]: + +``` yaml +plugins: + - offline: + enabled: !ENV [OFFLINE, false] +``` + +## Limitations + +When enabling the offline plugin, make sure to disable the following settings, +as they make use of the [Fetch API] which will error when invoked from the local +file system: + +- [Instant loading] +- [Site analytics] +- [Versioning] +- [Comment systems] + + [Instant loading]: ../setup/setting-up-navigation.md#instant-loading + [Site analytics]: ../setup/setting-up-site-analytics.md + [Versioning]: ../setup/setting-up-versioning.md + [Comment systems]: ../setup/adding-a-comment-system.md diff --git a/docs/plugins/optimize.md b/docs/plugins/optimize.md new file mode 100644 index 000000000..a30f7fb39 --- /dev/null +++ b/docs/plugins/optimize.md @@ -0,0 +1,443 @@ +--- +title: Built-in optimize plugin +icon: material/rabbit +--- + +# Built-in optimize plugin + +The optimize plugin automatically identifies and optimizes all media files when +[building your project] by using common compression and conversion techniques. +As a result, your site loads significantly faster and yields better rankings in +search engines. + + [building your project]: ../creating-your-site.md#building-your-site + +## Objective + +### How it works + +The plugin scans the [`docs` directory][mkdocs.docs_dir] for media files and +assets, optimizing them automatically in order to reduce the final size of the +[`site` directory][mkdocs.site_dir]. This leads to faster loading times as you +ship less bytes to your users, as well as a smaller download for +[offline-capable documentation]. + +Optimized images are [intelligently cached][intelligent caching], which is why +the plugin will only optimize media files that changed since the last build. +This makes it possible to swap out or update images, without having to worry +about optimizing them, or even worse, forgetting to do so. + +In order to optimize media files, a few [dependencies] need to be available on +your system. + + [offline-capable documentation]: ../setup/building-for-offline-usage.md + [dependencies]: #configuration + +### When to use it + +It's generally recommended to use the plugin, as media files are optimized +automatically without the need for intervention, ensuring that your site loads +as fast as possible. Optimized media files are one of the key components for a +high and consistent ranking in search engines. + +Additionally, the plugin can be combined with other built-in plugins +that Material for MkDocs offers, in order to create sophisticated +build pipelines tailored to your project: + +
+ +- :material-shield-account:   __[Built-in privacy plugin][privacy]__ + + --- + + The privacy plugin makes it easy to use unoptimized external assets, passing + them to the optimize plugin before copying them to the [`site` directory] + [mkdocs.site_dir]. + + --- + + __External media files can be automatically downloaded and optimized__ + +- :material-connection:   __[Built-in offline plugin][offline]__ + + --- + + The offline plugin adds support for building offline-capable documentation, + so you can distribute the [`site` directory][mkdocs.site_dir] as a `.zip` + file that can be downloaded. + + --- + + __Your documentation can be distributed as a smaller `.zip` download__ + +
+ + [privacy]: privacy.md + [offline]: offline.md + +## Configuration + + + + + + + +As with all [built-in plugins], getting started with the optimize plugin is +straightforward. Just add the following lines to `mkdocs.yml`, and observe how +media files are optimized automatically: + +``` yaml +plugins: + - optimize +``` + +The optimize plugin is built into Material for MkDocs and doesn't need to be +installed. + +However, in order to optimize all media files, it's necessary to install the +dependencies for [image processing], if they're not already available on your +system. The linked guide includes instructions for several operating systems +and mentions some alternative environments. + + [optimize]: optimize.md + [built-in plugins]: index.md + [image processing]: requirements/image-processing.md + +### General + +The following settings are available: + +--- + +#### + + + + + +Use this setting to enable or disable the plugin when [building your project]. +If you want to disable the plugin, e.g., for local builds, you can use an +[environment variable][mkdocs.env] in `mkdocs.yml`: + +``` yaml +plugins: + - optimize: + enabled: !ENV [CI, false] +``` + +This configuration enables the plugin only during continuous integration (CI). + +--- + +#### + + + + + +With more CPUs available, the plugin can do more work in parallel, and thus +complete media file optimization faster. If you want to disable concurrent +processing completely, use: + +``` yaml +plugins: + - optimize: + concurrency: 1 +``` + +By default, the plugin uses all available CPUs - 1 with a minimum of 1. + +### Caching + +The plugin implements an [intelligent caching] mechanism, ensuring that a media +file or asset is only passed through the optimization pipeline when its contents +change. If you swap out or update an image, the plugin detects it and updates +the optimized version of the media file. + +The following settings are available for caching: + + [intelligent caching]: requirements/caching.md + +--- + +#### + + + + + +Use this setting to instruct the plugin to bypass the cache, in order to +re-optimize all media files, even though the cache may not be stale. It's +normally not necessary to specify this setting, except for when debugging +the plugin itself. Caching can be disabled with: + +``` yaml +plugins: + - optimize: + cache: false +``` + +--- + +#### + + + + + +It is normally not necessary to specify this setting, except for when you want +to change the path within your root directory where media files are cached. +If you want to change it, use: + +``` yaml +plugins: + - optimize: + cache_dir: my/custom/dir +``` + +If you're using [multiple instances] of the plugin, it can be a good idea to +set different cache directories for both instances, so that they don't interfere +with each other. + + [multiple instances]: index.md#multiple-instances + +### Optimization + +Documentation often makes use of screenshots or diagrams for better +visualization of things, both of which are prime candidates for optimization. +The plugin automatically optimizes images using [pngquant] for `.png` files, +and [Pillow] for `.jpg` files. + +The following settings are available for optimization: + + [pngquant]: https://pngquant.org/ + [Pillow]: https://pillow.readthedocs.io/ + +--- + +#### + + + + + +Use this setting to enable or disable media file optimization. Currently, +the plugin's sole purpose is to optimize media files, so it's equivalent to the +[`enabled`][config.enabled] setting, but in the near future, other features +might be added. If you want to disable optimization, use: + +``` yaml +plugins: + - optimize: + optimize: false +``` + +--- + +#### + + + + + +Use this setting to enable or disable the optimization of `.png` files. It's +normally not necessary to specify this setting, but if you want to disable +the optimization of `.png` files, use: + +``` yaml +plugins: + - optimize: + optimize_png: false +``` + +--- + +#### + + + + + +Use this setting to specify the speed/quality tradeoff that [pngquant] applies +when optimizing `.png` files. The lower the number, the more aggressively +[pngquant] will try to optimize: + +=== "Slower smaller" + + ``` yaml + plugins: + - optimize: + optimize_png_speed: 1 + ``` + +=== "Faster larger" + + ``` yaml + plugins: + - optimize: + optimize_png_speed: 10 + ``` + +A factor of `10` has 5% lower quality, but is 8x faster than the default `3`. + +--- + +#### + + + + + +Use this setting to specify whether [pngquant] should strip optional metadata +from `.png` files that are not required to display the image, e.g., [EXIF]. +If you want to preserve metadata, use: + +``` yaml +plugins: + - optimize: + optimize_png_strip: false +``` + + [EXIF]: https://en.wikipedia.org/wiki/Exif + +--- + +#### + + + + + +Use this setting to enable or disable the optimization of `.jpg` files. It's +normally not necessary to specify this setting, but if you want to disable +the optimization of `.jpg` files, use: + +``` yaml +plugins: + - optimize: + optimize_jpg: false +``` + +--- + +#### + + + + + +Use this setting to specify the image quality that [Pillow] applies when +optimizing `.jpg` files. If the images look blurry, it's a good idea to +fine-tune and change this setting: + +``` yaml +plugins: + - optimize: + optimize_jpg_quality: 75 +``` + +--- + +#### + + + + + +Use this setting to specify whether [Pillow] should use progressive encoding +when optimizing `.jpg` files, rendering faster on slow connections. If you want +to disable progressive encoding, use: + +``` yaml +plugins: + - optimize: + optimize_jpg_progressive: false +``` + + [progressive encoding]: https://medium.com/hd-pro/jpeg-formats-progressive-vs-baseline-73b3938c2339 + +--- + +#### + + + + + +Use this setting to enable media file optimization for specific directories +of your project, e.g., when using [multiple instances] of the plugin to optimize +media files differently: + +``` yaml +plugins: + - optimize: + optimize_include: + - screenshots/* +``` + +This configuration enables optimization for all media files that are contained +in the `screenshots` folder and its subfolders inside the [`docs` directory] +[mkdocs.docs_dir]. + +--- + +#### + + + + + +Use this setting to disable media file optimization for specific directories +of your project, e.g., when using [multiple instances] of the plugin to optimize +media files differently: + +``` yaml +plugins: + - social: + optimize_exclude: + - vendor/* +``` + +This configuration disables optimization for all media files that are contained +in the `vendor` folder and its subfolders inside the [`docs` directory] +[mkdocs.docs_dir]. + +### Reporting + +The following settings are available for reporting: + +--- + +#### + + + + + +Use this setting to control whether the plugin should print the number of bytes +gained after optimizing each file. If you want to disable this behavior, use: + +``` yaml +plugins: + - optimize: + print_gain: false +``` + +--- + +#### + + + + + +Use this setting to control whether the plugin should print the total number of +bytes gained after optimizing all files. If you want to disable this behavior, +use: + +``` yaml +plugins: + - optimize: + print_gain_summary: false +``` diff --git a/docs/plugins/privacy.md b/docs/plugins/privacy.md new file mode 100644 index 000000000..d4141ac25 --- /dev/null +++ b/docs/plugins/privacy.md @@ -0,0 +1,416 @@ +--- +title: Built-in privacy plugin +icon: material/shield-account +--- + + +# Built-in privacy plugin + +The privacy plugin offers a streamlined solution for automatically self-hosting +external assets. With just a single line of configuration, the plugin can +automatically identify and download external assets, making GDPR compliance +as effortless as it can possibly be. + +## Objective + +### How it works + +The plugin scans the generated HTML for external assets, i.e., scripts, style +sheets, images, and web fonts, downloads them, stores them in the +[`site` directory][mkdocs.site_dir] and replaces all references with links to +the downloaded copies for effortless self-hosting. For example: + +``` html + +``` + +This external script is downloaded, and the link is replaced with: + +``` html + +``` + +Of course, scripts and style sheets can reference further external assets, +which is why this process is repeated recursively until no further external +assets are detected: + +- Scripts are scanned for further scripts, style sheets and JSON files +- Style sheets are scanned for images and web fonts + +Additionally, hints like [`preconnect`][preconnect], used to reduce latency when +requesting external assets, are removed from the output, as they're not +necessary when self-hosting. After the plugin has done it's work, your project +will be free of requests to external services. + +There are some [limitations]. + + [preconnect]: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preconnect + [limitations]: #limitations + +### When to use it + +The plugin was developed to make compliance with the 2018 European +__General Data Protection Regulation__ (GDPR) as simple as possible, while +retaining the flexibility and power that Material for MkDocs offers, like for +example its tight integration with [Google Fonts]. + +But, that's only the start. For example, if your project includes a lot of +images, enabling the plugin allows to move them outside of your repository, as +the plugin will automatically download and store them in the [`site` directory] +[mkdocs.site_dir] when [building your project]. + +Even more interestingly, the plugin can be combined with other built-in plugins +that Material for MkDocs offers, in order to create sophisticated build +pipelines tailored to your project: + +
+ +- :material-rabbit:   __[Built-in optimize plugin][optimize]__ + + --- + + The optimize plugin allows to optimize all downloaded external assets + detected by the privacy plugin by using compression and conversion + techniques. + + --- + + __External media files are automatically downloaded and optimized__ + +- :material-connection:   __[Built-in offline plugin][offline]__ + + --- + + The offline plugin adds support for building [offline-capable documentation], + so you can distribute the [`site` directory][mkdocs.site_dir] as a `.zip` + file that can be downloaded. + + --- + + __Your documentation can work without connectivity to the internet__ + +
+ + [Google Fonts]: ../setup/changing-the-fonts.md + [building your project]: ../creating-your-site.md#building-your-site + [optimize]: optimize.md + [offline]: offline.md + [offline-capable documentation]: ../setup/building-for-offline-usage.md + +## Configuration + + + + + + + +As with all [built-in plugins], getting started with the privacy plugin is +straightforward. Just add the following lines to `mkdocs.yml`, and start +effortlessly self-hosting external assets: + +``` yaml +plugins: + - privacy +``` + +The privacy plugin is built into Material for MkDocs and doesn't need to be +installed. + + [privacy]: privacy.md + [built-in plugins]: index.md + +### General + +The following settings are available: + +--- + +#### + + + + + +Use this setting to enable or disable the plugin when [building your project]. +If you want to disable the plugin, e.g., for local builds, you can use an +[environment variable][mkdocs.env] in `mkdocs.yml`: + +``` yaml +plugins: + - privacy: + enabled: !ENV [CI, false] +``` + +This configuration enables the plugin only during continuous integration (CI). + +--- + +#### + + + + + +With more CPUs available, the plugin can do more work in parallel, and thus +complete handling of external assets faster. If you want to disable concurrent +processing completely, use: + +``` yaml +plugins: + - privacy: + concurrency: 1 +``` + +By default, the plugin uses all available CPUs - 1 with a minimum of 1. + +### Caching + +The plugin implements an [intelligent caching] mechanism, ensuring that external +assets are only downloaded when they're not already contained in the cache. +While the initial build might take some time, it's a good idea to use caching, +as it will speed up consecutive builds. + +The following settings are available for caching: + + [intelligent caching]: requirements/caching.md + +--- + +#### + + + + + +Use this setting to instruct the plugin to bypass the cache, in order to +re-schedule downloads for all external assets, even though the cache may not be +stale. It's normally not necessary to specify this setting, except for when +debugging the plugin itself. Caching can be disabled with: + +``` yaml +plugins: + - privacy: + cache: false +``` + +--- + +#### + + + + + +It is normally not necessary to specify this setting, except for when you want +to change the path within your root directory where downloaded copies are +cached. If you want to change it, use: + +``` yaml +plugins: + - privacy: + cache_dir: my/custom/dir +``` + +If you're using [multiple instances] of the plugin, it can be a good idea to +set different cache directories for both instances, so that they don't interfere +with each other. + + [multiple instances]: index.md#multiple-instances + +### External assets + +The following settings are available for external assets: + +--- + +#### + + + + + +Use this setting to control whether the plugin should download external +assets. If you only want the plugin to process [external links], you can disable +handling of external assets with: + +``` yaml +plugins: + - privacy: + assets: false +``` + + [external links]: #external-links + +--- + +#### + + + + + +Use this setting to control whether the plugin should downloads or only report +external assets when they're encountered. If you already self-host all external +assets, this setting can be used as a safety net to detect links to external +assets placed by the author in pages: + +``` yaml +plugins: + - privacy: + assets_fetch: true +``` + +--- + +#### + + + + + +It is normally not necessary to specify this setting, except for when you want +to change the path within the [`site` directory][mkdocs.site_dir] where +external assets are stored. If you want to change it, use: + +``` yaml +plugins: + - privacy: + assets_fetch_dir: my/custom/dir +``` + +This configuration stores the downloaded copies at `my/custom/dir` in the +[`site` directory][mkdocs.site_dir]. + +--- + +#### + + + + + +Use this setting to enable downloading of external assets for specific origins, +e.g., when using [multiple instances] of the plugin to fine-tune processing of +external assets for different origins: + +``` yaml +plugins: + - privacy: + assets_include: + - unsplash.com/* +``` + +--- + +#### + + + + + +Use this setting to disable downloading of external assets for specific origins, +e.g., when using [multiple instances] of the plugin to fine-tune processing of +external assets for different origins: + +``` yaml +plugins: + - privacy: + assets_exclude: # (1)! + - cdn.jsdelivr.net/npm/mathjax@3/* + - giscus.app/* +``` + +1. [MathJax] loads web fonts for typesetting of mathematical content + through relative URLs, and thus cannot be automatically bundled by the + privacy plugin. [MathJax can be self-hosted]. + + [Giscus], which we recommend to use as a [comment system], uses a technique + called code-splitting to load only the code that is necessary, which + is implemented via relative URLs. [Giscus can be self-hosted] as well. + + [MathJax]: ../reference/math.md + [MathJax can be self-hosted]: https://docs.mathjax.org/en/latest/web/hosting.html + [Giscus]: https://giscus.app/ + [comment system]: ../setup/adding-a-comment-system.md + [Giscus can be self-hosted]: https://github.com/giscus/giscus/blob/main/SELF-HOSTING.md + +--- + +### External links + +The following settings are available for external links: + +--- + +#### + + + + + +Use this setting to instruct the plugin to parse and process external links to +annotate them for [improved security], or to automatically add additional +attributes to external links. If you want to disable processing of external +links, use: + +``` yaml +plugins: + - privacy: + links: false +``` + + [improved security]: https://developer.chrome.com/en/docs/lighthouse/best-practices/external-anchors-use-rel-noopener/ + +--- + +#### + + + + + +Use this setting to specify additional attributes that should be added to +external links, for example, to add `target="_blank"` to all external links +so they open in a new tab: + +``` yaml +plugins: + - privacy: + links_attr_map: + target: _blank +``` + +--- + +#### + + + + + +It is normally not recommended to change this setting, as it will automatically +annotate external links that open in a new window with `rel="noopener"` for +[improved security]: + +``` yaml +plugins: + - privacy: + links_noopener: true +``` + +## Limitations + +Dynamically created URLs as part of scripts are not detected, and thus cannot be +downloaded automatically, as the plugin does not execute scripts – it only detects fully qualified URLs for downloading and replacement. In short, don't do this: + +``` js +const cdn = "https://polyfill.io" +const url = `${cdn}/v3/polyfill.min.js` +``` + +Instead, always use fully qualified URLs: + +``` js +const url ="https://polyfill.io/v3/polyfill.min.js" +``` diff --git a/docs/plugins/projects.md b/docs/plugins/projects.md new file mode 100644 index 000000000..b308762f1 --- /dev/null +++ b/docs/plugins/projects.md @@ -0,0 +1,264 @@ +--- +title: Built-in projects plugin +icon: material/folder-open +--- + +# Built-in projects plugin + +The projects plugin adds the ability to split your main project into multiple +distinct projects, build them concurrently and preview them together as one. +This is particularly useful when creating a multi-language project, but can also +be used to split very large projects into smaller parts. + +## Objective + +### How it works + +The plugin scans the configured [`projects` directory][config.projects_dir] for +`mkdocs.yml` files, identifies all nested projects and builds them concurrently. +If not configured otherwise, the plugin expects that your project has +the following directory layout, e.g. for a multi-language project: + +``` { .sh .no-copy } +. +├─ docs/ +├─ projects/ +│ ├─ en/ +│ │ ├─ docs/ +│ │ └─ mkdocs.yml +│ └─ de/ +│ ├─ docs/ +│ └─ mkdocs.yml +└─ mkdocs.yml +``` + +One of the most useful and interesting features of the plugin is that it allows +[previewing your site] from the main project, while still being able to preview +and build each project individually. This is especially useful for +multi-language projects. + +If, when [previewing your site], you change a file in one of the projects, the +plugin only rebuilds this project and makes sure that MkDocs will also reload +the associated files. This also creates the opportunity for splitting your +main project into several projects for a better editing experience. + +There are some [limitations], but we're working hard to remove them. + + [previewing your site]: ../creating-your-site.md#previewing-as-you-write + [limitations]: #limitations + +### When to use it + +The plugin came into existence because we needed a convenient and scalable +method to build our [examples] repository, which features many self-contained +and runnable projects that users can download and use as a basis when +boostrapping a new project or [creating a reproduction]. + +When you want to create a multi-language project, or have a very large existing +project, you might consider using the plugin, as it makes managing, editing +and building more comfortable. + + [examples]: https://github.com/mkdocs-material/examples + [creating a reproduction]: ../guides/creating-a-reproduction.md + +## Configuration + + + + + + +In order to get started with the projects plugin, just add the following lines +to `mkdocs.yml`, and split your main project into several distinct projects that +can be built concurrently: + +``` yaml +plugins: + - projects +``` + +The projects plugin is built into Material for MkDocs and doesn't need to be +installed. + + [projects]: projects.md + +### General + +The following settings are available: + +--- + +#### + + + + + +Use this setting to enable or disable the plugin when [building your project]. +If you want to disable the plugin, e.g., for local builds, you can use an +[environment variable][mkdocs.env] in `mkdocs.yml`: + +``` yaml +plugins: + - projects: + enabled: !ENV [CI, false] +``` + +This configuration enables the plugin only during continuous integration (CI). + + [building your project]: ../creating-your-site.md#building-your-site + +--- + +#### + + + + + +With more CPUs available, the plugin can do more work in parallel, and thus +build projects faster. If you want to disable concurrent processing completely, +use: + +``` yaml +plugins: + - projects: + concurrency: 1 +``` + +By default, the plugin uses all available CPUs - 1 with a minimum of 1. + +### Caching + +The plugin implements an [intelligent caching] mechanism, ensuring that a +project is only rebuilt when its contents change. While the initial build might +take some time, it's a good idea to use caching, as it will speed up consecutive +builds. + +The following settings are available for caching: + + [intelligent caching]: requirements/caching.md + +--- + +#### + + + + + +Use this setting to instruct the plugin to bypass the cache, in order to +rebuild all projects, even though the cache may not be stale. It's normally not +necessary to specify this setting, except for when debugging the plugin itself. +Caching can be disabled with: + +``` yaml +plugins: + - projects: + cache: false +``` + +--- + +#### + + + + + +It is normally not necessary to specify this setting, except for when you want +to change the path within your root directory where the metadata is cached. +If you want to change it, use: + +``` yaml +plugins: + - projects: + cache_dir: my/custom/dir +``` + +### Projects + +The following settings are available for projects: + +--- + +#### + + + + + +Use this setting to enable or disable building of projects. Currently, the +plugin's sole purpose is to build projects, so it's equivalent to the +[`enabled`][config.enabled] setting, but in the future, other features might be +added. If you want to disable building of projects, use: + +``` yaml +plugins: + - projects: + projects: false +``` + +--- + +#### + + + + + +Use this setting to change the folder where your projects are located. It's +normally not necessary to change this setting, but if you want to rename the +folder or change its file system location, use: + +``` yaml +plugins: + - projects: + projects_dir: projects +``` + +Note that the [`projects` directory][config.projects_dir] is solely used for +project organization – it is not included in project URLs, since projects are +automatically hoisted by the plugin. + +The provided path is resolved from the root directory. + +### Hoisting + +The following settings are available for hoisting: + +--- + +#### + + + + + +Use this setting to enable or disable hoisting of themes files to the main +project. If you disable this setting, each project receives a copy of the +theme's files, which can be considered redundant: + +``` yaml +plugins: + - projects: + hoisting: false +``` + +It's generally advisable to enable hoisting, as it yields faster deployments +and faster loading of your project's sites, because the files are the same for +all projects and can be deduplicated. + +### Limitations + +The plugin is one of the latest additions to Material for MkDocs, which means it +is rather young and has some limitations. We're working hard to remove them, and +we're happy to receive feedback and learn about your requirements in ?5800. +Current limitations are: + +- __Basic multi-language support only__: we'll be investigating how to provide + better support for multi-language projects, allowing to easier interlink + projects and switch between them. + +- __Separate search indexes and sitemaps__: currently, the projects are entirely + separate, which means they will have separate search indexes and sitemaps. diff --git a/docs/plugins/requirements/caching.md b/docs/plugins/requirements/caching.md new file mode 100644 index 000000000..63b3f4a9e --- /dev/null +++ b/docs/plugins/requirements/caching.md @@ -0,0 +1,35 @@ +--- +icon: material/database-outline +--- + +# Caching + +Some of the [built-in plugins] implement intelligent caching mechanisms, which +massively speed up consecutive builds by reducing the amount of work that needs +to be done. This guide explains how to configure caching in different +environments. + +## Prerequisites + +Caching is entirely optional but enabled by default. It can be disabled per +plugin. If not configured otherwise, plugins will cache their data in the +`.cache` folder in the root of your project. For this reason it's recommended +to create a `.gitignore` file in the root of your project: + +``` title=".gitignore" +.cache +``` + +This ensures that cached files are not added to your git repository – something +that is generally not recommended to do unless absolutely necessary. In some +cases, you might need to check in cached files, e.g. when you need to +pre-generate [social cards] locally, e.g., when you're not be able to install +the image processing dependencies in your continuous integration (CI) +environment. + +In this case, we recommend changing the `cache_dir` setting – something that all +plugins that implement caching share – to a folder which you add to your git +repository. + + [built-in plugins]: ../index.md + [social cards]: ../../setup/setting-up-social-cards.md diff --git a/docs/setup/dependencies/image-processing.md b/docs/plugins/requirements/image-processing.md similarity index 73% rename from docs/setup/dependencies/image-processing.md rename to docs/plugins/requirements/image-processing.md index ae053e05f..38b3dc03d 100644 --- a/docs/setup/dependencies/image-processing.md +++ b/docs/plugins/requirements/image-processing.md @@ -1,21 +1,38 @@ +--- +icon: material/image-sync-outline +--- + # Image processing -Material for MkDocs depends on several libraries to allow for image processing -as part of the build pipeline, including [social cards] and [image optimization]. -For this reason, a few external libraries must be installed on the host system. -This section explains how to install them. +Some of the [built-in plugins] depend on external libraries for efficient image +processing, most notably the [social] plugin to generate [social cards], and the +[optimize] plugin for applying [image optimization]. This guide explains how to +install those libraries in different environments. - [social cards]: ../setting-up-social-cards.md - [image optimization]: ../building-an-optimized-site.md + [built-in plugins]: ../index.md + [social]: ../social.md + [social cards]: ../../setup/setting-up-social-cards.md + [optimize]: ../optimize.md + [image optimization]: ../../setup/building-an-optimized-site.md ## Dependencies -Install the Python dependencies for image processing with: +The libraries for image processing are entirely optional, and only need to be +installed if you want to use the [social] plugin or the [optimize] plugin. The +libraries are listed under the `imaging` extra: ``` -pip install pillow cairosvg +pip install "mkdocs-material[imaging]" ``` +This will install compatible versions of the following packages: + +- [Pillow] +- [CairoSVG] + + [Pillow]: https://pillow.readthedocs.io/ + [CairoSVG]: https://cairosvg.org/ + ### Cairo Graphics [Cairo Graphics] is a graphics library and dependency of [Pillow], which @@ -36,9 +53,8 @@ Material for MkDocs makes use of for generating [social cards] and performing === ":fontawesome-brands-windows: Windows" As stated in the [installation guide], the easiest way to get up and running - with the [Cairo Graphics] library on Windows is by installing [GTK+], since - it has Cairo as a dependency. You can also download and install a - precompiled [GTK runtime]. + with the [Cairo Graphics] library on Windows is by installing [GTK+]. You + can also download a precompiled [GTK runtime]. === ":material-linux: Linux" @@ -70,8 +86,6 @@ The following environments come with a preinstalled version of [Cairo Graphics]: - [x] No installation needed in [GitHub Actions] (Ubuntu) [Cairo Graphics]: https://www.cairographics.org/ - [Pillow]: https://pillow.readthedocs.io/ - [CairoSVG]: https://cairosvg.org/ [Homebrew]: https://brew.sh/ [installation guide]: https://www.cairographics.org/download/ [GTK+]: https://www.gtk.org/docs/installations/windows/ @@ -82,7 +96,7 @@ The following environments come with a preinstalled version of [Cairo Graphics]: ### pngquant [pngquant] is an excellent library for lossy PNG compression, and a direct -dependency of the [built-in optimize plugin]. See the following section which +dependency of the [built-in optimize plugin]. See the following section which explains how to install [pngquant] system: === ":material-apple: macOS" @@ -97,8 +111,8 @@ explains how to install [pngquant] system: === ":fontawesome-brands-windows: Windows" - Installing [pngquant] on Windows is a little more involved. The - [pngquant-winbuild] repository contains a guide on how to set up an + Installing [pngquant] on Windows is a little more involved. The + [pngquant-winbuild] repository contains a guide on how to set up an environment for building [pngquant] on Windows. === ":material-linux: Linux" @@ -113,6 +127,10 @@ explains how to install [pngquant] system: The same is true for `yum` and `zypper`. +The following environments come with a preinstalled version of [pngquant]: + +- [x] No installation needed in [Docker image] + [pngquant]: https://pngquant.org/ - [built-in optimize plugin]: ../building-an-optimized-site.md#built-in-optimize-plugin + [built-in optimize plugin]: ../../setup/building-an-optimized-site.md#built-in-optimize-plugin [pngquant-winbuild]: https://github.com/jibsen/pngquant-winbuild diff --git a/docs/plugins/search.md b/docs/plugins/search.md new file mode 100644 index 000000000..517b2b128 --- /dev/null +++ b/docs/plugins/search.md @@ -0,0 +1,427 @@ +--- +title: Built-in search plugin +icon: material/magnify +--- + +# Built-in search plugin + +The search plugin adds a search bar to the header, allowing users to search your +documentation. It's powered by [lunr.js], a lightweight full-text search engine +for the browser, elimininating the need for external services, and even works +when building [offline-capable documentation]. + + [lunr.js]: https://lunrjs.com/ + [offline-capable documentation]: ../setup/building-for-offline-usage.md + +## Objective + +### How it works + +The plugin scans the generated HTML and builds a search index from all pages and +sections by extracting the section titles and contents. It preserves some inline +formatting like code blocks and lists, but removes all other formatting, so the +search index is as small as possible. + +When a user visits your site, the search index is shipped to the browser, +indexed with [lunr.js] and made available for fast and simple querying – no +server needed. This ensures that the search index is always up to date with +your documentation, yielding accurate results. + +### When to use it + +It's generally recommended to use the plugin, as interactive search functionality +is a vital part of every good documentation. Additionally, the plugin integrates +perfectly with several of the other [built-in plugins] that Material for MkDocs +offers: + +
+ +- :material-connection:   __[Built-in offline plugin][offline]__ + + --- + + The offline plugin adds support for building offline-capable documentation, + so you can distribute the [`site` directory][mkdocs.site_dir] as a `.zip` + file that can be downloaded. + + --- + + __Your documentation can work without connectivity to the internet__ + +- :material-file-tree:   __[Built-in meta plugin][meta]__ + + --- + + The meta plugin makes it easy to [boost][meta.search.boost] specific + sections in search results or to [exclude][meta.search.exclude] them + entirely from being indexed, giving more granular control over search. + + --- + + __Simpler organization and management of search in different subsections__ + +
+ + [offline]: offline.md + [meta]: meta.md + [built-in plugins]: index.md + +## Configuration + + + + +As with all [built-in plugins], getting started with the search plugin is +straightforward. Just add the following lines to `mkdocs.yml`, and your users +will be able to search your documentation: + +``` yaml +plugins: + - search +``` + +The search plugin is built into Material for MkDocs and doesn't need to be +installed. + + [search]: search.md + [built-in plugins]: index.md + +### General + +The following settings are available: + +--- + +#### + + + + +Use this setting to enable or disable the plugin when [building your project]. +It's normally not necessary to specify this setting, but if you want to disable +the plugin, use: + +``` yaml +plugins: + - search: + enabled: false +``` + + [building your project]: ../creating-your-site.md#building-your-site + +### Search + +The following settings are available for search: + +--- + +#### + + + + +Use this setting to specify the language of the search index, enabling [stemming] +support for other languages than English. The default value is automatically +computed from the [site language], but can be explicitly set to another language +or even multiple languages with: + +=== "Set language" + + ``` yaml + plugins: + - search: + lang: en + ``` + +=== "Add further languages" + + ``` yaml + plugins: + - search: + lang: # (1)! + - en + - de + ``` + + 1. Be aware that including support for further languages increases the + base JavaScript payload by around 20kb and by another 15-30kb per + language, all before `gzip`. + + [stemming]: https://en.wikipedia.org/wiki/Stemming + [site language]: ../setup/changing-the-language.md#site-language + [lunr languages]: https://github.com/MihaiValentin/lunr-languages + +Language support is provided by [lunr languages], a collection of +language-specific stemmers and stop words for [lunr.js] maintained by the +Open Source community. + +--- + +The following languages are currently supported by [lunr languages]: + +
+ +- `ar` – Arabic +- `da` – Danish +- `de` – German +- `du` – Dutch +- `en` – English +- `es` – Spanish +- `fi` – Finnish +- `fr` – French +- `hi` – Hindi +- `hu` – Hungarian +- `hy` – Armenian +- `it` – Italian +- `ja` – Japanese +- `kn` - Kannada +- `ko` – Korean +- `no` – Norwegian +- `pt` – Portuguese +- `ro` – Romanian +- `ru` – Russian +- `sa` – Sanskrit +- `sv` – Swedish +- `ta` – Tamil +- `te` – Telugu +- `th` – Thai +- `tr` – Turkish +- `vi` – Vietnamese +- `zh` – Chinese + +
+ +If [lunr languages] doesn't provide support for the selected [site language], +the plugin falls back to another language that yields the best stemming results. +If you discover that the search results are not satisfactory, you can contribute +to [lunr languages] by adding support for your language. + +--- + +#### + + + + +Use this setting to specify the separator used to split words when building the +search index on the client side. The default value is automatically computed +from the [site language], but can also be explicitly set to another value with: + +``` yaml +plugins: + - search: + separator: '[\s\-,:!=\[\]()"/]+|(?!\b)(?=[A-Z][a-z])|\.(?!\d)|&[lg]t;' +``` + +Separators support [positive and negative lookahead assertions], which allows +for rather complex expressions that yield precise control over how words are +split when building the search index. + +Broken into its parts, this separator induces the following behavior: + +=== "Special characters" + + ``` + [\s\-,:!=\[\]()"/]+ + ``` + + The first part of the expression inserts token boundaries for each + document before and after whitespace, hyphens, commas, brackets and + other special characters. If several of those special characters are + adjacent, they are treated as one. + +=== "Case changes" + + ``` + (?!\b)(?=[A-Z][a-z]) + ``` + + Many programming languages have naming conventions like `PascalCase` or + `camelCase`. By adding this subexpression to the separator, + [words are split at case changes], tokenizing the word `PascalCase` + into `Pascal` and `Case`. + +=== "Version strings" + + ``` + \.(?!\d) + ``` + + When adding `.` to the separator, version strings like `1.2.3` are split + into `1`, `2` and `3`, which makes them undiscoverable via search. When + using this subexpression, a small lookahead is introduced which will + [preserve version strings] and keep them discoverable. + +=== "HTML/XML tags" + + ``` + &[lg]t; + ``` + + If your documentation includes HTML/XML code examples, you may want to allow + users to find [specific tag names]. Unfortunately, the `<` and `>` control + characters are encoded in code blocks as `<` and `>`. Adding this + subexpression to the separator allows for just that. + + [positive and negative lookahead assertions]: https://www.regular-expressions.info/lookaround.html + [words are split at case changes]: ?q=searchHighlight + [preserve version strings]: ?q=9.0.0 + [specific tag names]: ?q=script + +--- + +#### + + + + + +Use this setting to specify the [pipeline functions] that are used to filter and +expand tokens after tokenizing them with the [`separator`][config.separator] and +before adding them to the search index. The default value is automatically +computed from the [site language], but can also be explicitly set with: + +``` yaml +plugins: + - search: + pipeline: + - stemmer + - stopWordFilter + - trimmer +``` + +The following pipeline functions can be used: + +- `stemmer` – Stem tokens to their root form, e.g. `running` to `run` +- `stopWordFilter` – Filter common words according, e.g. `a`, `the`, etc. +- `trimmer` – Trim whitespace from tokens + + [pipeline functions]: https://lunrjs.com/guides/customising.html#pipeline-functions + +### Segmentation + +The plugin supports text segmentation of Chinese via [jieba], a popular +Chinese text segmentation library. Other languages like Japanese and Korean are +currently segmented on the client side, but we're considering to move this +functionality into the plugin in the future. + +The following settings are available for segmentation: + + [jieba]: https://pypi.org/project/jieba/ + +--- + +#### + + + + + +Use this setting to specify a [custom dictionary] to be used by [jieba] for +segmenting text, replacing the default dictionary. [jieba] comes with +several dictionaries, which can be used with: + +``` yaml +plugins: + - search: + jieba_dict: dict.txt +``` + +The following dictionaries are provided by [jieba]: + +- [dict.txt.small] – 占用内存较小的词典文件 +- [dict.txt.big] – 支持繁体分词更好的词典文件 + +The provided path is resolved from the root directory. + + [custom dictionary]: https://github.com/fxsjy/jieba#%E5%85%B6%E4%BB%96%E8%AF%8D%E5%85%B8 + [dict.txt.small]: https://github.com/fxsjy/jieba/raw/master/extra_dict/dict.txt.small + [dict.txt.big]: https://github.com/fxsjy/jieba/raw/master/extra_dict/dict.txt.big + +--- + +#### + + + + + +Use this setting to specify an additional [user dictionary] to be used by +[jieba] for segmenting text, augmenting the default dictionary. User +dictionaries are ideal for tuning the segmenter: + +``` yaml +plugins: + - search: + jieba_dict_user: user_dict.txt +``` + +The provided path is resolved from the root directory. + + [user dictionary]: https://github.com/fxsjy/jieba#%E8%BD%BD%E5%85%A5%E8%AF%8D%E5%85%B8 + +## Usage + +### Metadata + +The following properties are available: + +--- + +#### + + + + + +Use this property to increase or decrease the relevance of a page in the search +results, giving more weight to them. Use values above `1` to rank up and values +below `1` to rank down: + +=== ":material-arrow-up-circle: Rank up" + + ``` yaml + --- + search: + boost: 2 # (1)! + --- + + # Page title + ... + ``` + + 1. When boosting pages, always start with low values. + +=== ":material-arrow-down-circle: Rank down" + + ``` yaml + --- + search: + boost: 0.5 + --- + + # Page title + ... + ``` + +--- + +#### + + + + + +Use this property to exclude a page from the search results. Note that this will +not only remove the page, but also all subsections of the page from the search +results: + +``` yaml +--- +search: + exclude: true +--- + +# Page title +... +``` diff --git a/docs/plugins/social.md b/docs/plugins/social.md new file mode 100644 index 000000000..6093b8351 --- /dev/null +++ b/docs/plugins/social.md @@ -0,0 +1,1059 @@ +--- +title: Built-in social plugin +icon: material/share-circle +--- + +# Built-in social plugin + +The social plugin automatically and intelligently generates beautiful and highly +customizable social cards in different [layouts][default layouts] for each page +of your project, rendering as preview images whenever you or somebody else share +a link to your project on social media. + +## Objective + +### How it works + +The plugin automatically generates a customizable social card for each page +of your project, which appears as a preview image when sharing a link to your +project on social media, without the use of external services and just +[a single line of configuration][configuration]. + +With the use of an efficient [image processing] library, the plugin allows to +define [custom layouts] for social cards, which can be adapted to match your +project's style and branding. While it would technically be much simpler to +generate social cards by using a web browser and an automation framework like +[Puppeteer][^1], it would add further liabilities to your toolchain, with the +potential to make build pipelines more complex, much more resource intense, +and significantly slower. + + [^1]: + [GitHub wrote in their blog] that they use [Puppeteer] to generate social + card images for repositories, issues, commits, discussions, and basically + everything else that appear as preview images when shared on social media. + +The generated social cards are [cached] and stored in the +[`site` directory][mkdocs.site_dir], and thus self-hosted, ensuring that your +project doesn't depend on external services. In order to generate social cards +images, a few [dependencies] need to be available on your system. + + [configuration]: #configuration + [image processing]: requirements/image-processing.md + [custom layouts]: ../setup/setting-up-social-cards.md#customization + [Puppeteer]: https://github.com/puppeteer/puppeteer + [GitHub wrote in their blog]: https://github.blog/2021-06-22-framework-building-open-graph-images/ + [cached]: #caching + [dependencies]: #configuration + +### When to use it + +There's one particular case when we don't recommend to use the plugin: when you +build [offline-capable documentation] to offer it as a download. Otherwise, it +always makes sense to enable the plugin, as links to your documentation shared +on social media will appear much more appealing. + +Even more interestingly, the plugin can be combined with other built-in plugins +that Material for MkDocs offers, in order to create sophisticated build +pipelines tailored to your project: + +
+ +- :material-newspaper-variant-outline:   __[Built-in blog plugin][blog]__ + + --- + + The social plugin automatically generates beautiful and customizable + social cards for each post and page, showing as previews on social media. + + --- + + __Links to your blog render beautiful social cards when shared on social media__ + +- :material-file-tree:   __[Built-in meta plugin][meta]__ + + --- + + The meta plugin can be used to [change the layout][meta.social.cards_layout] + for social cards or [change specific layout options] + [meta.social.cards_layout_options] like [background][option.background_color] + or [color][option.color] for a subset of pages. + + --- + + __Your documentation can use completely different social cards per section__ + +
+ + [offline-capable documentation]: ../setup/building-for-offline-usage.md + [blog]: blog.md + [meta]: meta.md + +## Configuration + + + + + + +In order to get started with the social plugin, just add the following lines to +`mkdocs.yml`, and observe how Material for MkDocs generates beautiful social +cards for you: + +``` yaml +plugins: + - social +``` + +The social plugin is built into Material for MkDocs and doesn't need to be +installed. + +However, in order to generate social card images, it's necessary to install the +dependencies for [image processing], if they're not already available on your +system. The linked guide includes instructions for several operating systems +and mentions some alternative environments. + + [social]: social.md + +### General + +The following settings are available: + +--- + +#### + + + + +Use this setting to enable or disable the plugin when [building your project]. +If you want to disable the plugin, e.g., for local builds, you can use an +[environment variable][mkdocs.env] in `mkdocs.yml`: + +``` yaml +plugins: + - social: + enabled: !ENV [CI, false] +``` + +This configuration enables the plugin only during continuous integration (CI). + + [building your project]: ../creating-your-site.md#building-your-site + +--- + +#### + + + + + +With more CPUs available, the plugin can do more work in parallel, and thus +complete social card generation faster. If you want to disable concurrent +processing completely, use: + +``` yaml +plugins: + - social: + concurrency: 1 +``` + +By default, the plugin uses all available CPUs - 1 with a minimum of 1. + +### Caching + +The plugin implements an [intelligent caching] mechanism, ensuring that social +cards are only regenerated when their contents change or they're not already +contained in the cache. If any of the variables used in a layout changes, the +plugin detects it and regenerates the social card. + +The following settings are available for caching: + + [intelligent caching]: requirements/caching.md + +--- + +#### + + + + + +Use this setting to instruct the plugin to bypass the cache, in order to +re-generate social cards for all pages, even though the cache may not be stale. +It's normally not necessary to specify this setting, except for when debugging +the plugin itself. Caching can be disabled with: + +``` yaml +plugins: + - social: + cache: false +``` + +--- + +#### + + + + +It is normally not necessary to specify this setting, except for when you want +to change the path within your root directory where social card images are +cached. If you want to change it, use: + +``` yaml +plugins: + - social: + cache_dir: my/custom/dir +``` + +If you're using [multiple instances] of the plugin, it can be a good idea to +set different cache directories for both instances, so that they don't interfere +with each other. + + [multiple instances]: index.md#multiple-instances + +### Logging + +The following settings are available for logging: + +--- + +#### + + + + + +Use this setting to control whether the plugin should only log errors when +generating social cards without terminating the build, e.g., invalid references +to icons. To terminate the build, use: + +``` yaml +plugins: + - social: + log: false +``` + +--- + +#### + + + + + +Use this setting to control the log level that the plugin should employ when +encountering errors, which requires that the [`log`][config.log] setting is +enabled. The following log levels are available: + +=== "`warn`" + + ``` yaml + plugins: + - social: + log_level: warn + ``` + + Errors are reported as warnings, terminating the build in + [`strict`][mkdocs.strict] mode. + +=== "`info`" + + ``` yaml + plugins: + - social: + log_level: info + ``` + + Errors are only reported as informational messages. + +=== "`ignore`" + + ``` yaml + plugins: + - social: + log_level: ignore + ``` + + Errors are only reported when using the `--verbose` flag. + + +### Social cards + +The following settings are available for social card generation: + +--- + +#### + + + + +Use this setting to enable or disable social card generation. Currently, the +plugin's sole purpose is to generate social cards, so it's equivalent to the +[`enabled`][config.enabled] setting, but in the future, other features might be +added. If you want to disable social card generation, use: + +``` yaml +plugins: + - social: + cards: false +``` + +--- + +#### + + + + +It is normally not necessary to specify this setting, except for when you want +to change the path within the [`site` directory][mkdocs.site_dir] where +social cards are stored. If you want to change it, use: + +``` yaml +plugins: + - social: + cards_dir: my/custom/dir +``` + +This configuration stores the generated images at `my/custom/dir` in the +[`site` directory][mkdocs.site_dir]. + +--- + +#### + + + + + +If you want to build a [custom social card layout][custom layouts], use this +setting to change the folder where you store your custom layouts, the default +being a folder called `layouts` in your root directory: + +``` yaml +plugins: + - social: + cards_layout_dir: layouts +``` + +The provided path is resolved from the root directory. + +!!! tip "Where to store custom layouts" + + Our recommendation is to locate the folder outside of the + [`docs` directory][mkdocs.docs_dir], to make sure that your [custom layouts] + are not copied to the [`site` directory][mkdocs.site_dir] when + [building your project], e.g., by adhering to the following directory + layout: + + ``` { .sh .no-copy } + . + ├─ docs/ + │ └─ *.md + ├─ layouts/ + │ └─ *.yml + └─ mkdocs.yml + ``` + +--- + +#### + + + + + +The plugin ships a growing list of [`default` layouts][default layouts] for +social cards. If you've created a [custom social card layout][custom layouts], +you can instruct the plugin to use it exactly as one of the included layouts: + +``` yaml +plugins: + - social: + cards_layout: my-custom-layout +``` + +The provided path is resolved from the[ +`layouts` directory][config.cards_layout_dir]. + +!!! tip "How custom layouts are resolved" + + By default, the plugin will load your [custom layouts] from a folder named + `layouts` in your root directory. If your layout is called + `my-custom-layout`, the directory layout must adhere to: + + ``` { .sh .no-copy } + . + ├─ docs/ + │ └─ *.md + ├─ layouts/ + │ └─ my-custom-layout.yml + └─ mkdocs.yml + ``` + +--- + +#### + + + + +Use this setting to set options for the layout specified via [`cards_layout`] +[config.cards_layout] (if the layout supports it), which allows for making +layouts easily and entirely configurable: + +``` yaml +plugins: + - social: + cards_layout_options: +