I am updating my theme because of this deprecation warning: WARN Page's .UniqueID is deprecated and will be removed in a future release. Use .File.UniqueID.
Therefore I replaced all the .Page.UniqueID with .File.UniqueID and that works except for a where clause that lists the last 3 posts except the one that is currently shown:
{{ $pages := .Site.Pages }}
{{ with .File }}
{{ $files := where $pages ".File" "!=" nil }}
{{ $recent := where $files ".File.UniqueID" "!=" .UniqueID }}
{{ $.Scratch.Set "recentPosts" $recent }}
{{ end }}
For the where it now shows: WARN 2019/07/09 12:43:23 .File.UniqueID on zero object. Wrap it in if or with: {{ with .File }}{{ .UniqueID }}{{ end }}
If I understand it correctly, the first where should filter out all zero objects, right?
If you use with .File then everything INSIDE of the loop is .File based. Meaning there is no .File.UniqueID because it is .UniqueID, with the dot being the .File reference from the with.
This line {{ $recent := where $files ".File.UniqueID" "!=" .UniqueID }} probably did check if the currently ranged post is already shown on the currently shown page. And that’s not possible this way, because the .Page's .UniqueID is obsoleted.
If you can give more detail on what it was supposed to do we can dive deeper in how to achieve it. For now, the part that throws the error is ".File.UniqueID" because that at this location is .File.File.UniqueID.
On a second look, just remove the .File from the .UniqueID, because that one is relative to he files in $files I believe. That should not display the warning then.
Making it relative makes it worse because then it falls back to the page collection and gives this deprecation warning: WARN 2019/07/09 14:28:15 Page's .UniqueID is deprecated and will be removed in a future release. Use .File.UniqueID.
Context: I use the recent post collection in the sidebar of my blog (https://melcher.dev) to show the recent 3 posts. If one of the recent three posts is shown right now, I exclude that from the recent posts to not show them twice…
Let me try on my own blog and get back to you. The way I see it you can’t use UniqueID anymore to make this determination. Using .Title might do the trick - it might not come up too often that your posts identical titles.
It works - but it will be deprecated. The last .UniqueID is referencing the .Page context, right?
Does not work for me.
Again, the last .UniqueID is referencing the .Page context - and that gives me: Page's .UniqueID is deprecated and will be removed in a future release. Use .File.UniqueID.
I totally forgot that: I had the issue before and the way to use file within a page object is .Page.File.Variable. So this works without warning (already finished up to fit into my site):
Thanks yall for testing that. In hindsight it makes sense why it would return no pages, since the comparison is comparing the page to itself. So it’d need to updated to compare against an individual page, so doing a site.GetPage "foo" beforehand
Live with the warning for some days (it’s a warning, not an error ;). I tried to test my idea from earlier to use .Title instead of .UniqueID and that does not work. I will find a way - having the same problem. I will be out of IT-equipment for a day or two, so bear with me.
<!-- though using 'where' here is probably redundant;
$pages := .Site.RegularPages should be fine
-->
{{ $pages := where .Site.RegularPages ".File.UniqueID" "!=" "nil" }}
{{ with .File }}
{{ $recent := where $pages ".File.UniqueID" "!=" .UniqueID }}
{{ $.Scratch.Set "recentPosts" $recent }}
{{ end }}
If you only wanted to exclude the current page from the selection though: