add atom compliance
All checks were successful
ci/woodpecker/push/publish Pipeline was successful

This commit is contained in:
Mylloon 2023-04-26 16:51:19 +02:00
parent 5400166c2e
commit fddef30bad
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 20 additions and 4 deletions

View file

@ -24,4 +24,4 @@ comrak = "0.18"
reqwest = { version = "0.11", features = ["json"] } reqwest = { version = "0.11", features = ["json"] }
chrono = "0.4.24" chrono = "0.4.24"
chrono-tz = "0.8" chrono-tz = "0.8"
rss = "2.0" rss = { version = "2.0", features = ["atom"] }

View file

@ -3,7 +3,10 @@ use std::{
hash::{Hash, Hasher}, 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 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};
@ -20,6 +23,8 @@ use crate::{
template::Infos, template::Infos,
}; };
const MIME_TYPE: &str = "application/rss+xml";
#[get("/blog")] #[get("/blog")]
pub async fn index(config: web::Data<Config>) -> impl Responder { pub async fn index(config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(build_index(config.get_ref().to_owned())) HttpResponse::Ok().body(build_index(config.get_ref().to_owned()))
@ -174,7 +179,7 @@ fn get_post(post: &mut Option<File>, filename: String) -> Infos {
#[get("/blog/rss")] #[get("/blog/rss")]
pub async fn rss(req: HttpRequest, config: web::Data<Config>) -> impl Responder { pub async fn rss(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok() HttpResponse::Ok()
.append_header(("content-type", "application/rss+xml")) .append_header(("content-type", MIME_TYPE))
.body(build_rss( .body(build_rss(
config.get_ref().to_owned(), config.get_ref().to_owned(),
req.connection_info().to_owned(), req.connection_info().to_owned(),
@ -202,11 +207,12 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
None None
}; };
let title = "Blog d'Anri"; let title = "Blog d'Anri";
let lang = "fr";
let channel = Channel { let channel = Channel {
title: title.to_owned(), title: title.to_owned(),
link: link_to_site.to_owned(), link: link_to_site.to_owned(),
description: "Un fil qui parle d'informatique notamment".into(), description: "Un fil qui parle d'informatique notamment".into(),
language: Some("fr".into()), language: Some(lang.into()),
managing_editor: author.to_owned(), managing_editor: author.to_owned(),
webmaster: author, webmaster: author,
pub_date: Some(Local::now().to_rfc2822()), pub_date: Some(Local::now().to_rfc2822()),
@ -252,6 +258,16 @@ fn build_rss(config: Config, info: ConnectionInfo) -> String {
..Item::default() ..Item::default()
}) })
.collect(), .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() ..Channel::default()
}; };