Add order by

This commit is contained in:
Florian RICHER 2024-02-18 15:56:22 +01:00
parent 1377be120e
commit 909c28050a
4 changed files with 10 additions and 86 deletions

View file

@ -1,7 +1,5 @@
mod post;
pub use post::{Post, PostMetadata};
cfg_if::cfg_if! {
if #[cfg(feature = "ssr")] {
use std::collections::HashMap;
@ -16,8 +14,10 @@ cfg_if::cfg_if! {
impl Data {
#[allow(dead_code)] // Use in main.rs
pub fn new() -> anyhow::Result<Self> {
let posts = crate::app::utils::data_src::get_all::<Post>("posts")?
.into_iter()
let mut posts = crate::app::utils::data_src::get_all::<Post>("posts")?;
posts.sort_by(|post, post2| post2.metadata.date.cmp(&post.metadata.date));
let posts = posts.into_iter()
.map(Arc::new)
.collect::<Vec<_>>();
@ -47,4 +47,6 @@ cfg_if::cfg_if! {
}
}
}
pub use post::{Post, PostMetadata};

View file

@ -38,7 +38,7 @@ cfg_if::cfg_if! {
let matter = Matter::<YAML>::new();
let mut post_data = matter
.parse_with_struct::<PostMetadata>(&content)
.ok_or_else(|| PostDeserializationError::InvalidFrontMatter)?;
.ok_or(PostDeserializationError::InvalidFrontMatter)?;
let content = post_data.content;