This commit is contained in:
parent
68ea0fb8a1
commit
a97e292565
1 changed files with 25 additions and 1 deletions
|
@ -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<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> {
|
||||
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),
|
||||
|
|
Loading…
Reference in a new issue