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]]
|
||||
name = "libreddit"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"askama",
|
||||
|
@ -3,7 +3,7 @@ name = "libreddit"
|
||||
description = " Alternative private front-end to Reddit"
|
||||
license = "AGPL-3.0"
|
||||
repository = "https://github.com/spikecodes/libreddit"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||
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.
|
||||
|
||||
### In Progress
|
||||
- Nested comments
|
||||
- User flairs
|
||||
- Searching
|
||||
- Multireddits
|
||||
|
||||
### How does it compare to Teddit?
|
||||
|
||||
|
30
src/post.rs
30
src/post.rs
@ -17,12 +17,15 @@ struct PostTemplate {
|
||||
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
|
||||
dbg!(&id);
|
||||
|
||||
// Handling sort paramater
|
||||
let sorting: String = sort.unwrap_or("confidence".to_string());
|
||||
|
||||
// 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
|
||||
let req = request(url).await;
|
||||
@ -48,7 +51,7 @@ async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
||||
let s = PostTemplate {
|
||||
comments: comments.unwrap(),
|
||||
post: post.unwrap(),
|
||||
sort: sort,
|
||||
sort: sorting,
|
||||
}
|
||||
.render()
|
||||
.unwrap();
|
||||
@ -56,15 +59,12 @@ async fn render(id: String, sort: String) -> Result<HttpResponse> {
|
||||
}
|
||||
|
||||
// SERVICES
|
||||
pub async fn short(web::Path(id): web::Path<String>) -> Result<HttpResponse> {
|
||||
render(id.to_string(), "confidence".to_string()).await
|
||||
pub async fn short(web::Path(id): web::Path<String>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||
render(id, params.sort.clone()).await
|
||||
}
|
||||
|
||||
pub async fn page(web::Path((_sub, id)): web::Path<(String, String)>, params: web::Query<Params>) -> Result<HttpResponse> {
|
||||
match ¶ms.sort {
|
||||
Some(sort) => render(id, sort.to_string()).await,
|
||||
None => render(id, "confidence".to_string()).await,
|
||||
}
|
||||
render(id, params.sort.clone()).await
|
||||
}
|
||||
|
||||
// UTILITIES
|
||||
@ -115,6 +115,11 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
||||
community: val(post_data, "subreddit").await,
|
||||
body: markdown_to_html(post_data["data"]["selftext"].as_str().unwrap()).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,
|
||||
score: format_num(score),
|
||||
post_type: media.0,
|
||||
@ -128,7 +133,7 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
||||
} else {
|
||||
"white".to_string()
|
||||
},
|
||||
),
|
||||
)
|
||||
};
|
||||
|
||||
Ok(post)
|
||||
@ -164,6 +169,11 @@ async fn parse_comments(json: serde_json::Value) -> Result<Vec<Comment>, &'stati
|
||||
score: format_num(score),
|
||||
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
||||
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 body: String,
|
||||
pub author: String,
|
||||
pub author_flair: Flair,
|
||||
pub url: String,
|
||||
pub score: String,
|
||||
pub post_type: String,
|
||||
@ -35,6 +36,7 @@ pub struct Post {
|
||||
pub struct Comment {
|
||||
pub body: String,
|
||||
pub author: String,
|
||||
pub flair: Flair,
|
||||
pub score: String,
|
||||
pub time: String,
|
||||
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,
|
||||
body: val(post, "body").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),
|
||||
post_type: "link".to_string(),
|
||||
media: img,
|
||||
|
@ -63,6 +63,7 @@ a:not(.post_right):hover {
|
||||
}
|
||||
|
||||
#about {
|
||||
padding-top: 20px;
|
||||
background: #151515;
|
||||
}
|
||||
|
||||
@ -133,6 +134,7 @@ a:not(.post_right):hover {
|
||||
}
|
||||
|
||||
#sort > div, footer > a {
|
||||
box-shadow: var(--black-contrast);
|
||||
background: var(--outside);
|
||||
color: lightgrey;
|
||||
border-radius: 5px;
|
||||
@ -251,7 +253,7 @@ a:not(.post_right):hover {
|
||||
display: none;
|
||||
}
|
||||
|
||||
small {
|
||||
.post_flair {
|
||||
background: aqua;
|
||||
color: black;
|
||||
padding: 5px;
|
||||
@ -267,11 +269,7 @@ small {
|
||||
margin-top: 1em;
|
||||
border-radius: 5px;
|
||||
display: flex;
|
||||
/* border: 2px solid var(--foreground); */
|
||||
}
|
||||
|
||||
.comment:hover {
|
||||
background: var(--post);
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.comment_left, .comment_right {
|
||||
@ -282,7 +280,7 @@ small {
|
||||
.comment_left {
|
||||
text-align: center;
|
||||
min-width: 50px;
|
||||
padding: 5px;
|
||||
padding: 5px 0px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
@ -294,6 +292,16 @@ small {
|
||||
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 {
|
||||
margin-top: 0.5em;
|
||||
border-radius: 5px 5px 0px 0px;
|
||||
@ -377,6 +385,21 @@ small {
|
||||
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 */
|
||||
|
||||
table {
|
||||
|
@ -3,6 +3,7 @@
|
||||
<head>
|
||||
{% block head %}
|
||||
<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="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
@ -15,14 +15,15 @@
|
||||
<div class="post_right">
|
||||
<h4>
|
||||
<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" style="float: right;">{{ post.time }}</span>
|
||||
</h4>
|
||||
<h3 class="post_title">
|
||||
{% 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 %}
|
||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||
</h3>
|
||||
|
@ -14,7 +14,11 @@
|
||||
</div>
|
||||
<details class="comment_right" open>
|
||||
<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>
|
||||
<h4 class="comment_body">{{ item.body }}</h4>
|
||||
|
||||
@ -29,14 +33,16 @@
|
||||
<h4>
|
||||
<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>
|
||||
{% if post.author_flair.0 != "" %}
|
||||
<small class="author_flair">{{ post.author_flair.0 }}</small>
|
||||
{% endif %}
|
||||
<span class="datetime">{{ post.time }}</span>
|
||||
</h4>
|
||||
<a href="{{ post.url }}" class="post_title">
|
||||
{{ post.title }}
|
||||
{% 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 %}
|
||||
</a>
|
||||
{% if post.post_type == "image" %}
|
||||
|
@ -27,14 +27,15 @@
|
||||
<div class="post_right">
|
||||
<h4>
|
||||
<b><a class="post_subreddit" href="/r/{{ post.community }}">r/{{ sub.name }}</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>
|
||||
</h4>
|
||||
<h3 class="post_title">
|
||||
{% 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 %}
|
||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||
</h3>
|
||||
|
@ -27,16 +27,17 @@
|
||||
<div class="post_right">
|
||||
<h4>
|
||||
<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" style="float: right;">{{ post.time }}</span>
|
||||
</h4>
|
||||
<h3 class="post_title">
|
||||
{% if post.flair.0 == "Comment" %}
|
||||
{% else if post.flair.0 == "" %}
|
||||
{% 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 %}
|
||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||
</h3>
|
||||
|
Reference in New Issue
Block a user