remove old svelte web source
This commit is contained in:
17
src/blog_posts/blog_post_model.rs
Normal file
17
src/blog_posts/blog_post_model.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::post_utils::post_parser::deserialize_date;
|
||||
|
||||
pub const BLOG_POST_PATH: &str = "../_posts/blog";
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct BlogPostMetadata {
|
||||
pub title: String,
|
||||
pub segments: Vec<String>,
|
||||
pub published: bool,
|
||||
#[serde(deserialize_with = "deserialize_date")]
|
||||
pub date: DateTime<Utc>,
|
||||
pub thumbnail: Option<String>,
|
||||
pub tags: Vec<String>,
|
||||
}
|
15
src/blog_posts/featured_blog_posts.rs
Normal file
15
src/blog_posts/featured_blog_posts.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use axum::http::StatusCode;
|
||||
|
||||
use crate::post_utils::{post_listing::get_post_list, post_parser::ParseResult};
|
||||
|
||||
use super::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH};
|
||||
|
||||
pub async fn get_featured_blog_posts() -> Result<Vec<ParseResult<BlogPostMetadata>>, StatusCode> {
|
||||
let mut post_list = get_post_list::<BlogPostMetadata>(BLOG_POST_PATH).await?;
|
||||
post_list.retain(|post| post.metadata.segments.contains(&"featured".to_string()));
|
||||
post_list.retain(|post| post.metadata.published);
|
||||
post_list.sort_by_key(|post| post.metadata.date);
|
||||
post_list.reverse();
|
||||
|
||||
Ok(post_list)
|
||||
}
|
3
src/blog_posts/mod.rs
Normal file
3
src/blog_posts/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub mod blog_post_model;
|
||||
pub mod featured_blog_posts;
|
||||
pub mod tag_list;
|
38
src/blog_posts/tag_list.rs
Normal file
38
src/blog_posts/tag_list.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use axum::http::StatusCode;
|
||||
use std::collections::HashMap;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::{
|
||||
blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH},
|
||||
post_utils::post_listing::get_post_list,
|
||||
};
|
||||
|
||||
pub async fn get_popular_blog_tags() -> Result<Vec<String>, StatusCode> {
|
||||
const TAGS_LENGTH: usize = 7;
|
||||
|
||||
let post_list = get_post_list::<BlogPostMetadata>(BLOG_POST_PATH).await?;
|
||||
let tags_sum = post_list
|
||||
.into_iter()
|
||||
.flat_map(|post| post.metadata.tags)
|
||||
.fold(HashMap::new(), |mut acc, tag| {
|
||||
*acc.entry(tag).or_insert(0) += 1;
|
||||
acc
|
||||
});
|
||||
|
||||
let mut sorted_tags_by_count: Vec<_> = tags_sum.into_iter().collect();
|
||||
sorted_tags_by_count.sort_by_key(|&(_, count)| std::cmp::Reverse(count));
|
||||
|
||||
// Log the counts
|
||||
for (tag, count) in &sorted_tags_by_count {
|
||||
debug!("Tag: {}, Count: {}", tag, count);
|
||||
}
|
||||
|
||||
let popular_blog_tags = sorted_tags_by_count
|
||||
.into_iter()
|
||||
.map(|tag_count| tag_count.0)
|
||||
.filter(|tag| tag != "dev")
|
||||
.take(TAGS_LENGTH)
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Ok(popular_blog_tags)
|
||||
}
|
Reference in New Issue
Block a user