rss: add <pubDate> field, fixes #356 (#358)

* rss: add <pubDate> field, fixes #356

* rss: also add pub_date on user feed

* fix(fmt)

---------

Co-authored-by: Matthew Esposito <matt@matthew.science>
This commit is contained in:
Martin Lindhe 2025-02-03 04:00:44 +01:00 committed by GitHub
parent adf25cb15b
commit fd1c32f555
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 2 deletions

View file

@ -11,6 +11,7 @@ use hyper::{Body, Request, Response};
use log::{debug, trace};
use rinja::Template;
use chrono::DateTime;
use once_cell::sync::Lazy;
use regex::Regex;
use time::{Duration, OffsetDateTime};
@ -607,6 +608,7 @@ pub async fn rss(req: Request<Body>) -> Result<Response<Body>, String> {
link: Some(utils::get_post_url(&post)),
author: Some(post.author.name),
content: Some(rewrite_urls(&post.body)),
pub_date: Some(DateTime::from_timestamp(post.created_ts as i64, 0).unwrap_or_default().to_rfc2822()),
description: Some(format!(
"<a href='{}{}'>Comments</a>",
config::get_setting("REDLIB_FULL_URL").unwrap_or_default(),

View file

@ -5,6 +5,7 @@ use crate::client::json;
use crate::server::RequestExt;
use crate::utils::{error, filter_posts, format_url, get_filters, nsfw_landing, param, setting, template, Post, Preferences, User};
use crate::{config, utils};
use chrono::DateTime;
use hyper::{Body, Request, Response};
use rinja::Template;
use time::{macros::format_description, OffsetDateTime};
@ -165,6 +166,7 @@ pub async fn rss(req: Request<Body>) -> Result<Response<Body>, String> {
title: Some(post.title.to_string()),
link: Some(utils::get_post_url(&post)),
author: Some(post.author.name),
pub_date: Some(DateTime::from_timestamp(post.created_ts as i64, 0).unwrap_or_default().to_rfc2822()),
content: Some(rewrite_urls(&post.body)),
..Default::default()
})