构建优化网站¶
¥Building an optimized site¶
Material for MkDocs 默认支持构建优化的网站,使其在搜索引擎上排名靠前、加载速度快(即使在慢速网络环境下),并且无需 JavaScript 即可完美运行。此外,内置的优化插件还支持更多实用的自动优化技术。
¥Material for MkDocs, by default, allows to build optimized sites that rank great on search engines, load fast (even on slow networks), and work perfectly without JavaScript. Additionally, the built-in optimize plugin adds support for further useful automatic optimization techniques.
配置¶
¥Configuration¶
内置项目插件¶
¥Built-in projects plugin¶
insiders-4.38.0项目 – 内置
¥ insiders-4.38.0 projects – built-in
内置的项目插件允许将文档拆分为多个不同的 MkDocs 项目,并同时构建它们并一起提供。将以下内容添加到mkdocs.yml中:
¥The built-in projects plugin allows to split your documentation into multiple distinct MkDocs projects, build them concurrently and serve them together. Add the following to mkdocs.yml:
有关所有设置的列表,请参阅插件文档。
¥For a list of all settings, please consult the plugin documentation.
Use cases for the projects plugin
项目插件的理想用例是:
¥Ideal use cases for the projects plugin are:
构建多语言网站
¥Building a multi-language site
在撰写文档的同时建立博客
¥Building a blog alongside your documentation
拆分大型代码库以获得更好的性能
¥Splitting large code bases for better performance
请注意,该插件目前处于实验阶段。我们提前发布它,以便与用户共同改进,并在发现新的用例后使其更加强大。
¥Note that the plugin is currently experimental. We're releasing it early, so that we can improve it together with our users and make it even more powerful as we discover new use cases.
范围¶
¥Scope¶
8.0.0
在某些情况下,你可能希望在所有项目之间共享用户级设置,例如所选调色板或Cookie 同意。为此,请将以下几行添加到mkdocs.yml中:
¥There might be a use case, where you want to share user-level settings like the selected color palette, or cookie consent across all projects. To do so, add the following lines to mkdocs.yml:
工作原理
¥How it works
假设您有以下站点结构:
¥Suppose you have this site structure:
By default, each site will have its own scope (/subsite-a/, /subsite-b/, /subsite-c/). To modify this behaviour, add the following lines to mkdocs.yml: 通过将其设置为/ ,它应该允许您在主站点和所有子站点之间共享以下首选项:
¥By setting it to /, it should allow you to share the following preferences across the main site and all subsites:
内置优化插件¶
¥Built-in optimize plugin¶
insiders-4.29.0优化 – 内置
¥ insiders-4.29.0 optimize – built-in
内置的优化插件会在构建过程中使用压缩和转换技术自动识别并优化所有媒体文件。将以下几行添加到mkdocs.yml中:
¥The built-in optimize plugin automatically identifies and optimizes all media files as part of the build using compression and conversion techniques. Add the following lines to mkdocs.yml:
有关所有设置的列表,请参阅插件文档。
¥For a list of all settings, please consult the plugin documentation.