From 6853d21ea947de2de9f70b60dac0c5da2334a7ed Mon Sep 17 00:00:00 2001
From: spikecodes <19519553+spikecodes@users.noreply.github.com>
Date: Mon, 16 Nov 2020 18:49:08 -0800
Subject: [PATCH] 1.1.2 Flairs
---
src/post.rs | 11 ++++++++++-
src/subreddit.rs | 9 +++++++++
src/user.rs | 9 +++++++++
static/style.css | 9 +++++++++
templates/popular.html | 7 ++++++-
templates/post.html | 7 ++++++-
templates/subreddit.html | 7 ++++++-
templates/user.html | 9 ++++++++-
8 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/src/post.rs b/src/post.rs
index b252612..df91971 100644
--- a/src/post.rs
+++ b/src/post.rs
@@ -13,6 +13,9 @@ struct PostTemplate {
sort: String,
}
+// Post flair with text, background color and foreground color
+pub struct Flair(String, String, String);
+
pub struct Post {
pub title: String,
pub community: String,
@@ -22,6 +25,7 @@ pub struct Post {
pub score: String,
pub media: String,
pub time: String,
+ pub flair: Flair,
}
pub struct Comment {
@@ -39,7 +43,7 @@ async fn render(id: String, sort: String) -> Result {
let s = PostTemplate {
comments: comments,
post: post,
- sort: sort,
+ sort: sort
}
.render()
.unwrap();
@@ -126,6 +130,11 @@ async fn fetch_post(id: &String) -> Post {
score: if score > 1000 { format!("{}k", score / 1000) } else { score.to_string() },
media: media(post_data).await,
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
+ flair: Flair(
+ val(post_data, "link_flair_text").await,
+ val(post_data, "link_flair_background_color").await,
+ if val(post_data, "link_flair_text_color").await == "dark" { "black".to_string() } else { "white".to_string() }
+ ),
}
}
diff --git a/src/subreddit.rs b/src/subreddit.rs
index ee3eddb..e8f227f 100644
--- a/src/subreddit.rs
+++ b/src/subreddit.rs
@@ -12,6 +12,9 @@ struct SubredditTemplate {
sort: String,
}
+// Post flair with text, background color and foreground color
+pub struct Flair(pub String, pub String, pub String);
+
pub struct Post {
pub title: String,
pub community: String,
@@ -20,6 +23,7 @@ pub struct Post {
pub image: String,
pub url: String,
pub time: String,
+ pub flair: Flair,
}
pub struct Subreddit {
@@ -106,6 +110,11 @@ pub async fn posts(sub: String, sort: &String) -> Vec {
image: img,
url: val(post, "permalink").await,
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
+ flair: Flair(
+ val(post, "link_flair_text").await,
+ val(post, "link_flair_background_color").await,
+ if val(post, "link_flair_text_color").await == "dark" { "black".to_string() } else { "white".to_string() }
+ ),
});
}
posts
diff --git a/src/user.rs b/src/user.rs
index afb9054..489ed0c 100644
--- a/src/user.rs
+++ b/src/user.rs
@@ -12,6 +12,9 @@ struct UserTemplate {
sort: String,
}
+// Post flair with text, background color and foreground color
+pub struct Flair(String, String, String);
+
pub struct Post {
pub title: String,
pub community: String,
@@ -20,6 +23,7 @@ pub struct Post {
pub image: String,
pub url: String,
pub time: String,
+ pub flair: Flair,
}
pub struct User {
@@ -99,6 +103,11 @@ async fn posts(sub: String, sort: &String) -> Vec {
image: img,
url: post_val(post, "permalink").await,
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
+ flair: Flair(
+ post_val(post, "link_flair_text").await,
+ post_val(post, "link_flair_background_color").await,
+ if post_val(post, "link_flair_text_color").await == "dark" { "black".to_string() } else { "white".to_string() }
+ ),
});
}
diff --git a/static/style.css b/static/style.css
index dfa0b3e..01acc81 100644
--- a/static/style.css
+++ b/static/style.css
@@ -220,6 +220,15 @@ span {
border: none;
}
+small {
+ background: aqua;
+ color: black;
+ padding: 5px;
+ border-radius: 5px;
+ font-size: 12px;
+ font-weight: bold;
+}
+
/* Comment */
.comment {
diff --git a/templates/popular.html b/templates/popular.html
index 1a3c399..ed89285 100644
--- a/templates/popular.html
+++ b/templates/popular.html
@@ -37,7 +37,12 @@
u/{{ post.author }}
{{ post.time }}
-
+
+ {% if post.flair.0 != "" %}
+ {{ post.flair.0 }}
+ {% endif %}
+ {{ post.title }}
+
diff --git a/templates/post.html b/templates/post.html
index 65f83ec..85ae836 100644
--- a/templates/post.html
+++ b/templates/post.html
@@ -32,7 +32,12 @@
u/{{ post.author }}
{{ post.time }}
- {{ post.title }}
+
+ {{ post.title }}
+ {% if post.flair.0 != "" %}
+ {{ post.flair.0 }}
+ {% endif %}
+
{{ post.media }}
{{ post.body }}
diff --git a/templates/subreddit.html b/templates/subreddit.html
index af862bb..42184d6 100644
--- a/templates/subreddit.html
+++ b/templates/subreddit.html
@@ -48,7 +48,12 @@
u/{{ post.author }}
{{ post.time }}
-
+
+ {% if post.flair.0 != "" %}
+ {{ post.flair.0 }}
+ {% endif %}
+ {{ post.title }}
+
diff --git a/templates/user.html b/templates/user.html
index 3b54d87..580c608 100644
--- a/templates/user.html
+++ b/templates/user.html
@@ -48,7 +48,14 @@
u/{{ post.author }}
{{ post.time }}
-
+
+ {% if post.flair.0 == "Comment" %}
+ {% else if post.flair.0 == "" %}
+ {% else %}
+ {{ post.flair.0 }}
+ {% endif %}
+ {{ post.title }}
+