为离线使用而构建¶
¥Building for offline usage¶
如果您想将文档与产品一起发布,MkDocs 可以满足您的需求——借助主题支持, MkDocs支持构建离线文档。值得一提的是,Material for MkDocs 的许多功能都提供了离线支持。
¥If you want to ship your documentation together with your product, MkDocs has you covered – with support from themes, MkDocs supports building offline-capable documentation. Notably, Material for MkDocs offers offline support for many of its features.
配置¶
¥Configuration¶
内置离线插件¶
¥Built-in offline plugin¶
9.0.0离线 – 内置
内置离线插件可确保在您将站点目录内容分发为下载内容时,站点搜索能够正常工作。只需将以下几行添加到mkdocs.yml即可:
¥The built-in offline plugin makes sure that the site search works when you distribute the contents of your site directory as a download. Simply add the following lines to mkdocs.yml:
有关所有设置的列表,请参阅插件文档。
¥For a list of all settings, please consult the plugin documentation.
自动捆绑所有外部资产
¥Automatically bundle all external assets
内置的隐私插件使得在构建离线使用的文档时使用外部资产变得容易,因为它会自动下载所有外部资产并将其与您的文档一起分发。
¥The built-in privacy plugin makes it easy to use external assets while building documentation for offline usage, as it will automatically download all external assets to distribute them with your documentation.
限制¶
¥Limitations¶
MkDocs 的 Material 提供了许多交互式功能,由于现代浏览器的限制,其中一些功能无法在文件系统中使用:所有使用fetch API 的功能都会出错。
¥Material for MkDocs offers many interactive features, some of which will not work from the file system due to the restrictions of modern browsers: all features that use the fetch API will error.
因此,在构建离线使用时,请确保禁用以下配置设置:即时加载、站点分析、 git 存储库、版本控制和评论系统。
¥Thus, when building for offline usage, make sure to disable the following configuration settings: instant loading, site analytics, git repository, versioning and comment systems.