summaryrefslogtreecommitdiff
path: root/src/views/posts.rs
blob: 5091059cbc520f119885403de94ee21ff88f01e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::helpers::*;
use crate::posts::abstractions::post::Post;
use askama::Template;

#[derive(Template)]
#[template(path = "posts.html.j2")]
pub struct PostsView<P: Post> {
    posts: Vec<P>,
}

impl<P: Post> PostsView<P> {
    pub fn with_posts(posts: impl IntoIterator<Item = P>) -> Self {
        let mut posts: Vec<P> = posts.into_iter().collect();
        posts.sort();
        posts.reverse();
        Self { posts }
    }
}