From 909c28050ad0dc0ac7f5a4377930f354901dc799 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Sun, 18 Feb 2024 15:56:22 +0100 Subject: [PATCH] Add order by --- data_src/posts/kde_contribution.md | 4 +- data_src/posts/test.md | 78 ------------------------------ src/app/models/mod.rs | 12 +++-- src/app/models/post.rs | 2 +- 4 files changed, 10 insertions(+), 86 deletions(-) delete mode 100644 data_src/posts/test.md diff --git a/data_src/posts/kde_contribution.md b/data_src/posts/kde_contribution.md index ddab172..08dae0c 100644 --- a/data_src/posts/kde_contribution.md +++ b/data_src/posts/kde_contribution.md @@ -1,8 +1,8 @@ --- -image_path: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Test-Logo.svg/783px-Test-Logo.svg.png?20150906031702" +image_path: "https://community.kde.org/images.community/thumb/a/af/Mascot_konqi-base-plasma.png/250px-Mascot_konqi-base-plasma.png" slug: kde_first_conf title: Mes premières contributions à KDE -date: 2023-11-26T00:00:00Z +date: 2024-01-12T00:00:00Z description: Ma première configuration et ma première contribution à l'environnement mobile (Plasma-Mobile). project_link: none draft: true diff --git a/data_src/posts/test.md b/data_src/posts/test.md deleted file mode 100644 index f2ee268..0000000 --- a/data_src/posts/test.md +++ /dev/null @@ -1,78 +0,0 @@ ---- -image_path: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Test-Logo.svg/783px-Test-Logo.svg.png?20150906031702" -slug: test_layout -title: Testing layout -date: 2023-11-26T00:00:00Z -description: Testing the layout of the site. -project_link: none -draft: true -tags: - - test ---- - -# Heading 1 -## Heading 2 -### Heading 3 -#### Heading 4 -##### Heading 5 -###### Heading 6 - -This is a paragraph tag. It's used `for` displaying text content. - -[Click me to visit Example website!](https://www.example.com) - -Unordered list - -* Item 1 -* Item 2 -* Item 3 - -Ordered list - -1. Item 1 -2. Item 2 -3. Item 3 - - -> It's probably important that images look okay here by default as well: - - - -### Code Blocks - -```python -def hello_world(): - print("Hello World!") -``` - -```rust -fn main() { - println!("Hello World!"); -} -``` - -```javascript -function helloWorld() { - console.log("Hello World!"); -} -``` - -```ruby -def hello_world - puts "Hello World!" -end -``` - -```dockerfile -FROM rust -RUN cargo build --release -CMD ["./target/release/hello_world"] -``` - -```mermaid -graph TD; - A-->B; - A-->C; - B-->D; - C-->D; -``` \ No newline at end of file diff --git a/src/app/models/mod.rs b/src/app/models/mod.rs index bc89fad..9d95d2e 100644 --- a/src/app/models/mod.rs +++ b/src/app/models/mod.rs @@ -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 { - let posts = crate::app::utils::data_src::get_all::("posts")? - .into_iter() + let mut posts = crate::app::utils::data_src::get_all::("posts")?; + posts.sort_by(|post, post2| post2.metadata.date.cmp(&post.metadata.date)); + + let posts = posts.into_iter() .map(Arc::new) .collect::>(); @@ -47,4 +47,6 @@ cfg_if::cfg_if! { } -} \ No newline at end of file +} + +pub use post::{Post, PostMetadata}; diff --git a/src/app/models/post.rs b/src/app/models/post.rs index 348f6b0..b7a8fa9 100644 --- a/src/app/models/post.rs +++ b/src/app/models/post.rs @@ -38,7 +38,7 @@ cfg_if::cfg_if! { let matter = Matter::::new(); let mut post_data = matter .parse_with_struct::(&content) - .ok_or_else(|| PostDeserializationError::InvalidFrontMatter)?; + .ok_or(PostDeserializationError::InvalidFrontMatter)?; let content = post_data.content;