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

Document absURL and relURL’s behaviours with leading / slash #469

Closed
anthonyfok opened this issue May 2, 2018 · 9 comments · Fixed by #1895
Closed

Document absURL and relURL’s behaviours with leading / slash #469

anthonyfok opened this issue May 2, 2018 · 9 comments · Fixed by #1895

Comments

@anthonyfok
Copy link
Member

anthonyfok commented May 2, 2018

absURL and relURL seems to ignore the sub-folder of the baseURL when it is given a path with a leading / slash, but that behaviour isn't documented in https://gohugo.io/functions/absurl https://gohugo.io/functions/relurl.

See theNewDynamic/gohugo-theme-ananke#103 for example.

TODO: Study AbsURL() and RelURL() in helpers/url.go (and maybe fix the comments there too) before touching hugoDocs

@kaushalmodi
Copy link
Contributor

This has come up many times before.. I believe it's a bug.. but we need to document whatever the current behavior is.

Here's a recent thread with lots of detailed discussion.

@anthonyfok anthonyfok changed the title Document absURL and relURL behaviours with leading / slash Document absURL ~~and relURL~~ behaviours with leading / slash May 17, 2018
@anthonyfok anthonyfok changed the title Document absURL ~~and relURL~~ behaviours with leading / slash Document absURL and relURL’s DIFFERENT behaviours with leading / slash May 17, 2018
@anthonyfok
Copy link
Member Author

Okay, here is a historical account of what led to today's absURL behaviour:

  1. Hugo 0.14: absURL and relURL were born:

  2. Hugo 0.15: Same behaviour as in Hugo 0.14.

  3. Hugo 0.16: absURL's behaviour changed, and remained the same to this day:

@anthonyfok
Copy link
Member Author

See also https://discourse.gohugo.io/t/problem-with-relurl-on-hugo-themes-demo-sites/11850 (Problem with relURL on Hugo Themes demo sites)

And MunifTanjim/minimo#121. Is it really a Hugo bug as @MunifTanjim suggested? Or is it something else? Oh! Indeed! Running hugo with the environment variable HUGO_CANONIFYURLS=true changes relURL's output! Hmm....

@anthonyfok
Copy link
Member Author

Extensive discussion HUGO_CANONIFYURLS=true here: https://discourse.gohugo.io/t/baseurl-path-subdir-sometimes-ignored-by-relurl-absurl/11512 (Thank you @kaushalmodi for providing that link!)

@kaushalmodi
Copy link
Contributor

@anthonyfok You're welcome. Here's a test page (that I also link in the discourse thread you linked), that summarizes the absURL vs relURL vs canonifyURLs: https://hugo-sandbox.netlify.com/subdir-canonify-true/.

This inconsistency definitely looks like a bug to me. I hope it gets fixed.

@bep bep changed the title Document absURL and relURL’s DIFFERENT behaviours with leading / slash Document absURL and relURL’s behaviours with leading / slash May 17, 2018
@bep
Copy link
Member

bep commented May 17, 2018

Not sure what the issue is, but I just wanted to point out that:

  • When canonifyURLs = true, we make absolute URLs out of relative ones from the rendered HTML output
  • Since the above is a stupid search and replace that prepends the baseURL, the output from relURL cannot have any sub-paths in it if this is going to work.

So, whatver you do to verify "correctness", if will have to be the rendered output (and not some debug output of relURL.

Hope that helps.

@anthonyfok
Copy link
Member Author

Thank you for the clarification, @ bep!

Not sure what the issue is...

There are actually a few separate issues that got kind of mixed into one single GitHub issue about clarifying absURL/relURL documentation:

  1. @mjanda's change to absURL (leading / slash) in Hugo 0.16 needs to be documented.

  2. (canonifyURLs = false) relURL did not get the same change about leading / slash (which I just realized today), and we should probably discuss in a new issue over at gohugoio/hugo whether relURL should also drop the baseURL sub-path component like absURL does when given a leading / slash.

  3. relURL's behaviour when canonifyURLs = true, which @kaushalmodi and you clarified. It is again an entirely different issue, which I just realized about an hour ago.

So, yes, it suddenly became a lot more complicated than I thought. (I went dumbfounded... my head sort of exploded.) But your clairification did ease my fear a lot. :-)

Moving forward:

  • We should document the current absURL and relURL behaviours, especially those which catches users by surprise.
  • In the more distant future, should we consider changing relURL's behaviours (regarding points 2 and 3)? [To be discussed]

@bep
Copy link
Member

bep commented May 18, 2018

Also see gohugoio/hugo#4733

@stale
Copy link

stale bot commented Nov 29, 2018

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If you still think this is important, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

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 a pull request may close this issue.

4 participants