Skip to content

Commit

Permalink
rss: add <pubDate> field, fixes #356 (#358)
Browse files Browse the repository at this point in the history
* rss: add <pubDate> field, fixes #356

* rss: also add pub_date on user feed

* fix(fmt)

---------

Co-authored-by: Matthew Esposito <[email protected]>
  • Loading branch information
martinlindhe and sigaloid authored Feb 3, 2025
1 parent adf25cb commit fd1c32f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ common-words-all = { version = "0.0.2", default-features = false, features = ["e
hyper-rustls = { version = "0.24.2", features = [ "http2" ] }
tegen = "0.1.4"
serde_urlencoded = "0.7.1"
chrono = { version = "0.4.39", default-features = false, features = [ "std" ] }
htmlescape = "0.3.1"


Expand Down
2 changes: 2 additions & 0 deletions src/subreddit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
})
Expand Down

0 comments on commit fd1c32f

Please sign in to comment.