subreddit-created-date #19

Merged
Ayaka merged 1 commits from subreddit-created-date into main 2025-01-13 14:44:16 +13:00
4 changed files with 16 additions and 7 deletions
Showing only changes of commit 49afd83ad3 - Show all commits

View File

@ -12,7 +12,8 @@ use rinja::Template;
use once_cell::sync::Lazy;
use regex::Regex;
use time::{Duration, OffsetDateTime};
use time::{Duration, OffsetDateTime,macros::format_description};
use log::trace;
// STRUCTS
@ -467,6 +468,10 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
// Metadata regarding the subreddit
let members: i64 = res["data"]["subscribers"].as_u64().unwrap_or_default() as i64;
let active: i64 = res["data"]["accounts_active"].as_u64().unwrap_or_default() as i64;
// Grab creation date as unix timestamp
let created_unix = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64;
let created = OffsetDateTime::from_unix_timestamp(created_unix).unwrap_or(OffsetDateTime::UNIX_EPOCH);
// Fetch subreddit icon either from the community_icon or icon_img value
let community_icon: &str = res["data"]["community_icon"].as_str().unwrap_or_default();
@ -481,6 +486,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
icon: format_url(&icon),
members: format_num(members),
active: format_num(active),
created: created.format(format_description!("[month repr:short] [day] '[year repr:last_two]")).unwrap_or_default(),
wiki: res["data"]["wiki_enabled"].as_bool().unwrap_or_default(),
nsfw: res["data"]["over18"].as_bool().unwrap_or_default(),
})

View File

@ -587,6 +587,7 @@ pub struct Subreddit {
pub icon: String,
pub members: (String, String),
pub active: (String, String),
pub created: String,
pub wiki: bool,
pub nsfw: bool,
}

View File

@ -531,11 +531,14 @@ aside {
grid-template-columns: auto 4fr 1fr;
}
#user_details,
#sub_details {
#user_details {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
#sub_details {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
@media screen and (max-width: 279px) {
#sub_actions { display: unset; }
}
@ -547,13 +550,9 @@ aside {
/* Subscriptions */
#sub_subscription,
#user_subscription,
#sub_filter,
#user_filter,
#sub_quicklist,
#user_quicklist,
#sub_rss,
#user_rss {
margin-top: 20px;
}

View File

@ -120,9 +120,12 @@
<div id="sub_details">
<label>Members</label>
<label>Active</label>
<label>Created</label>
<div title="{{ sub.members.1 }}">{{ sub.members.0 }}</div>
<div title="{{ sub.active.1 }}">{{ sub.active.0 }}</div>
<div>{{ sub.created }}</div>
</div>
<hr>
<div id="sub_actions">
<div id="sub_subscription">
{% if prefs.subscriptions.contains(sub.name) %}