You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MkDocs allows absulute paths assuming that the site is deployed to the root of the hosted website like "http://localhost/". When using the following absolute path "/assets/image1.jpg" it is actually using "http://localhost/assets/image1.jpg" which is correct if the MkDocs is deployed to the site root.
3
+
MkDocs assumes absolute paths start from the root of the hosted website, like `http://localhost/`. For example, an absolute path like `/assets/image1.jpg` becomes `http://localhost/assets/image1.jpg`, which is correct if MkDocs is hosted at the root.
4
4
5
-
When the server root is not the same as the MkDocs root, the webcontext plugin can be used to define a webcontext to use instead of the defined root. The webcontext path which can be anyting like "/projectname/documents" is used where "/" is defined.
5
+
When the server root is not the same as the MkDocs root, this plugin lets you define a `webcontext` to prepend to these absolute paths. The `webcontext` path (e.g., `/projectname/documents`) replaces the default root (`/`).
6
6
7
-
Some examples of site urls before and after using the webcontext plugin:
2. In your project, add a plugin configuration to `mkdocs.yml`:
25
+
## Quick Start
26
+
27
+
1. Install the plugin:
28
+
29
+
```bash
30
+
pip install mkdocs-webcontext-plugin
31
+
```
32
+
33
+
Or using Poetry:
34
+
35
+
```bash
36
+
poetry add mkdocs-webcontext-plugin
37
+
```
38
+
39
+
2. Enable the plugin in your `mkdocs.yml`:
23
40
24
41
```yaml
25
42
plugins:
26
43
- webcontext:
27
44
context: foo/bar
28
45
```
29
46
30
-
Special thanks to the following repositories for guidance:
47
+
## Supported Link Types
48
+
49
+
The plugin modifies the following path formats:
50
+
51
+
* Markdown links: `[title](/path/image.png)`
52
+
* Markdown reference links:
53
+
54
+
```markdown
55
+
[logo]: /assets/logo.png
56
+
```
57
+
* HTML image tags: `<img src="/assets/img.png">`
58
+
* CSS `url()` paths: `url("/assets/bg.jpg")`
59
+
60
+
These paths will be rewritten to start with your defined `context`.
61
+
62
+
## CSS Support
63
+
64
+
After your site is built, the plugin will scan all `.css` files in the output directory and rewrite any `url("/...")` references to use the defined `context`.
65
+
66
+
## Logging
67
+
68
+
Rewrites are logged at the `DEBUG` level. Updated CSS files are logged at the `INFO` level.
69
+
70
+
## Special Thanks
71
+
72
+
This plugin was inspired by and built with guidance from:
0 commit comments