1.1.2 Flairs
This commit is contained in:
parent
3618f8815f
commit
6853d21ea9
11
src/post.rs
11
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<HttpResponse> {
|
||||
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() }
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Post> {
|
||||
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
|
||||
|
@ -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<Post> {
|
||||
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() }
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -37,7 +37,12 @@
|
||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||
<span style="float: right;">{{ post.time }}</span>
|
||||
</p>
|
||||
<h3 class="post_title"><a href="{{ post.url }}">{{ post.title }}</a></h3>
|
||||
<h3 class="post_title">
|
||||
{% if post.flair.0 != "" %}
|
||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||
{% endif %}
|
||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||
</h3>
|
||||
</div>
|
||||
<img class="post_thumbnail" src="{{ post.image }}">
|
||||
</div><br>
|
||||
|
@ -32,7 +32,12 @@
|
||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||
<span style="float: right;">{{ post.time }}</span>
|
||||
</p>
|
||||
<h3 class="post_title">{{ post.title }}</h3>
|
||||
<h3 class="post_title">
|
||||
{{ post.title }}
|
||||
{% if post.flair.0 != "" %}
|
||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||
{% endif %}
|
||||
</h3>
|
||||
{{ post.media }}
|
||||
<h4 class="post_body">{{ post.body }}</h4>
|
||||
</div>
|
||||
|
@ -48,7 +48,12 @@
|
||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||
<span style="float: right;">{{ post.time }}</span>
|
||||
</p>
|
||||
<h3 class="post_title"><a href="{{ post.url }}">{{ post.title }}</a></h3>
|
||||
<h3 class="post_title">
|
||||
{% if post.flair.0 != "" %}
|
||||
<small style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small>
|
||||
{% endif %}
|
||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||
</h3>
|
||||
</div>
|
||||
<img class="post_thumbnail" src="{{ post.image }}">
|
||||
</div><br>
|
||||
|
@ -48,7 +48,14 @@
|
||||
<a class="post_author" href="/u/{{ post.author }}">u/{{ post.author }}</a>
|
||||
<span style="float: right;">{{ post.time }}</span>
|
||||
</p>
|
||||
<h3 class="post_title"><a href="{{ post.url }}">{{ post.title }}</a></h3>
|
||||
<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>
|
||||
{% endif %}
|
||||
<a href="{{ post.url }}">{{ post.title }}</a>
|
||||
</h3>
|
||||
</div>
|
||||
<img class="post_thumbnail" src="{{ post.image }}">
|
||||
</div><br>
|
||||
|
Loading…
Reference in New Issue
Block a user