diff --git a/Cargo.toml b/Cargo.toml index 376979b..4ed14bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,4 @@ comrak = "0.18" reqwest = { version = "0.11", features = ["json"] } chrono = "0.4.24" chrono-tz = "0.8" -rss = "2.0" +rss = { version = "2.0", features = ["atom"] } diff --git a/src/routes/blog.rs b/src/routes/blog.rs index be0f4f0..c62a271 100644 --- a/src/routes/blog.rs +++ b/src/routes/blog.rs @@ -3,7 +3,10 @@ use std::{ hash::{Hash, Hasher}, }; -use ::rss::{Category, Channel, Guid, Image, Item}; +use ::rss::{ + extension::atom::{AtomExtension, Link}, + 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}; @@ -20,6 +23,8 @@ use crate::{ template::Infos, }; +const MIME_TYPE: &str = "application/rss+xml"; + #[get("/blog")] pub async fn index(config: web::Data) -> impl Responder { HttpResponse::Ok().body(build_index(config.get_ref().to_owned())) @@ -174,7 +179,7 @@ fn get_post(post: &mut Option, filename: String) -> Infos { #[get("/blog/rss")] pub async fn rss(req: HttpRequest, config: web::Data) -> impl Responder { HttpResponse::Ok() - .append_header(("content-type", "application/rss+xml")) + .append_header(("content-type", MIME_TYPE)) .body(build_rss( config.get_ref().to_owned(), req.connection_info().to_owned(), @@ -202,11 +207,12 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String { None }; let title = "Blog d'Anri"; + let lang = "fr"; let channel = Channel { title: title.to_owned(), link: link_to_site.to_owned(), description: "Un fil qui parle d'informatique notamment".into(), - language: Some("fr".into()), + language: Some(lang.into()), managing_editor: author.to_owned(), webmaster: author, pub_date: Some(Local::now().to_rfc2822()), @@ -252,6 +258,16 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String { ..Item::default() }) .collect(), + atom_ext: Some(AtomExtension { + links: vec![Link { + href: format!("{}/blog/rss", link_to_site), + rel: "self".into(), + hreflang: Some(lang.into()), + mime_type: Some(MIME_TYPE.into()), + title: Some(title.to_owned()), + length: None, + }], + }), ..Channel::default() };