Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef3820a2e1 | |||
1678245750 | |||
3594b6d41f | |||
a754d42b9e | |||
c7e0234d33 | |||
11a9ff53e4 |
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,9 +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
|
||||||
- Nested comments
|
|
||||||
- User flairs
|
|
||||||
- Searching
|
- Searching
|
||||||
|
- Multireddits
|
||||||
|
|
||||||
### How does it compare to Teddit?
|
### How does it compare to Teddit?
|
||||||
|
|
||||||
|
30
src/post.rs
30
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();
|
||||||
@ -56,15 +59,12 @@ async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
pub async fn short(web::Path(id): web::Path<String>) -> Result<HttpResponse> {
|
pub async fn short(web::Path(id): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
render(id.to_string(), "confidence".to_string()).await
|
render(id, params.sort.clone()).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
|
||||||
@ -115,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,
|
||||||
@ -128,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)
|
||||||
@ -164,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,
|
||||||
|
@ -63,6 +63,7 @@ a:not(.post_right):hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#about {
|
#about {
|
||||||
|
padding-top: 20px;
|
||||||
background: #151515;
|
background: #151515;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +134,7 @@ a:not(.post_right):hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#sort > div, footer > a {
|
#sort > div, footer > a {
|
||||||
|
box-shadow: var(--black-contrast);
|
||||||
background: var(--outside);
|
background: var(--outside);
|
||||||
color: lightgrey;
|
color: lightgrey;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
@ -251,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;
|
||||||
@ -267,11 +269,7 @@ small {
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
display: flex;
|
display: flex;
|
||||||
/* border: 2px solid var(--foreground); */
|
font-size: 15px;
|
||||||
}
|
|
||||||
|
|
||||||
.comment:hover {
|
|
||||||
background: var(--post);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment_left, .comment_right {
|
.comment_left, .comment_right {
|
||||||
@ -282,7 +280,7 @@ small {
|
|||||||
.comment_left {
|
.comment_left {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
min-width: 50px;
|
min-width: 50px;
|
||||||
padding: 5px;
|
padding: 5px 0px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,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;
|
||||||
@ -377,6 +385,21 @@ small {
|
|||||||
background: black;
|
background: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Code */
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background: var(--outside);
|
||||||
|
padding: 20px;
|
||||||
|
margin-top: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
box-shadow: var(--black-contrast);
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Tables */
|
/* Tables */
|
||||||
|
|
||||||
table {
|
table {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<title>{% block title %}{% endblock %}</title>
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline';">
|
||||||
<meta name="description" content="View on Libreddit, an alternative private front-end to Reddit.">
|
<meta name="description" content="View on Libreddit, an alternative private front-end to Reddit.">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
@ -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>
|
||||||
|
Reference in New Issue
Block a user