-
Notifications
You must be signed in to change notification settings - Fork 448
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
URLs for sites not in the webserver root are broken [was: The image url is not correct.] #986
Comments
I believe there was an issue of this sort already. Nikola seems not to like sites deployed to a subdirectory. But this needs more investigation. |
Looks like it’s a part of #912. Copy-pasting so it’s in a sane location, also re-titled the issue properly:
|
Is |
I have identified the issue before (when the issue came up, might not be up-to-date) to be |
>>> urljoin('http://a.com/foo/', 'bar/')
'http://a.com/foo/bar/'
>>> urljoin('http://a.com/foo/', '/bar/')
'http://a.com/bar/' |
@Kwpolska, that is because beginning with / refers to root. Should be easy enough to strip out the leading slash. |
We are actually doing this in some places! |
…-subdirectory work Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
not fixed yet, sorry. |
I had to take out a semi-fix because it crashed the tests. It won’t be included in the new release then. |
i'd like to try and reproduce this, anyone with some public m.w.e.? is it known to affect 9f2d691 ? (current master as of the time im writting) |
@mike4999 yes: it’s all broken everywhere. urljoin is the main culprit, there is also some crazy code in galleries. |
@Kwpolska so to reproduce all that needs to be done is create galleries in a project with |
yes. More things are broken, including links in RSS, sitemaps; see 87bb8b7 for more (possibly not everything) |
One way to fix it is write a replacement urljoin that strips the initial "/" in the paths. |
or better, if the input starts with a / it could do it mindful of the base url. |
Working on it. |
Reproduced. |
RSS feeds are also broken. |
@max-arnold which rss feeds, the gallery ones? |
Posts for example. http://ar0.me/blog/en/rss.xml http://ar0.me/blog/rss.xml Both SITE_URL and BASE_URL are set to |
This bug has an even more obvious effect on the blog name link on the navbar due to the base template using def urljoin(base, url):
if url.startswith("/"): # mind our SITE_URL root
template = urllib.parse.urljoin("http://base_placeholder/", url)
return template.replace("http://base_placeholder", base.rstrip("/"))
else:
return urllib.parse.urljoin(base, url) |
Probably wasn’t meant to be closed. Reopening. |
Indeed, I just fixed a part of it. |
Also, I'm struggling to set absolute path for favicon. It is located at http://example.com/static/favicon.ico. Blog is located at http://example.com/blog/. If I specify it this way:
actual generated link will become relative |
@max-arnold, workaround (untested but should work): |
@Kwpolska It works, but embeds domain name and http scheme into the link. Any chances it will be fixed properly someday? |
@max-arnold I am taking a piece-by-piece approach here. Can you open a separate issue describing that specific problem? I promise to fix it in the following day. |
@max-arnold I am looking at the favicon issue. What Nikola is doing is considering "/static/favicon.ico" as meaning "this path inside what Nikola generates". And you want it to mean "this path relative to the site root". I agree that your reading makes sense and I am trying to figure out a fix. |
@max-arnold ok, so, good news, bad news ;-) Bad news: it's very hard to make the favicon path mean what you want it to mean. Basically, Nikola always generates URLs as if it's the only thing in the world, then makes them relative so the site can be "relocated". That means / is Nikola's Good news: you can use if the site is in |
Yes, explicit way to produce both absolute and relative links in Nikola would be good. |
@max-arnold I suppose we could use some overloaded syntax. For example, we have link:// for links that are converted into configurable destinations. We could use link:///foo to mean "just use /foo" |
Thanks, this is better workaround than embedding absolute urls. |
In theory, to get absolute urls in conf.py we can use something like this, although I don't like another config variable:
What to do in templates/posts/articles/galleries is more tricky. Adding new overloaded syntax for links in markdown/rest is probably bad idea. |
The syntax is already implemented, all it needs is: if dst_url.scheme == 'link':
if dst_url.startswith('/'):
return dst_url Though I personally believe re-using |
@Kwpolska well, more or less that, yes, I just proposed a branch for it. It's a harmless workaround until we can find a better solution, and it may be handy in itself. link is undocumented anyway ;-) |
We should create some more documentation of our internals. It could even sit in the github wiki instead of getnikola.com. |
Fix absolute paths in favicons (Issue #986)
So, I fixed links in galleries and RSS. Are there any other broken links? Or we just close this one? |
I don't get that for sitemaps. Setting BASE_URL to http://getnikola.com/blog/ I get these:
|
Actually, no. Sitemaps work. @asmeurer’s site is broken because he set Though there is still an issue with |
@Kwpolska can you give me a hint of where it fails and how? I can fix these things really quickly but diagnosing takes more time than I have today :-) |
Sure thing! Well, basically, everything fails. with <link rel="canonical" href="http://getnikola.com/index.html">
<a class="navbar-brand" href="http://getnikola.com/">Demo Site</a>
<li><a href="/archive.html">Archives</a>
</li><li><a href="/categories/index.html">Tags</a>
</li><li><a href="/rss.xml">RSS</a> with <link rel="canonical" href="http://getnikola.com/index.html">
<a class="navbar-brand" href="http://getnikola.com/">Demo Site</a>
<li><a href="http://getnikola.com/archive.html">Archives</a>
</li><li><a href="http://getnikola.com/categories/index.html">Tags</a>
</li><li><a href="http://getnikola.com/rss.xml">RSS</a> No links are correct. |
Looks like that "feature" was never tested much. I'd say let's close this bug and open one or two more for those. |
Considering it’s not the default and affecting only willing people, we can do this. For the record, tried this: 3210de1 And travis crashed badly. I took it out because it was right before the release and I didn’t have time to tinker with it and debug. |
I can work with that. So, closing this one, and opened #1046 |
My site is in a subfolder, such as http://www.abc.com/blog/. The url of image in the gallery is not correct.
If I put a jpg file in galleries/software/screen.jpg, after building, the url will be http://www.abc.com/galleries/software/screen.jpg. In face it should be http://www.abc.com/blog/galleries/software/screen.jpg.
The images in the posts are good.
Nikola version 6.2.1
The text was updated successfully, but these errors were encountered: