Skip to content

Additional aspects

Several aspects of documentation production are not covered by the basic MkDocs and its Material for theme.

Online versus offline

The standard rendering of site content is for either online or offline consumption, only one of these at the same time.

There is something to be said for a ‘brute force’ approach in which mkdocs produces output for both target platforms, more or less simultaneously. When publishing the rendered output, the operator could select either the offline representation or the online representation for publication – both being readily available at any time then.

Multi-site expansion

A single MkDocs ‘project’, resulting in a single rendered ‘site’ (in online form, offline form or both), may be too narrow for really wide collections of documentation.

Uptick allows multiple MkDocs projects to be ‘stitched together’. Each project exists in its own right, but can have a parent project that can be reached easily.

For the uplink to its immediate parent project, a MkDocs project does not need to do anything. It need not even know that it is part of a wider Uptick umbrella. As such, Uptick-united MkDocs projects have an independent existence, independence which becomes apparent in searches. Any search performed within a MkDocs project is performed only against content within the project.

At the same time, the projects under the umbrella, and the content within these projects, do have predictable paths. Through this, projects have the ability to refer to content in other projects they may be aware of – if they so wish.

Offline rendering

With the privacy plugin enabled, [the Material for plugin to] MkDocs will attempt to fetch content from the public Internet. When the rendering server has no connectivity to the Internet (as, for security reasons, it should not), the mkdocs build process fails, with...

WARNING -  Couldn't retrieve https://unpkg.com/mermaid@11/dist/mermaid.min.js:
           HTTPSConnectionPool(host='unpkg.com', port=443): Max retries exceeded
           with url: /mermaid@11/dist/mermaid.min.js (Caused by
           NameResolutionError("<urllib3.connection.HTTPSConnection object at
           0x7fbd6b187760>: Failed to resolve 'unpkg.com' ([Errno -2] Name or
           service not known)"))

...or perhaps...

WARNING -  Couldn't retrieve https://unpkg.com/mermaid@11/dist/mermaid.min.js:
           HTTPSConnectionPool(host='unpkg.com', port=443): Max retries exceeded
           with url: /mermaid@11/dist/mermaid.min.js (Caused by
           NewConnectionError('<urllib3.connection.HTTPSConnection object at
           0x7fc2f7b26a30>: Failed to establish a new connection: [Errno 101]
           Network is unreachable'))

Downloaded files get dumped on the build-local filesystem, by default in a subdirectory .cache off the current working directory. As long as this directory remains in place, MkDocs will make no further attempt to download the content.

In mkdocs.yml, a sub-entry cache_dir can be placed beneath the entry for the privacy plugin. This changes...

plugins:
  - privacy
  - offline

...into...

plugins:
  - privacy:
      cache_dir: /path/to/cache
  - offline

...in which the cache_dir value is the path, presumably absolute to avoid any uncertainty, to a filesystem directory that can be filled while the rendering server does have Internet connectivity.

In the caching, there is a link with the font setting of the theme as well, as in...

theme:
  name: material
  palette:
    primary: blue grey
  font: true

When the font theme setting is set to true, the privacy plugin downloads a bunch of fonts as well, from Google.

The placement of correct cache_dir directives is handled by the rendering process of Uptick. Before mkdocs is run against any project, the mkdocs.yml file of that project is patched to ensure it contains the right directives with the right values.