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

search.pages() and search.page() should return the data object instead of the full Page instance. #251

Closed
oscarotero opened this issue Sep 1, 2022 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@oscarotero
Copy link
Member

This makes working with pages easier. For example, instead of this:

{% for article in search.pages("type=article", "date=desc") %} 
<a href="{{ article.data.url }}">
  <h1>{{ article.data.title }}</h1>
</a>
{% endfor %}

It would become to this:

{% for article in search.pages("type=article", "date=desc") %} 
<a href="{{ article.url }}">
  <h1>{{ article.title }}</h1>
</a>
{% endfor %}

If it's necesary to access to the Page instance (to get the src data, for example) it's available at data.page. Example:

{% for article in search.pages("type=article", "date=desc") %} 
<a href="{{ article.url }}">
  <h1>{{ article.title }}</h1>
  Loaded from {{ article.page.src.path }}
</a>
{% endfor %}

Due this is a breaking change, it will be in Lume 2.0.

@oscarotero oscarotero added the enhancement New feature or request label Sep 1, 2022
@oscarotero oscarotero added this to the 2.0.0 milestone Sep 1, 2022
@oscarotero oscarotero changed the title search.pages() and search.page() should return the data object instead of the full page object. search.pages() and search.page() should return the data object instead of the full Page instance. Sep 1, 2022
@naiyerasif
Copy link
Contributor

I like this but aren't the functions search.pages() and search.page() signalling that the return type would be a Page (at least from naming perspective)?

For data, I'd say, there should be search.data() which can return Array<Data> | Data depending on filter. If we choose to add search.data(), we can bring it in 1.x by deprecating search.pages() and search.page().

@oscarotero
Copy link
Member Author

search.data() already exits and returns the data associated to a file or directory. For example search.data("/") returns the data associated to the root directory (the _data files/folders), and search.data("/post/first-post.md") the data associated to this specific page.

In Lume 1.11, I've added the data filter as a temporary solution, so it's possible to do the following:

{% for article in search.pages("type=article", "date=desc") | data %} 
<a href="{{ article.url }}">
  <h1>{{ article.title }}</h1>
  Loaded from {{ article.page.src.path }}
</a>
{% endfor %}

But I think the Page instance is something internal, a implementation detail that users working with templates shouldn't need to know.

@paulrobertlloyd
Copy link
Contributor

Might it be possible to enable this behaviour in v1.0 via an option in the plugin’s config?

@oscarotero
Copy link
Member Author

Yes, it's a good idea.

@oscarotero
Copy link
Member Author

Implemented in v2 branch #446

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

No branches or pull requests

3 participants