Stickied Posts
This commit is contained in:
parent
f65ee2eb6a
commit
aa9aad6743
@ -1,5 +1,5 @@
|
|||||||
// CRATES
|
// CRATES
|
||||||
use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Params, Post};
|
use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Flags, Params, Post};
|
||||||
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
||||||
|
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
@ -130,7 +130,10 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
|||||||
"white".to_string()
|
"white".to_string()
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
flags: Flags {
|
||||||
nsfw: post_data["data"]["over_18"].as_bool().unwrap_or(false),
|
nsfw: post_data["data"]["over_18"].as_bool().unwrap_or(false),
|
||||||
|
stickied: post_data["data"]["stickied"].as_bool().unwrap_or(false)
|
||||||
|
},
|
||||||
media: media.1,
|
media: media.1,
|
||||||
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
||||||
};
|
};
|
||||||
|
10
src/utils.rs
10
src/utils.rs
@ -13,6 +13,11 @@ use base64::encode;
|
|||||||
//
|
//
|
||||||
// Post flair with text, background color and foreground color
|
// Post flair with text, background color and foreground color
|
||||||
pub struct Flair(pub String, pub String, pub String);
|
pub struct Flair(pub String, pub String, pub String);
|
||||||
|
// Post flags with nsfw and stickied
|
||||||
|
pub struct Flags {
|
||||||
|
pub nsfw: bool,
|
||||||
|
pub stickied: bool
|
||||||
|
}
|
||||||
|
|
||||||
// Post containing content, metadata and media
|
// Post containing content, metadata and media
|
||||||
pub struct Post {
|
pub struct Post {
|
||||||
@ -25,7 +30,7 @@ pub struct Post {
|
|||||||
pub score: String,
|
pub score: String,
|
||||||
pub post_type: String,
|
pub post_type: String,
|
||||||
pub flair: Flair,
|
pub flair: Flair,
|
||||||
pub nsfw: bool,
|
pub flags: Flags,
|
||||||
pub media: String,
|
pub media: String,
|
||||||
pub time: String,
|
pub time: String,
|
||||||
}
|
}
|
||||||
@ -171,7 +176,10 @@ pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec<Pos
|
|||||||
"white".to_string()
|
"white".to_string()
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
flags: Flags {
|
||||||
nsfw: post["data"]["over_18"].as_bool().unwrap_or(false),
|
nsfw: post["data"]["over_18"].as_bool().unwrap_or(false),
|
||||||
|
stickied: post["data"]["stickied"].as_bool().unwrap_or(false)
|
||||||
|
},
|
||||||
url: val(post, "permalink").await,
|
url: val(post, "permalink").await,
|
||||||
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
|
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
|
||||||
});
|
});
|
||||||
|
@ -237,6 +237,12 @@ aside {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.stickied {
|
||||||
|
--accent: #5cff85;
|
||||||
|
border: 1px solid #5cff85;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.post_subreddit {
|
.post_subreddit {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<div class="post">
|
<div class="post">
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<p class="post_score">{{ post.score }}</p>
|
<p class="post_score">{{ post.score }}</p>
|
||||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<p>
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<div class="post highlighted">
|
<div class="post highlighted">
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<p class="post_score">{{ post.score }}</p>
|
<p class="post_score">{{ post.score }}</p>
|
||||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<p>
|
||||||
|
@ -22,10 +22,10 @@
|
|||||||
</select>{% endif %}<input id="sort_submit" type="submit" value="→">
|
</select>{% endif %}<input id="sort_submit" type="submit" value="→">
|
||||||
</form>
|
</form>
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<div class="post">
|
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<p class="post_score">{{ post.score }}</p>
|
<p class="post_score">{{ post.score }}</p>
|
||||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<p>
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<div class='post'>
|
<div class='post'>
|
||||||
<div class="post_left">
|
<div class="post_left">
|
||||||
<p class="post_score">{{ post.score }}</p>
|
<p class="post_score">{{ post.score }}</p>
|
||||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user