hash the post
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-26 14:19:02 +02:00
parent 68ea0fb8a1
commit a97e292565
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -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 actix_web::{dev::ConnectionInfo, get, web, HttpRequest, HttpResponse, Responder};
use cached::proc_macro::once; use cached::proc_macro::once;
use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc}; use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc};
@ -56,6 +61,17 @@ struct Post {
desc: Option<String>, desc: Option<String>,
} }
impl Hash for Post {
fn hash<H: Hasher>(&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<Post> { fn get_posts(location: &str) -> Vec<Post> {
let entries = match std::fs::read_dir(location) { let entries = match std::fs::read_dir(location) {
Ok(res) => res Ok(res) => res
@ -207,6 +223,14 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
title: Some(p.title.to_owned()), title: Some(p.title.to_owned()),
link: Some(format!("{}/blog/p/{}", link_to_site, p.url)), link: Some(format!("{}/blog/p/{}", link_to_site, p.url)),
description: p.desc.to_owned(), 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( pub_date: Some(
NaiveDateTime::parse_from_str( NaiveDateTime::parse_from_str(
&format!("{}-{}-{} 13:12:00", p.date.day, p.date.month, p.date.year), &format!("{}-{}-{} 13:12:00", p.date.day, p.date.month, p.date.year),