-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Introduce before and after filters
#3017
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
base: next
Are you sure you want to change the base?
Conversation
|
With I figured it would be somewhat useful when honing in on a particular month or particular year:
|
|
How about adding |
| Filters an array of pages/sections to keep only items with a `date` field on or after the specified date. Items without a `date` field are excluded. | ||
|
|
||
| ```jinja2 | ||
| {% for page in section.pages | after(date="2020-03-10") %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking at the usage, I'm wondering if it would be better to have the before/after work on a date rather than Page[]. It would be usable in more places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a bit peculiar to have that filter work on an array of items that have a date property, that's pretty arbitrary.
To clarify you suggest we have some after and before filters that yield either true or false when they're used on a date, that we'd use like:
{% for page in section.pages %}
{% if page.date | before(date="2025-01-01") %} {% continue %} {% endif %}
{{ page.content | markdown | safe }}
{% endfor %}Correct?
If so, that makes sense as well, I can do that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't suppose it'd make sense to have it run on BOTH OF Page[]/Section[] and date, right? It'd be somewhat neat to have a filter that directly eliminates stuff from an array, I quite like the section.pages | after(xxx) construct.
But supporting both if page.date | before(xxx) and for page in section.page | before(xxx) is semantically overloaded, I believe.
It's very, very easy to implement and maintain, however ;)
I'll go ahead and assume you'd rather want only the:
{% if page.date | before(date="2025-01-01") %}
We can always revert that commit later anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to work on a date rather than on a page/section. I think for that it will be better to design an improved filter filter for tera2 so you can apply a filter on every elements of a collection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hell yeah, a filter filter would be awesome :)
In the meantime, I went ahead and made the adjustments you requested. This approach will definitely be perfect once the filter filter is available, and it's already still quite useable.
Let me know how you want to proceed from here!
Ha! Yeah, seems obvious in retrospect. I'll do just that (tonight). |
|
Hey @Keats, I addressed your comments, do you think it makes sense to merge this as it now is? |
f6557c7 to
2bfec1a
Compare
Fixes getzola#2619. - The "before" filter is exclusive, and the "after" one is inclusive; it may be better thought of as a "since" than a strict "after". - Pages with no dates are never included. - Dates can be 8601 default, like: 2023-12-01T12:00:00Z or only have the date component, like: 2023-12-01 Ref: getzola#2619
Change the default inclusiveness of "after" to be *false*, so that both behave the same: exclusive by default, inclusive only if specifically marked as such. Suggested-by: Vincent Prouillet <[email protected]>
Suggested-by: Vincent Prouillet <[email protected]>
2bfec1a to
6f72b54
Compare
|
I've just realised, these shouldn't be filters but tests |
|
Ah, like |
|
Yes exactly, it's basically a shorthand for a function returning a bool |
nextbranch?Fixes #2619.
may be better thought of as a "since" than a strict "after".
or only have the date component, like: 2023-12-01