-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image paths can break when deploying to gh-pages #1757
Comments
For consistent results the documentation actually points out that relative paths are required. You may or may not get things to work correctly with absolute paths and use them at your own risk. In fact, they only work if the mkDocs root and server root are the same directory. The reason for this is that relative paths are adjusted by MkDocs to ensure they are always relative to the page, However, absolute paths are not modified at all. In other words, absolute paths do not get adjusted based on the server environment. We do not adjust absolute URLs as some users actually want/need that behavior. For example, some users may want to link to something hosted on the same sever, but outside of MkDocs. Suppose the MkDocs site was at Finally, note that if you are in an environment where the MkDocs root directory is a subdirectory of the server root, then you should set the site_url config setting to include the subdirectory. For example: site_url: https://username.github.io/repo-name/ The local dev server will then use that subdirectory, which will help to ensure consistent behavior between the local dev server and your production server. In conclusion, the problem is user error, not a bug. Two things should be done to correct the problem:
|
Thanks for taking a look at this. I have a follow-up question: I have https://username.github.io/repo-name/ If I use |
Sorry, my last comment was slightly misleading. Actually, including the subdir in |
Okay, thanks I will look into it. Now that I read the docs more thoroughly, it does seem clearer that relative paths are the way to go. This wasn't clear for me before, and the paste image vscode happened to be configured on my machine to use absolute paths. Now I managed to reconfigure it to use relative paths so it's all good. Maybe we should add an explicit warning in the documentation about the usage of absolute paths not being supported and recommended. I would be happy to do a PR if you think it's a good idea. |
I'm always happy to review PRs. |
i am using image links exactly as @devakker described, but my yml is generating links like this : https://username.github.io/img/image.png (i.e not including sitename at all, causing error. What could be the possible issue?
|
As I explained, this is the wrong way to format your links.
|
@waylan i think i am confused about the concept of relative and absolute paths. To clarify, My markdown files import images as |
No a relative path does not start with a slash. Your path needs to be 'relative' to the current file location. |
@waylan how am i supposed yo maintain a clean repository if i have to make picture location relative to "current folder" and not "parent folder" ? currently , i am using the following structure for my I try to access them via I even feel the end location is being successfully identified i.e the pictures present in the I am guessing its my repo problem. Should i create a new issue? |
To link from As a reminder, MkDocs is a tool for generating technical documentation. We assume users have a technical background. Additionally, as it is a command line tool, we assume that users understand the basis of the command line, which includes an understanding of relative paths. |
Oops😅, I apologize. I am not a fan of web development and never came across this special |
This is not specific to web development and is not "special," but is a standard feature at the system level. For example, see Absolute and Relative Pathnames in UNIX, which was one of the top results in a quick search (perhaps not the best explanation, but the first I found with little effort). In any event, I'm glad to have helped. |
Thanks @devakker, saved a lot of debugging!! :) |
tl;dr
I'm new in Let's suppose a project like this: /docs/
|-- img/
|-- image.svg # /docs/img/image.svg
|-- index.md # /docs/index.md
|--page-a.md # /docs/page-a.md Importing
However, importing
I suppose that difference between markdown and raw HTML became from the fact that "When including internal links within raw HTML, you will need to manually format the link appropriately for the rendered document." (see more here). However, concerning to difference between |
@danielpcampagna there are two separate reasons why various of those URLs failed.
|
I'm using relative urls, but the images are still not working. |
@lindsayfowler |
refer: mkdocs/mkdocs#1757 Signed-off-by: litreily <707922098@qq.com>
Github says: "For consistent results the documentation actually points out that relative paths are required. " mkdocs/mkdocs#1757
Link still not working deployed; needs further troubleshooting, see solution for future reference: mkdocs/mkdocs#1757
img
folder inside the root of your docs![](/img/image.png)
The generated HTML will link to the image like this:
<p><img alt="" src="/img/image.png" /></p>
But the image will actually be at
https://username.github.io/repo-name/img/image.png
and it won't show up.This entire issue can be avoided (and most likely is by a lot of people) by using relative paths. Still worth considering if maybe the repo's name should automatically added before the image URL, if it's an absolute path.
config: mkdocs 1.0.04, windows10
The text was updated successfully, but these errors were encountered: