diff --git a/src/routes/blog.rs b/src/routes/blog.rs index 271b386..8b11b32 100644 --- a/src/routes/blog.rs +++ b/src/routes/blog.rs @@ -1,4 +1,9 @@ -use ::rss::{Category, Channel, Image, Item}; +use std::{ + collections::hash_map::DefaultHasher, + hash::{Hash, Hasher}, +}; + +use ::rss::{Category, Channel, Guid, Image, Item}; use actix_web::{dev::ConnectionInfo, get, web, HttpRequest, HttpResponse, Responder}; use cached::proc_macro::once; use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc}; @@ -56,6 +61,17 @@ struct Post { desc: Option, } +impl Hash for Post { + fn hash(&self, state: &mut H) { + let blog_dir = "data/blog"; + let ext = ".md"; + + if let Some(file) = read_file(&format!("{blog_dir}/{}{ext}", self.url)) { + file.content.hash(state) + } + } +} + fn get_posts(location: &str) -> Vec { let entries = match std::fs::read_dir(location) { Ok(res) => res @@ -207,6 +223,14 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String { title: Some(p.title.to_owned()), link: Some(format!("{}/blog/p/{}", link_to_site, p.url)), description: p.desc.to_owned(), + guid: Some(Guid { + value: format!("urn:hash:{}", { + let mut hasher = DefaultHasher::new(); + p.hash(&mut hasher); + hasher.finish() + }), + permalink: false, + }), pub_date: Some( NaiveDateTime::parse_from_str( &format!("{}-{}-{} 13:12:00", p.date.day, p.date.month, p.date.year),