Jekyll - Can't reverse sort by date - jekyll

I'm trying to sort the 3 most recent, 'featured' posts only on my blog, but the for loop I currently have won't let me sort the collection to show the most recent posts first.
What I have below outputs the three most recent posts on my blog, but ignores the where_exp and displays both featured and non-featured posts.
If I remove the 'reverse' filter after the sort by date it will only sort featured posts, but sorts them oldest to newest. I've tried reassigning the featured-posts variable to sort by reverse-date again before the for loop but it doesn't work.
Everything I've tried so far won't let me display the three most recent, featured posts in my site, I'm hoping someone can tell me where I'm going wrong..
Post Front matter:
---
post_date: 2017-08-14 00:00:00
featured: true
---
Page For-Loop:
{% assign sorted-posts = site.posts | sort: 'post_date' | reverse %}
{% assign featured-posts = sorted-posts | where_exp:"post","post.featured" %}
{% for post in featured-posts limit:3 %}
<h2>{{ post.title | truncate: 58 }}</h2>
{% endfor %}
Output:
Three most recent posts on the website regardless of whether they're 'featured' or not.
Thanks in advance

Solved by upgrading Jekyll. I was running version 3.0.0, upgraded to 3.5.2 and the issue has been resolved.

Related

How to sort posts by modified date when using pagination?

I add a 'modified' date to my posts and make them sorted from new to old by modified date instead of posted date. Make people notice the update of posts.
I have ymal for posts , like this:
---
title: Mytitle
posted: 2020-06-29
modified: 2020-07-29
....
And the following code works well:
{% assign my_sorted_list = site.posts | sort:"modified" %}
{% for post in my_sorted_list %}
...
{% endfor %}
But when I turn on the jekyll-paginate in my _config.yml, it is sorted by the posted date again.
Is there any way I can sort by modified date when I turn on the pagination? I have tried a few methods but nothing seems to work. Please help!
I suppose this function is not supported. Because I found this pull request. This request aims to that paginator can sort posts by modified date. And this request is not merged yet.

How do make it so that every time the incremental load in dbt runs it just updates the new rows from when it last ran?

How do make it so that every time the incremental load in dbt runs it just updates the new rows from when it last ran?
{% if is_incremental() %}
/* code */
{% endif %}
Your two main resources for doing this are going to be in the dbt docs already:
How to build incremental models in dbt:
https://docs.getdbt.com/docs/building-a-dbt-project/building-models/configuring-incremental-models/
Incremental models particular to bigquery:
https://docs.getdbt.com/reference/resource-configs/bigquery-configs/#merge-behavior-incremental-models
Most likely the model will look something like:
{{
config(
materialized='incremental'
)
}}
select <columns>
from <my_table>
{% if is_incremental() %}
where <my_table>.<record_update_timestamp> >= (
select max(<my_table>.<record_update_timestamp>) from {{ this }}
)
{% endif %}
Full example in from docs in:
https://docs.getdbt.com/docs/building-a-dbt-project/building-models/configuring-incremental-models/#defining-a-uniqueness-constraint-optional

Custom comparator for sorting arrays in Liquid or Jekyll

I am trying to set up a blog in Jekyll. Some (not all) of my posts have updated_on variable in its front matter which I use to store the date (YYYY-MM-DD HH:MM:SS +0530) it was last updated on.
I wish to display the posts on my index page in the decreasing order of post.updated_on if available, otherwise using post.date. To make things clear, here is pseudo-code of what I want my sort comparator to work like
comp(post a, post b){
if(a.updated_on) t1 = a.updated_on
else t1 = a.date
if(b.updated_on) t2 = b.updated_on
else t2 = b.date
return t1>t2
}
How can I achieve this kind of sorting in Liquid/Jekyll?
One fallback I have thought is to add updated_on in every post even if it was never updated since post date. Then I could do something like
{% assign sorted_posts = paginator.posts | sort: 'updated_on' | reverse %}
{% for post in sorted_posts %}
... some code here ...
{% endfor %}
But I don't want to go this way since I will have to manually add updated_on to each post where it doesn't already exists.

Liquid Tag in Where Filter in Jekyll

The following:
{% assign devices = site.data.equipment | where:"department","sound" | group_by:"servicelocation" %}
Is helping me build a list of sound devices from the equipment data list, grouped by location. The file resides in the _includes folder and is entitled equipment_list.html.
When I include this file in a _page, it displays exactly what I need, but I am attempting to take it one step further.
{% assign departmentname = page.name | remove:"equipment_list_" | remove:".md" %} yields the word sound based upon the _page/equipment_list_sound.md file.
{{ departmentname }} = "sound" as expected.
Can I insert this value into the where filter somehow to be able to re-use the equipment list page over and over again for different departments?
where:"department","{{departmentname}}" fails, and any variation I can imagine also fails. Is it possible?
You can use : {% assign devices = site.data.equipment | where:"department", departmentname | group_by:"servicelocation" %}

Fetch currently logged in user relation with a given model instance

Assume we have a model called Author as such:
class Author(models.Model):
name = models.CharField(max_length=250)
We also have a feature which enables users to follow a certain author:
class UserFollow(models.Model):
author = models.ForeignKey(Author)
user = models.ForeignKey(User)
If you have a button in your UI that enables logged in users to follow / unfollow these authors. One way to check if this user is already following a certain author is to make a query on the existence of a record in UserFollow. However, when you're fetching a list of 10 / 20 .. etc authors, how would you check each author for the currently logged in user?
The usual approach would result in +X number of extra queries depending on how many items you're loading per page. Is there a more efficient way to achieve the same effect?
Thanks in advance
you can fetch all instances of UserFollow in view, pass it as a variable to the template and then you can check if given author is in this list
def my_view(request):
following = list(UserFollow.objects.filter(user=request.user))
template_context = {
'following': following
}
template:
{% for author in authors %}
{% if author in following %}
{# do some magic #}
{% endif %}
{% endfor %}