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

Clarify the difference in behavior of Site vs Page GetPage #546

Closed
kaushalmodi opened this issue Jul 26, 2018 · 8 comments · Fixed by #2296
Closed

Clarify the difference in behavior of Site vs Page GetPage #546

kaushalmodi opened this issue Jul 26, 2018 · 8 comments · Fixed by #2296

Comments

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Jul 26, 2018

For a path like /foo/bar/abc.md, .Site.GetPage "abc" will work (assuming that the "abc" name is unique in the whole site).

But given that the /foo page context is stored in $foo, $foo.GetPage "abc" is not expected to always? work.

The Page version of GetPage expects either an absolute path (starting with /) or a valid relative path from the current context. It is not designed to do a "lookup" anywhere in the given context.

This distinction needs to be made explicit in the docs.

@bep
Copy link
Member

bep commented Jul 26, 2018

But given that the /foo page context is stored in $foo, $foo.GetPage "abc" is not expected to always? work.

I'm not sure I follow (and please don't ask me to read the thred on the forum):

  • Given that "abc" is unique, then
    • .Site.GetPage "abc"
    • $foo.GetPage "abc"

Should return the same Page. If abc is not found relative to $foo we currently print a warning about using /abc instead. But it should be found and returned?

@kaushalmodi
Copy link
Contributor Author

@bep I have committed a very light weight reproducible example at https://gitlab.com/hugo-mwe/hugodocs-issue-546. See the "But this fails!" section in the layout file.

@bep
Copy link
Member

bep commented Jul 26, 2018

OK, then I misunderstood the problem -- "post-1" is not unique.

Maybe in that page context, as you say it, but that is not how this works.

@kaushalmodi
Copy link
Contributor Author

kaushalmodi commented Jul 26, 2018

but that is not how this works

I now realize that it's not how this works. But it's not intuitive given that .Page.GetPage works on a Page object.. it shouldn't be confused with similar named pages outside that Page object context.

So it should be explicitly documented that the arg to .Page.GetPage should be relative references directly from the input page object argument or absolute links. While .Site.GetPage style lookups work, they are not guaranteed as the "ambiguity error" is triggered from the context of the whole site.

@bep
Copy link
Member

bep commented Jul 26, 2018

But it's not intuitive given that .Page.GetPage works on a Page object.. it shouldn't be confused with similar named pages outside that Page object context.

That argument could be had and a possible improvement (possibly expensive): But I think it helps to think about Page.GetPage as also supporting relative paths. .GetPage "mypage.md" (assuming it is in the root folder of that branch bundle) is plenty more portable than .Site.GetPage "/mybundle/mypage.md"`.

@kaushalmodi
Copy link
Contributor Author

But I think it helps to think about Page.GetPage as also supporting relative paths.

I am not denying the utility of the new function. Also I don't suggest adding this feature ASAP.. (it would be awesome if the long standing bugs like Next/Previous and NextInSection/PrevInSection get love before addition of more new features :)).

I opened this issue in HugoDocs just so that this nuance of the context when calculating the ambiguity is properly documented (i.e. the .Site context is used for ambiguity detection whether .Site.GetPage or .Page.GetPage is used).

@kaushalmodi
Copy link
Contributor Author

@bep Actually turns out that the "Page context" association with .Page.GetPage is completely misleading..

This works! .. even though the post-2 is not inside /posts/bar at all:

├── content/
│  └── posts/
│     ├── bar/
│     │  ├── _index.md
│     │  └── x/
│     │     ├── _index.md
│     │     └── post-1.md
│     └── foo/
│        ├── _index.md
│        └── x/
│           ├── _index.md
│           ├── post-1.md
│           └── post-2.md
        {{ with .Site.GetPage "/posts/bar" }}
            {{ with .GetPage "post-2" }}
                {{ printf "Title of a post-2 post anywhere in Site: %s" .Title }}<br />
            {{ end }}
        {{ end }}

So.. for $page.GetPage "<path>":

  • If <path> begins with / look for that exact path in site root
  • Else if <path> exists relative to $page, consider that as a relative path
  • Else behave like .Site.GetPage "<path>" (and this last "else" condition gives that ambiguity error).

@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.

@stale stale bot added the Stale label Nov 29, 2018
@stale stale bot removed the Stale label Dec 6, 2018
@jmooring jmooring removed the Keep label Dec 6, 2021
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 15, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 16, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 19, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 19, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 20, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 24, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 27, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Oct 30, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 1, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 2, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 2, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 2, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 2, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 2, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 2, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 3, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 3, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 3, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 3, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 4, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 4, 2023
jmooring added a commit to jmooring/hugo-docs that referenced this issue Nov 5, 2023
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.

3 participants