Replies: 3 comments 2 replies
-
I assume you are not controlling the generation of the files? We did have a question about adding a base_url to image paths the other day, which might be helpful: #6615. It seems that the mkdocs-site-urls plugin does the job. I have not tried it myself, so feedback would be very welcome. Re the Gitlab instant loading issue, can you be a bit more specific and provide information about what is not working and what you have done so far to investigate? |
Beta Was this translation helpful? Give feedback.
-
Hello @Lexachoc, mkdocs-material/src/templates/base.html Line 102 in b7fc7ba https://github.com/mkdocs/mkdocs/blob/e755aaed7ea47348a60495ab364d5483ab90a4a6/mkdocs/utils/templates.py#L38 So you could use a hook to monkey patch the function to meet your needs, here is an example: url_filter.zip In the example I add a base_path prefix to paths starting with assets/
The hook filetry:
from jinja2 import pass_context as contextfilter # type: ignore
except ImportError:
from jinja2 import contextfilter # type: ignore
from mkdocs.utils import templates
def on_startup(*_, **__):
templates.url_filter = url_filter_wrapper(templates.url_filter)
def url_filter_wrapper(func):
base_path = "/mkdocs/site/"
@contextfilter
def wrapper(context, value):
if value.strip().startswith("assets/"):
value = base_path + value.strip()
return func(context, value)
return wrapper Having said that, I consider this issue out of scope of the theme, as the server is responsible for serving the files. As for the Instant loading not working, the logic is in JavaScript, so check the developer tools in your browser. |
Beta Was this translation helpful? Give feedback.
-
@kamilkrzyskow thank you so much! I add the issue open in here: #6792 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This question relates to the use of FastAPI, but more to the mkdocs material here.
Issue with FastAPI
The issue came to me when I want to serve static files and the
build mkdocs pages
from a directory using StaticFiles.For example, my application structure looks like this:
my FastAPI main.py:
app
folder where main.py is located, runpython -m uvicorn main:app --reload
and go tohttp://localhost:8000/mkdocs
because the build files are using relative paths for stylesheets or javascripts
I have to manually add a prefix
/mkdocs/site/
to all the src locations in the auto-generated html filesSo I would like to know if there is a configuration for adding a base_url as a prefix to the locations of these auto-generated files?
I tried to add site_url, but apparently this has nothing to do with the relative locations within the automatically generated HTML files
Issue with Instant loading
The instant loading function does not work when deploying with GitLab. (Since I have problems with FastAPI deployment, I am currently using GitLab CI to deploy the pages)
I use the exact same
gitlab-ci.yml
task from https://squidfunk.github.io/mkdocs-material/publishing-your-site/#gitlab-pagesand noticed that the instant loading won't work in gitlab pages while it works locally using
mkdocs serve
For reproduction:
app.zip
app
folder where main.py is locatedpython -m uvicorn main:app --reload
http://localhost:8000/mkdocs
FastAPI version: 0.109.0
mkdocs-material version: 9.5.9
Does anyone know the solution to these problem?
Beta Was this translation helpful? Give feedback.
All reactions