User Flairs
This commit is contained in:
parent
1678245750
commit
ef3820a2e1
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1015,7 +1015,7 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libreddit"
|
name = "libreddit"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"askama",
|
"askama",
|
||||||
|
@ -3,7 +3,7 @@ name = "libreddit"
|
|||||||
description = " Alternative private front-end to Reddit"
|
description = " Alternative private front-end to Reddit"
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
repository = "https://github.com/spikecodes/libreddit"
|
repository = "https://github.com/spikecodes/libreddit"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ Libreddit hopes to provide an easier way to browse Reddit, without the ads, trac
|
|||||||
Libreddit currently implements most of Reddit's functionalities but still lacks a few features that are being worked on below.
|
Libreddit currently implements most of Reddit's functionalities but still lacks a few features that are being worked on below.
|
||||||
|
|
||||||
### In Progress
|
### In Progress
|
||||||
- User flairs
|
|
||||||
- Searching
|
- Searching
|
||||||
|
- Multireddits
|
||||||
|
|
||||||
### How does it compare to Teddit?
|
### How does it compare to Teddit?
|
||||||
|
|
||||||
|
31
src/post.rs
31
src/post.rs
@ -17,12 +17,15 @@ struct PostTemplate {
|
|||||||
sort: String,
|
sort: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
async fn render(id: String, sort: Option<String>) -> Result<HttpResponse> {
|
||||||
// Log the post ID being fetched
|
// Log the post ID being fetched
|
||||||
dbg!(&id);
|
dbg!(&id);
|
||||||
|
|
||||||
|
// Handling sort paramater
|
||||||
|
let sorting: String = sort.unwrap_or("confidence".to_string());
|
||||||
|
|
||||||
// Build the Reddit JSON API url
|
// Build the Reddit JSON API url
|
||||||
let url: String = format!("https://reddit.com/{}.json?sort={}", id, sort);
|
let url: String = format!("https://reddit.com/{}.json?sort={}", id, sorting);
|
||||||
|
|
||||||
// Send a request to the url, receive JSON in response
|
// Send a request to the url, receive JSON in response
|
||||||
let req = request(url).await;
|
let req = request(url).await;
|
||||||
@ -48,7 +51,7 @@ async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
|||||||
let s = PostTemplate {
|
let s = PostTemplate {
|
||||||
comments: comments.unwrap(),
|
comments: comments.unwrap(),
|
||||||
post: post.unwrap(),
|
post: post.unwrap(),
|
||||||
sort: sort,
|
sort: sorting,
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -57,17 +60,11 @@ async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
|||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
pub async fn short(web::Path(id): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
pub async fn short(web::Path(id): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
match ¶ms.sort {
|
render(id, params.sort.clone()).await
|
||||||
Some(sort) => render(id, sort.to_string()).await,
|
|
||||||
None => render(id, "confidence".to_string()).await,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn page(web::Path((_sub, id)): web::Path<(String, String)>, params: web::Query<Params>) -> Result<HttpResponse> {
|
pub async fn page(web::Path((_sub, id)): web::Path<(String, String)>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
match ¶ms.sort {
|
render(id, params.sort.clone()).await
|
||||||
Some(sort) => render(id, sort.to_string()).await,
|
|
||||||
None => render(id, "confidence".to_string()).await,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UTILITIES
|
// UTILITIES
|
||||||
@ -118,6 +115,11 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
|||||||
community: val(post_data, "subreddit").await,
|
community: val(post_data, "subreddit").await,
|
||||||
body: markdown_to_html(post_data["data"]["selftext"].as_str().unwrap()).await,
|
body: markdown_to_html(post_data["data"]["selftext"].as_str().unwrap()).await,
|
||||||
author: val(post_data, "author").await,
|
author: val(post_data, "author").await,
|
||||||
|
author_flair: Flair(
|
||||||
|
val(post_data, "author_flair_text").await,
|
||||||
|
val(post_data, "author_flair_background_color").await,
|
||||||
|
val(post_data, "author_flair_text_color").await,
|
||||||
|
),
|
||||||
url: val(post_data, "permalink").await,
|
url: val(post_data, "permalink").await,
|
||||||
score: format_num(score),
|
score: format_num(score),
|
||||||
post_type: media.0,
|
post_type: media.0,
|
||||||
@ -131,7 +133,7 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
|||||||
} else {
|
} else {
|
||||||
"white".to_string()
|
"white".to_string()
|
||||||
},
|
},
|
||||||
),
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(post)
|
Ok(post)
|
||||||
@ -167,6 +169,11 @@ async fn parse_comments(json: serde_json::Value) -> Result<Vec<Comment>, &'stati
|
|||||||
score: format_num(score),
|
score: format_num(score),
|
||||||
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(),
|
||||||
replies: replies,
|
replies: replies,
|
||||||
|
flair: Flair(
|
||||||
|
val(comment, "author_flair_text").await,
|
||||||
|
val(comment, "author_flair_background_color").await,
|
||||||
|
val(comment, "author_flair_text_color").await,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ pub struct Post {
|
|||||||
pub community: String,
|
pub community: String,
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
|
pub author_flair: Flair,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub score: String,
|
pub score: String,
|
||||||
pub post_type: String,
|
pub post_type: String,
|
||||||
@ -35,6 +36,7 @@ pub struct Post {
|
|||||||
pub struct Comment {
|
pub struct Comment {
|
||||||
pub body: String,
|
pub body: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
|
pub flair: Flair,
|
||||||
pub score: String,
|
pub score: String,
|
||||||
pub time: String,
|
pub time: String,
|
||||||
pub replies: Vec<Comment>,
|
pub replies: Vec<Comment>,
|
||||||
@ -147,6 +149,11 @@ pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec<Pos
|
|||||||
community: val(post, "subreddit").await,
|
community: val(post, "subreddit").await,
|
||||||
body: val(post, "body").await,
|
body: val(post, "body").await,
|
||||||
author: val(post, "author").await,
|
author: val(post, "author").await,
|
||||||
|
author_flair: Flair(
|
||||||
|
val(post, "author_flair_text").await,
|
||||||
|
val(post, "author_flair_background_color").await,
|
||||||
|
val(post, "author_flair_text_color").await,
|
||||||
|
),
|
||||||
score: format_num(score),
|
score: format_num(score),
|
||||||
post_type: "link".to_string(),
|
post_type: "link".to_string(),
|
||||||
media: img,
|
media: img,
|
||||||
|
@ -253,7 +253,7 @@ a:not(.post_right):hover {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
small {
|
.post_flair {
|
||||||
background: aqua;
|
background: aqua;
|
||||||
color: black;
|
color: black;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
@ -292,6 +292,16 @@ small {
|
|||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.author_flair {
|
||||||
|
background: var(--highlighted);
|
||||||
|
color: white;
|
||||||
|
padding: 5px;
|
||||||
|
margin-right: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
.comment_upvote {
|
.comment_upvote {
|
||||||
margin-top: 0.5em;
|
margin-top: 0.5em;
|
||||||
border-radius: 5px 5px 0px 0px;
|
border-radius: 5px 5px 0px 0px;
|
||||||
|
@ -15,14 +15,15 @@
|
|||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<h4>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
||||||
•
|
• <a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
Posted by
|
{% if post.author_flair.0 != "" %}
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
|
{% endif %}
|
||||||
<span class="datetime" style="float: right;">{{ post.time }}</span>
|
<span class="datetime" style="float: right;">{{ post.time }}</span>
|
||||||
</h4>
|
</h4>
|
||||||
<h3 class="post_title">
|
<h3 class="post_title">
|
||||||
{% if post.flair.0 != "" %}
|
{% if post.flair.0 != "" %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
@ -14,7 +14,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<details class="comment_right" open>
|
<details class="comment_right" open>
|
||||||
<summary class="comment_data">
|
<summary class="comment_data">
|
||||||
<a class="comment_author" href="/u/{{ item.author }}">u/{{ item.author }}</a> • <span class="datetime">{{ item.time }}</span>
|
<a class="comment_author" href="/u/{{ item.author }}">u/{{ item.author }}</a>
|
||||||
|
{% if item.flair.0 != "" %}
|
||||||
|
<small class="author_flair">{{ item.flair.0 }}</small>
|
||||||
|
{% endif %}
|
||||||
|
• <span class="datetime">{{ item.time }}</span>
|
||||||
</summary>
|
</summary>
|
||||||
<h4 class="comment_body">{{ item.body }}</h4>
|
<h4 class="comment_body">{{ item.body }}</h4>
|
||||||
|
|
||||||
@ -29,14 +33,16 @@
|
|||||||
<h4>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
||||||
•
|
•
|
||||||
Posted by
|
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
|
{% if post.author_flair.0 != "" %}
|
||||||
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
|
{% endif %}
|
||||||
<span class="datetime">{{ post.time }}</span>
|
<span class="datetime">{{ post.time }}</span>
|
||||||
</h4>
|
</h4>
|
||||||
<a href="{{ post.url }}" class="post_title">
|
<a href="{{ post.url }}" class="post_title">
|
||||||
{{ post.title }}
|
{{ post.title }}
|
||||||
{% if post.flair.0 != "" %}
|
{% if post.flair.0 != "" %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
{% if post.post_type == "image" %}
|
{% if post.post_type == "image" %}
|
||||||
|
@ -27,14 +27,15 @@
|
|||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<h4>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ sub.name }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ sub.name }}</a></b>
|
||||||
•
|
• <a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
Posted by
|
{% if post.author_flair.0 != "" %}
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
|
{% endif %}
|
||||||
<span class="datetime">{{ post.time }}</span>
|
<span class="datetime">{{ post.time }}</span>
|
||||||
</h4>
|
</h4>
|
||||||
<h3 class="post_title">
|
<h3 class="post_title">
|
||||||
{% if post.flair.0 != "" %}
|
{% if post.flair.0 != "" %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
@ -27,16 +27,17 @@
|
|||||||
<div class="post_right">
|
<div class="post_right">
|
||||||
<h4>
|
<h4>
|
||||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a></b>
|
||||||
•
|
• <a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||||
Posted by
|
{% if post.author_flair.0 != "" %}
|
||||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||||
|
{% endif %}
|
||||||
<span class="datetime" style="float: right;">{{ post.time }}</span>
|
<span class="datetime" style="float: right;">{{ post.time }}</span>
|
||||||
</h4>
|
</h4>
|
||||||
<h3 class="post_title">
|
<h3 class="post_title">
|
||||||
{% if post.flair.0 == "Comment" %}
|
{% if post.flair.0 == "Comment" %}
|
||||||
{% else if post.flair.0 == "" %}
|
{% else if post.flair.0 == "" %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
Loading…
Reference in New Issue
Block a user