An MkDocs plugin for linking without specifying the full relative path and other features that ease using the file structure to generate navigation.
Project description
mkdocs-awesome-autolinks
The MkDocs Awesome Autolinks plugin makes it possible to link to pages and images without specifying the full relative path. In addition, to ease using the file structure to generate navigation, it will remove a configurable part from the directory and page file name that can be used to order the navigation and page structure.
As a result the part of directory and page names that is used to order pages does not have to be included in links and will not show in the URLs of the built site. Otherwise links would break when the page order is changed and the part used for sorting would clutter the site URLs.
This plugin has been built to be used in combination with the Awesome Pages plugin that allows combination of custom navigation with file structure. Hence the awesome in the name of this plugin. Tough there is no relation with or dependency on the Awesome Pages Plugin.
The functionality to remove a part of file and directory names can be disabled in mkdocs.yml
and
the autolink functionality will continue to work.
Installation
Note: This package requires Python >=3.7 and MkDocs version 1.4 or higher.
Install the package with pip:
pip install mkdocs-awesome-autolinks
Enable the plugin in your mkdocs.yml
:
plugins:
- awesome-autolinks
Configuration of the plugin is possible but not necessary if the default behavior suits your need.
Usage
More information will be provided in the future. Here is a short summary of how the automatic linking can be used.
- The default pattern for the sorting part of directory and file names is that the start
of each file/directory name contains numbers followed by a
-
. For example010-about.md
or in case of a file in a directory100-examples/010-about.md
.
There is no limit to the amount of numbers. - Instead of specifying the full relative path in a link only include the file name. From here on
it will be called a short link. An example of a short link is
[About](about.md)
. This plugin will replaceabout.md
with the relative path to the page file. Normal MkDocs processing will transform the Markdown link with relative path to HTML. - In case there is a short link on a page but there are multiple files in the whole docs directory
with the file name of that short link a warning will be logged but this depends of the
warn_less
setting. Ifwarn_less
is true, the default, a warning is only logged if there is no file with the same name in the same directory branch or if there are multiple files with the same name in the same directory branch.
So it is safe to have link[About](about.md)
on a page if fileabout.md
is located somewhere in a subdirectory of the directory where the page with the short link is located. Even if there are otherabout.md
files in other directory branches, as long as they can only be reached by going higher up in the directory tree (do a ../ first). - Some page file names are very common. Instead of forcing unique file names the directory
the file is located in can be included in the short link. For example
[Subject A](subject-a/index.md)
. - Normal relative links such as
[Subject A](../subjects/subject-a/index.md)
can still be used. Configuration settingwarn_on_no_use
will determine whether a warning will be logged about not using the autolink functionality. - Removal of a part from the directory and page file names can be disabled by setting
remove_re
to an empty string.
Configuration
The following configuration options can be set in mkdocs.yml
. Values shown here are the default.
plugins:
- awesome-autolinks:
remove_re: '^[0-9]+-'
warn_less: true
warn_on_no_use: true
ignore_dirs:
- css
- fonts
- img
- js
- search
debug: false
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mkdocs_awesome_autolinks-0.9.1.tar.gz
.
File metadata
- Download URL: mkdocs_awesome_autolinks-0.9.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a503c9d31316d1528c69a92dc68feb28d6f0df746d1b1f973f7c0839c257c99c |
|
MD5 | 7a9588614b0974f5c6910bc7bcdc9ac9 |
|
BLAKE2b-256 | 101f808f024091f0aa45ca7f17b919c09353b696429324eb413e2732793de935 |
File details
Details for the file mkdocs_awesome_autolinks-0.9.1-py3-none-any.whl
.
File metadata
- Download URL: mkdocs_awesome_autolinks-0.9.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccbe7c675ccd4b3407972236a83a15786270405e2aa2e36bc65533de413efa46 |
|
MD5 | 2bfe67179e63e23852b4fb02d97df1f5 |
|
BLAKE2b-256 | dcc9b8dc60cdda287cec30d342b81c2c12be997a5f00f24c81a92500164bb1f5 |