Use a placeholder to simplify relative asset links. #7379
Replies: 2 comments 2 replies
-
Nice hook, the usage of relative links is mandated by the "keep things compatible with other Markdown processors like GitHub or VS Code or keep things standardized to be able to switch to other static site generators more easily" idea. Some users don't need this kind of approach and prefer the ability to write paths more easily. There was a plugin for this:
The As for a quick code review:
As for the meta analysis, assuming large amount of files 1000+ with many links per page, using regex to find links and replacing them will decrease performance, so then it would be better to either hack into the MkDocs internals (there is a list of relative docs paths to File objects) or maybe use a markdown extension and modify links as they come for better performance.🤔 |
Beta Was this translation helpful? Give feedback.
-
Shameless plug... 'x) I wrote a plugin for such a kind of things (internal references only) where the main idea is to avoid writting any kind of address manually and work instead with various identifiers. It provides autocompletion (that is... when using a VSC-like editor), validation of all the references, warns the user when something wrong is found (unknown identifiers ; it also validates relative paths written "the normal way"). Here it is: mkdocs-addresses (docs)
Note that:
If ever that may help... |
Beta Was this translation helpful? Give feedback.
-
Introduction:
Mkdocs encounters difficulties when handling absolute links, especially in conjunction with certain plugins. By default, Mkdocs validates links using the following configuration:
This setup generates a warning for every absolute link present in the documentation. Changing the validation configuration is not a viable option as it may lead to compatibility issues with some plugins. Moreover, using only relative links can be cumbersome and error-prone, particularly when the location of a page changes, necessitating updates to all relative links.
For example:
Solution:
To simplify the process, I wrote a hook that converts links with a placeholder
{assets}
to relative links. This hook assumes that the assets folder is located in thedocs/assets
directory. It allows you to write links in a simplified manner, as shown below:Implementation:
Here is the hook currently used in my documentation:
Discussion:
Is this a case of an XY-Problem? Despite exploring various alternatives, this solution currently seems to be the most effective. However, I'm open to suggestions for better approaches that might resolve the issue more efficiently.
Beta Was this translation helpful? Give feedback.
All reactions