Skip to content

Commit eac7071

Browse files
committed
Added documentation for offline plugin
1 parent bcacf4c commit eac7071

5 files changed

+103
-36
lines changed
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
template: overrides/main.html
3+
---
4+
5+
# Building for offline usage
6+
7+
If you want to ship your documentation together with your product, MkDocs has
8+
you covered – with support from themes, [MkDocs] allows for building
9+
offline-capable documentation. Luckily, Material for MkDocs offers offline
10+
support for many of its features.
11+
12+
[MkDocs]: https://www.mkdocs.org
13+
14+
## Configuration
15+
16+
### Built-in offline plugin
17+
18+
[:octicons-heart-fill-24:{ .mdx-heart } Insiders][Insiders]{ .mdx-insiders } ·
19+
[:octicons-tag-24: insiders-4.10.0][Insiders] ·
20+
:octicons-cpu-24: Plugin ·
21+
:octicons-beaker-24: Experimental
22+
23+
The built-in offline plugin makes sure that the [site search] works when you
24+
distribute the contents of your [site directory] as a download. Simply add
25+
the following lines to `mkdocs.yml`:
26+
27+
``` yaml
28+
plugins:
29+
- offline # (1)!
30+
```
31+
32+
1. Note that the offline plugin should be located at the end of the list of
33+
`plugins`, as it will post-process the search index. If you want to use
34+
other plugins that alter the search index together with this plugin, add
35+
them before the built-in offline plugin.[^1]
36+
37+
[^1]:
38+
Offline search was previously implemented through the third-party
39+
[localsearch] plugin, which is still possible if you don't want to use
40+
[Insiders]. Note, however, that setup might be challenging if you're not
41+
experienced with MkDocs.
42+
43+
The plugin will automatically disable [`use_directory_urls`][use_directory_urls]
44+
via `mkdocs.yml`, ensuring that the user can open your documentation directly
45+
from the local file system.
46+
47+
The following configuration options are available:
48+
49+
`enabled`{ #enabled }
50+
51+
: :octicons-milestone-24: Default: `true` – This option specifies whether
52+
the plugin is enabled when building your project. If you want to switch
53+
the plugin off, e.g. for local builds, use an [environment variable]:
54+
55+
``` yaml
56+
plugins:
57+
- privacy:
58+
enabled: !ENV [OFFLINE, false]
59+
```
60+
61+
Now, after invoking `mkdocs build`, you can open `site/index.html` directly
62+
in your browser and the [site search] will work as if the documentation was
63+
hosted on a regular server.
64+
65+
!!! tip "Automatically bundle all external assets"
66+
67+
The brand-new [built-in privacy plugin] makes it easy to use external assets
68+
while building documentation for offline usage, as it will automatically
69+
download all external assets to distribute them with your documentation.
70+
71+
[Insiders]: ../insiders/index.md
72+
[site search]: setting-up-site-search.md
73+
[site directory]: https://www.mkdocs.org/user-guide/configuration/#site_dir
74+
[localsearch]: https://github.com/wilhelmer/mkdocs-localsearch/
75+
[use_directory_urls]: https://www.mkdocs.org/user-guide/configuration/#use_directory_urls
76+
[environment variable]: https://www.mkdocs.org/user-guide/configuration/#environment-variables
77+
[built-in privacy plugin]: ensuring-data-privacy.md#built-in-privacy-plugin
78+
79+
#### Limitations
80+
81+
Material for MkDocs offers many interactive features, some of which will not
82+
work from the file system due to the restrictions of modern browsers: all
83+
features that use the `fetch` API will error.
84+
85+
Thus, when building for offline usage, make sure to disable the following
86+
configuration settings: [instant loading], [site analytics], [git repository],
87+
[versioning] and [comment systems].
88+
89+
[Instant loading]: setting-up-navigation.md#instant-loading
90+
[Site analytics]: setting-up-site-analytics.md
91+
[Versioning]: setting-up-versioning.md
92+
[Git repository]: adding-a-git-repository.md
93+
[Comment systems]: adding-a-comment-system.md

docs/setup/changing-the-logo-and-icons.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ theme:
8484
In order to use custom icons, [extend the theme] and create a new folder named
8585
`.icons` in the [`custom_dir`][custom_dir] you want to use for overrides.
8686
Next, add your `*.svg` icons into a subfolder of the `.icons` folder. Let's say
87-
you downloaded and unpacked the [Bootstrap] icon set, and want to add it to
87+
you downloaded and unpacked the [Bootstrap] icon set, and want to add it to
8888
your project documentation. The structure of your project should look like this:
8989

9090
``` sh

docs/setup/ensuring-data-privacy.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ template: overrides/main.html
77
Material for MkDocs makes compliance with data privacy regulations very easy,
88
as it offers a native [cookie consent] solution to seek explicit consent from
99
users before setting up [tracking]. Additionally, external assets can be
10-
automatically bundled as part of the build process.
10+
automatically downloaded for self-hosting.
1111

1212
[cookie consent]: setting-up-site-analytics.md#cookie-consent
1313
[tracking]: setting-up-site-analytics.md
@@ -22,8 +22,8 @@ automatically bundled as part of the build process.
2222
:octicons-beaker-24: Experimental
2323

2424
The built-in privacy plugin automatically identifies [external assets] as part
25-
of the build process and allows to download and serve them as part of your site.
26-
Add the following to `mkdocs.yml`:
25+
of the build process and download all assets for dead simple self-hosting. Add
26+
the following lines to `mkdocs.yml`:
2727

2828
``` yaml
2929
plugins:
@@ -65,9 +65,13 @@ The following configuration options are available:
6565
If you've removed all external assets from your project via [customization],
6666
it's still a good idea to enable the plugin and set the mode to `report`,
6767
as the plugin will make sure that there are no hidden external links in any
68-
Markdown files that were unintentionally added to the build.
68+
Markdown files that were unintentionally added.
69+
70+
Using `report` in [strict mode] will make the build fail when external
71+
assets are detected.
6972

7073
[customization]: ../customization.md
74+
[strict mode]: https://www.mkdocs.org/user-guide/configuration/#strict
7175

7276
`externals_directory`{ #externals-directory }
7377

docs/setup/setting-up-site-search.md

-31
Original file line numberDiff line numberDiff line change
@@ -305,37 +305,6 @@ clipboard.
305305

306306
[search.share support]: https://github.com/squidfunk/mkdocs-material/releases/tag/7.2.0
307307

308-
### Offline search
309-
310-
[:octicons-heart-fill-24:{ .mdx-heart } Insiders][Insiders]{ .mdx-insiders } ·
311-
[:octicons-tag-24: insiders-4.7.0][Insiders] ·
312-
:octicons-beaker-24: Experimental
313-
314-
Insiders makes sure that the built-in search also works when you distribute your
315-
documentation as `*.html` files for download. Simply add the following lines to
316-
`mkdocs.yml`:
317-
318-
``` yaml
319-
use_directory_urls: false
320-
```
321-
322-
This ensures that `index.html` is appended to all internal URLs, which is
323-
necessary for allowing users to view your documentation locally and without
324-
Internet connection. No further setup is necessary – your documentation will
325-
work online and offline without any further ado.[^1]
326-
327-
Now, after invoking `mkdocs build`, you can open `site/index.html` directly
328-
in your browser and the built-in search will work as if the documentation was
329-
hosted on a regular server.
330-
331-
[^1]:
332-
Offline search was previously implemented through the third-party
333-
[localsearch] plugin, which is still possible if you don't want to use
334-
[Insiders]. Note, however, that setup might be challenging if you're not
335-
experienced with MkDocs.
336-
337-
[localsearch]: https://github.com/wilhelmer/mkdocs-localsearch/
338-
339308
## Usage
340309

341310
### Search boosting

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ nav:
187187
- Setting up the footer: setup/setting-up-the-footer.md
188188
- Adding a git repository: setup/adding-a-git-repository.md
189189
- Adding a comment system: setup/adding-a-comment-system.md
190+
- Building for offline usage: setup/building-for-offline-usage.md
190191
- Extensions:
191192
- setup/extensions/index.md
192193
- Python Markdown: setup/extensions/python-markdown.md

0 commit comments

Comments
 (0)