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

Deprecate and then rename/remove Page.URL #4117

Open
bep opened this Issue Nov 24, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@bep
Copy link
Member

bep commented Nov 24, 2017

I cannot think of one valid use case for it, and I see it used in the wild all the time when RelPermalik or Permalink is the correct choice.

URL returns the front matter value for regular pages, if set, else it return the RelPermalink.

@bep bep self-assigned this Nov 24, 2017

@bep bep added this to the v0.32 milestone Nov 24, 2017

@bep bep modified the milestones: v0.32, v0.33 Dec 16, 2017

@bep bep modified the milestones: v0.33, v0.34 Jan 11, 2018

@onedrawingperday

This comment has been minimized.

Copy link
Member

onedrawingperday commented Jan 18, 2018

I am not in favor of removing Page.URL.

For example
if eq .URL "/some-url/" provides an easy way to add an active class to page links that live outside Hugo's menu configuration (for various reasons) Also this is handy in cases where it's difficult to do a .Permalink or .RelPermalink check, like in Nested Sections list pages.

But if you really think these are not valid use cases. Go ahead and remove it. I'll look into what can be done to replace its functionality... like I always do...

@Jos512

This comment has been minimized.

Copy link

Jos512 commented Jan 19, 2018

.URL and .Permalink are indeed much the same, although the first returns a string value and the second a template.HTML value. So even though they return the same data, they behave differently:

{{ if in .URL "hugo" }}
...
{{ end }}

{{ if in (.Permalink | string) "hugo" }}
...
{{ end }}

I agree there's some redundancy. And on one hand I think Hugo template code might become easier when there's no two variables that return the same data. But on the other hand the required conversion to string of .Permalink might be more odd to newcomers than two variables are.

That latter might also make explaining how people can update from .URL to .Permalink somewhat confusing. Assuming we use a terminal message for this like Hugo did with previous depreciations. Would a terminal message like this be something people with little knowledge of Go/Hugo understand?

WARN: .URL has been deprecated. Replace .URL with 
.Permalink, but when comparing .Permalink against a 
string, first translate .Permalink to a string value
with the 'string' function.

Even though I wrote this without using programming lingo (like 'casting' or 'type incompatibility'), I still doubt if this is clear enough. (Or should we assume people read the release notes, where this can be explained more fully?)

So to summarise: I don't know what wisdom is for this issue. 😆

@onedrawingperday

This comment has been minimized.

Copy link
Member

onedrawingperday commented Jan 19, 2018

Or should we assume people read the release notes, where this can be explained more fully?

If the recent release of Hugo 0.32 is any indication I would say that people don't bother with the release notes. The forum is full of posts regarding index.md

A Warn like @Jos512 proposes is the way to go.

And possibly an example of the .Permalink translation to a string value, in the Release notes.

You cannot assume that every user of Hugo has used every one of its functions or that he/she knows what to do in advance. Not all of us are from a Dev background.

@bep bep modified the milestones: v0.34, v0.35, v0.36 Jan 22, 2018

@bep bep modified the milestones: v0.36, v0.37 Feb 3, 2018

@bep bep modified the milestones: v0.37, v0.38 Feb 11, 2018

@bep bep modified the milestones: v0.38, v0.39 Feb 21, 2018

@bep bep modified the milestones: v0.39, v0.40 Apr 9, 2018

@bep bep modified the milestones: v0.40, v0.41 Apr 20, 2018

@bep bep modified the milestones: v0.41, v0.42 May 4, 2018

@bep bep modified the milestones: v0.42, v0.43 Jun 5, 2018

@bep bep modified the milestones: v0.43, v0.44 Jun 30, 2018

@bep bep removed this from the v0.44 milestone Jul 10, 2018

@bep bep modified the milestones: v0.45, v0.46 Jul 10, 2018

@onedrawingperday

This comment has been minimized.

Copy link
Member

onedrawingperday commented Jul 26, 2018

{{ if in (.Permalink | string) "hugo" }}

I just want to say that the above approach would not work with .FirstSection list pages because obviously the string is also present in the Nested Sections of that section.

For example let's say that I have a section called /women/ and a nested section called /women/backpacks and I want to have each custom menu entry of these links have a selected class when the user is in their corresponding URL. With the above both menu entries would have the selected class under both URLs.

But thanks to Hugo 0.45.1 and .FirstSection here is how I finally managed to do this.

{{ $currentURL := .Permalink }}
{{ with .FirstSection }}
<a {{ if eq .Permalink $currentURL }}class="selected"{{ end }} href="...">...</a>
{{ end }}

And then for other list pages within that Section I do the following simple check:

{{ if eq .Permalink $currentURL }}class="selected" {{ end }}

So at this point, I am fine with .URL being deprecated from Hugo, since I can have the functionality I need with other simple means.

@bep bep modified the milestones: v0.46, v0.47, v0.48 Aug 3, 2018

@bep bep modified the milestones: v0.48, v0.49 Aug 22, 2018

@bep bep modified the milestones: v0.49, v0.50 Sep 13, 2018

SamWhited added a commit to SamWhited/newsprint that referenced this issue Sep 23, 2018

@bep bep modified the milestones: v0.50, v0.51 Oct 6, 2018

@bep bep modified the milestones: v0.51, v0.53 Nov 8, 2018

@bep bep modified the milestones: v0.53, v0.54 Dec 6, 2018

@bep bep modified the milestones: v0.54, v0.55 Dec 26, 2018

@bep bep modified the milestones: v0.55, v0.56 Feb 1, 2019

@onedrawingperday

This comment has been minimized.

Copy link
Member

onedrawingperday commented Mar 22, 2019

Actually if .Page.URL is deprecated and removed it will break several older themes that are currently in the Hugo Themes showcase.

And that is not a bad thing.

Since it will force theme authors to update their themes or if they don't we can always clean up the showcase from unmaintained themes.

So +1 for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.