Skip to content
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

Make URL part joining aware of absolute URLs #2196

Merged
merged 2 commits into from
Feb 8, 2018

Conversation

mosra
Copy link
Contributor

@mosra mosra commented Aug 7, 2017

Previously, with RELATIVE_URLS disabled, when both SITEURL and STATIC_URL were absolute, the final generated data URLs looked wrong like this (two absolute URLs joined by /):

http://your.site/http://static.your.site/image.png

With this patch, the data URLs are correctly:

http://static.your.site/image.png

This also applies to all *_URL configuration options (for example, ability to have pages and articles on different domains) and behaves like one expects even with URLs starting with just //, thanks to making use of urllib.parse.urljoin().

However, when RELATIVE_URLS are enabled, urllib.parse.urljoin() doesn't handle the relative base correctly. In that case, simple os.path.join() is used. That, however, breaks the above case, but as RELATIVE_URLS are meant for local development (thus no data scattered across multiple domains), I don't see any problem.

Just to clarify, this is a fully backwards-compatible change, it only enables new use cases that were impossible before.

Properly implements, obsoletes and thus closes #2031 and #2034. Also, besides doing the above, there's a commit that moves the local link replacer function to a _link_replacer() function that's callable from outside -- a minimal subset of #2164 that should not do any harm.

Would be nice if this patch could still make it into 3.8, I'm depending on it quite heavily. Thank you a lot!

@mosra mosra force-pushed the absolute-url-merging branch 2 times, most recently from 4cf4a5b to 23c4135 Compare August 7, 2017 17:10
@mosra mosra force-pushed the absolute-url-merging branch 2 times, most recently from 7eaae71 to 4d4b31d Compare October 26, 2017 20:03
@mosra
Copy link
Contributor Author

mosra commented Oct 26, 2017

Update: looked again into this, rebased onto current master and fixed broken behavior with RELATIVE_URLS enabled. The PR description is updated to reflect that. The Travis build is failing only because some flake8 tests that are broken in master as well. Should be safe to merge, in my opinion.

Thanks in advance!

@justinmayer
Copy link
Member

Thanks, @mosra. I fixed the PyCodeStyle issues via 56a4834 and have re-triggered your PR's build, so everything is green here now. I will take a look at this PR as soon as I can.

mosra added 2 commits October 26, 2017 23:23
So it can be used from outside.
Previously, with RELATIVE_URLS disabled, when both SITEURL and
STATIC_URL were absolute, the final generate data URLs looked wrong like
this (two absolute URLs joined by `/`):

    http://your.site/http://static.your.site/image.png

With this patch, the data URLs are correctly:

    http://static.your.site/image.png

This also applies to all *_URL configuration options (for example,
ability to have pages and articles on different domains) and behaves
like one expects even with URLs starting with just `//`, thanks to
making use of urllib.parse.urljoin().

However, when RELATIVE_URLS are enabled, urllib.parse.urljoin() doesn't
handle the relative base correctly. In that case, simple os.path.join()
is used. That, however, breaks the above case, but as RELATIVE_URLS are
meant for local development (thus no data scattered across multiple
domains), I don't see any problem.

Just to clarify, this is a fully backwards-compatible change, it only
enables new use cases that were impossible before.
@mosra mosra force-pushed the absolute-url-merging branch from 4d4b31d to 0b13aa9 Compare October 26, 2017 21:24
@mosra
Copy link
Contributor Author

mosra commented Oct 26, 2017

Oh, I did the same (rebased and triggered the build) after seeing the commit, because I saw it earlier than your comment :)

Thank you a lot!

@mosra
Copy link
Contributor Author

mosra commented Feb 2, 2018

I have a bunch of new features (such as cache busting for static files etc) that depend on this PR (and mainly 1f30306 in particular -- it just moves a function around, nothing more), would it be possible to get this merged anytime soon so I can rely on something that's already considered stable?

Thank you a lot.

@justinmayer
Copy link
Member

Apologies for the delay, @mosra. Any comments from @getpelican/reviewers?

@justinmayer justinmayer added this to the 3.8.0 milestone Feb 8, 2018
@justinmayer
Copy link
Member

Many thanks for the contribution and for your patience, Vladimír. Much appreciated!

@mosra
Copy link
Contributor Author

mosra commented Feb 9, 2018

Thanks for the merge! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

{filename} issue when {{ SITEURL }} and {{ STATIC_URL }} are different absolute URLS
2 participants