Merge pull request #1 from spikecodes/master

Merge upstream
This commit is contained in:
robrobinbin 2021-01-13 20:22:43 +01:00 committed by GitHub
commit 33c8bdffb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 149 additions and 76 deletions

28
Cargo.lock generated
View File

@ -498,9 +498,9 @@ checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.0.0" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72" checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040"
[[package]] [[package]]
name = "bytestring" name = "bytestring"
@ -508,7 +508,7 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90706ba19e97b90786e19dc0d5e2abd80008d99d4c0c5d1ad0b5e72cec7c494d" checksum = "90706ba19e97b90786e19dc0d5e2abd80008d99d4c0c5d1ad0b5e72cec7c494d"
dependencies = [ dependencies = [
"bytes 1.0.0", "bytes 1.0.1",
] ]
[[package]] [[package]]
@ -752,7 +752,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-task", "futures-task",
"memchr", "memchr",
"pin-project-lite 0.2.3", "pin-project-lite 0.2.4",
"pin-utils", "pin-utils",
"proc-macro-hack", "proc-macro-hack",
"proc-macro-nested", "proc-macro-nested",
@ -856,7 +856,7 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747"
dependencies = [ dependencies = [
"bytes 1.0.0", "bytes 1.0.1",
"fnv", "fnv",
"itoa", "itoa",
] ]
@ -1013,9 +1013,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.11" version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if 0.1.10",
] ]
@ -1244,9 +1244,9 @@ checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.3" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba36e0a6cc5a4c645073f4984f1ed55d09f5857d4de7c14550baa81a39ef5a17" checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
[[package]] [[package]]
name = "pin-utils" name = "pin-utils"
@ -1472,18 +1472,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.118" version = "1.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" checksum = "9bdd36f49e35b61d49efd8aa7fc068fd295961fd2286d0b2ee9a4c7a14e99cc3"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.118" version = "1.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" checksum = "552954ce79a059ddd5fd68c271592374bd15cab2274970380c000118aeffe1cd"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1805,7 +1805,7 @@ checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"log", "log",
"pin-project-lite 0.2.3", "pin-project-lite 0.2.4",
"tracing-core", "tracing-core",
] ]

View File

@ -1,5 +1,5 @@
// Import Crates // Import Crates
use actix_web::{get, middleware, web, App, HttpResponse, HttpServer}; // dev::Service use actix_web::{middleware, web, App, HttpResponse, HttpServer}; // dev::Service
// Reference local files // Reference local files
mod post; mod post;
@ -21,9 +21,10 @@ async fn robots() -> HttpResponse {
.body(include_str!("../static/robots.txt")) .body(include_str!("../static/robots.txt"))
} }
#[get("/favicon.ico")]
async fn favicon() -> HttpResponse { async fn favicon() -> HttpResponse {
HttpResponse::Ok().body("") HttpResponse::Ok()
.header("Cache-Control", "public, max-age=1209600, s-maxage=86400")
.body(include_bytes!("../static/favicon.ico").as_ref())
} }
#[actix_web::main] #[actix_web::main]
@ -64,7 +65,7 @@ async fn main() -> std::io::Result<()> {
.default_service(web::get().to(|| utils::error("Nothing here".to_string()))) .default_service(web::get().to(|| utils::error("Nothing here".to_string())))
// GENERAL SERVICES // GENERAL SERVICES
.route("/style.css/", web::get().to(style)) .route("/style.css/", web::get().to(style))
.route("/favicon.ico/", web::get().to(HttpResponse::Ok)) .route("/favicon.ico/", web::get().to(favicon))
.route("/robots.txt/", web::get().to(robots)) .route("/robots.txt/", web::get().to(robots))
// SETTINGS SERVICE // SETTINGS SERVICE
.route("/settings/", web::get().to(settings::get)) .route("/settings/", web::get().to(settings::get))

View File

@ -1,5 +1,5 @@
// CRATES // CRATES
use crate::utils::{cookie, error, format_num, format_url, media, param, prefs, request, rewrite_url, val, Comment, Flags, Flair, Post, Preferences}; use crate::utils::{cookie, error, format_num, format_url, media, parse_rich_flair, param, prefs, request, rewrite_url, val, Comment, Flags, Flair, Post, Preferences};
use actix_web::{HttpRequest, HttpResponse}; use actix_web::{HttpRequest, HttpResponse};
use async_recursion::async_recursion; use async_recursion::async_recursion;
@ -82,25 +82,25 @@ async fn parse_post(json: &serde_json::Value) -> Post {
community: val(post, "subreddit"), community: val(post, "subreddit"),
body: rewrite_url(&val(post, "selftext_html")), body: rewrite_url(&val(post, "selftext_html")),
author: val(post, "author"), author: val(post, "author"),
author_flair: Flair( author_flair: Flair{
val(post, "author_flair_text"), flair_parts: parse_rich_flair(val(post, "author_flair_type"), post["data"]["author_flair_richtext"].as_array(), post["data"]["author_flair_text"].as_str()),
val(post, "author_flair_background_color"), background_color: val(post, "author_flair_background_color"),
val(post, "author_flair_text_color"), foreground_color: val(post, "author_flair_text_color"),
), },
permalink: val(post, "permalink"), permalink: val(post, "permalink"),
score: format_num(score), score: format_num(score),
upvote_ratio: ratio as i64, upvote_ratio: ratio as i64,
post_type, post_type,
thumbnail: format_url(val(post, "thumbnail").as_str()), thumbnail: format_url(val(post, "thumbnail").as_str()),
flair: Flair( flair: Flair{
val(post, "link_flair_text"), flair_parts: parse_rich_flair(val(post, "link_flair_type"), post["data"]["link_flair_richtext"].as_array(), post["data"]["link_flair_text"].as_str()),
val(post, "link_flair_background_color"), background_color: val(post, "link_flair_background_color"),
if val(post, "link_flair_text_color") == "dark" { foreground_color: if val(post, "link_flair_text_color") == "dark" {
"black".to_string() "black".to_string()
} else { } else {
"white".to_string() "white".to_string()
}, },
), },
flags: Flags { flags: Flags {
nsfw: post["data"]["over_18"].as_bool().unwrap_or(false), nsfw: post["data"]["over_18"].as_bool().unwrap_or(false),
stickied: post["data"]["stickied"].as_bool().unwrap_or(false), stickied: post["data"]["stickied"].as_bool().unwrap_or(false),
@ -117,7 +117,7 @@ async fn parse_comments(json: &serde_json::Value) -> Vec<Comment> {
// Separate the comment JSON into a Vector of comments // Separate the comment JSON into a Vector of comments
let comment_data = match json["data"]["children"].as_array() { let comment_data = match json["data"]["children"].as_array() {
Some(f) => f.to_owned(), Some(f) => f.to_owned(),
None => { let v = Vec::new(); v } None => Vec::new(),
}; };
let mut comments: Vec<Comment> = Vec::new(); let mut comments: Vec<Comment> = Vec::new();
@ -145,11 +145,11 @@ async fn parse_comments(json: &serde_json::Value) -> Vec<Comment> {
score: format_num(score), score: format_num(score),
time: OffsetDateTime::from_unix_timestamp(unix_time).format("%b %d %Y %H:%M UTC"), time: OffsetDateTime::from_unix_timestamp(unix_time).format("%b %d %Y %H:%M UTC"),
replies, replies,
flair: Flair( flair: Flair{
val(&comment, "author_flair_text"), flair_parts: parse_rich_flair(val(&comment, "author_flair_type"), comment["data"]["author_flair_richtext"].as_array(), comment["data"]["author_flair_text"].as_str()),
val(&comment, "author_flair_background_color"), background_color: val(&comment, "author_flair_background_color"),
val(&comment, "author_flair_text_color"), foreground_color: val(&comment, "author_flair_text_color"),
), },
}); });
} }

View File

@ -8,6 +8,8 @@ pub async fn handler(web::Path(b64): web::Path<String>) -> Result<HttpResponse>
// THUMBNAILS // THUMBNAILS
"a.thumbs.redditmedia.com", "a.thumbs.redditmedia.com",
"b.thumbs.redditmedia.com", "b.thumbs.redditmedia.com",
// EMOJI
"emoji.redditmedia.com",
// ICONS // ICONS
"styles.redditmedia.com", "styles.redditmedia.com",
"www.redditstatic.com", "www.redditstatic.com",

View File

@ -5,16 +5,26 @@ use actix_web::{cookie::Cookie, HttpRequest, HttpResponse, Result};
use askama::Template; use askama::Template;
use base64::encode; use base64::encode;
use regex::Regex; use regex::Regex;
use serde_json::from_str; use serde_json::{from_str, Value};
use std::collections::HashMap; use std::collections::HashMap;
use time::OffsetDateTime; use time::{OffsetDateTime, Duration};
use url::Url; use url::Url;
// //
// STRUCTS // STRUCTS
// //
// Post flair with text, background color and foreground color // Post flair with content, background color and foreground color
pub struct Flair(pub String, pub String, pub String); pub struct Flair{
pub flair_parts: Vec<FlairPart>,
pub background_color: String,
pub foreground_color: String,
}
pub struct FlairPart{
pub flair_part_type: String,
pub value: String,
}
// Post flags with nsfw and stickied // Post flags with nsfw and stickied
pub struct Flags { pub struct Flags {
pub nsfw: bool, pub nsfw: bool,
@ -169,10 +179,15 @@ pub async fn media(data: &serde_json::Value) -> (String, String) {
format_url(data["secure_media"]["reddit_video"]["fallback_url"].as_str().unwrap_or_default()) format_url(data["secure_media"]["reddit_video"]["fallback_url"].as_str().unwrap_or_default())
} else if data["post_hint"].as_str().unwrap_or("") == "image" { } else if data["post_hint"].as_str().unwrap_or("") == "image" {
let preview = data["preview"]["images"][0].clone(); let preview = data["preview"]["images"][0].clone();
post_type = "image";
match preview["variants"]["mp4"].as_object() { match preview["variants"]["mp4"].as_object() {
Some(gif) => format_url(gif["source"]["url"].as_str().unwrap_or_default()), Some(gif) => {
None => format_url(preview["source"]["url"].as_str().unwrap_or_default()), post_type = "gif";
format_url(gif["source"]["url"].as_str().unwrap_or_default())
},
None => {
post_type = "image";
format_url(preview["source"]["url"].as_str().unwrap_or_default())
},
} }
} else if data["is_self"].as_bool().unwrap_or_default() { } else if data["is_self"].as_bool().unwrap_or_default() {
post_type = "self"; post_type = "self";
@ -185,6 +200,45 @@ pub async fn media(data: &serde_json::Value) -> (String, String) {
(post_type.to_string(), url) (post_type.to_string(), url)
} }
pub fn parse_rich_flair(flair_type: String, rich_flair: Option<&Vec<Value>>, text_flair: Option<&str>) -> Vec<FlairPart> {
let mut result: Vec<FlairPart> = Vec::new();
if flair_type == "richtext" && !rich_flair.is_none() {
for part in rich_flair.unwrap() {
let flair_part_type = part["e"].as_str().unwrap_or_default().to_string();
let value = if flair_part_type == "text" {
part["t"].as_str().unwrap_or_default().to_string()
} else if flair_part_type == "emoji" {
format_url(part["u"].as_str().unwrap_or_default())
} else {
"".to_string()
};
result.push(FlairPart {
flair_part_type,
value,
});
}
} else if flair_type == "text" && !text_flair.is_none() {
result.push(FlairPart {
flair_part_type: "text".to_string(),
value: text_flair.unwrap().to_string(),
});
}
result
}
pub fn time(unix_time: i64) -> String {
let time = OffsetDateTime::from_unix_timestamp(unix_time);
let time_delta = OffsetDateTime::now_utc() - time;
if time_delta > Duration::days(1) {
time.format("%b %d '%y") // %b %e '%y
} else if time_delta.whole_hours() > 0 {
format!("{}h ago", time_delta.whole_hours())
} else {
format!("{}m ago", time_delta.whole_minutes())
}
}
// //
// JSON PARSING // JSON PARSING
// //
@ -238,32 +292,32 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec<Post
community: val(post, "subreddit"), community: val(post, "subreddit"),
body: rewrite_url(&val(post, "body_html")), body: rewrite_url(&val(post, "body_html")),
author: val(post, "author"), author: val(post, "author"),
author_flair: Flair( author_flair: Flair{
val(post, "author_flair_text"), flair_parts: parse_rich_flair(val(post, "author_flair_type"), post["data"]["author_flair_richtext"].as_array(), post["data"]["author_flair_text"].as_str()),
val(post, "author_flair_background_color"), background_color: val(post, "author_flair_background_color"),
val(post, "author_flair_text_color"), foreground_color: val(post, "author_flair_text_color"),
), },
score: format_num(score), score: format_num(score),
upvote_ratio: ratio as i64, upvote_ratio: ratio as i64,
post_type, post_type,
thumbnail: format_url(val(post, "thumbnail").as_str()), thumbnail: format_url(val(post, "thumbnail").as_str()),
media, media,
domain: val(post, "domain"), domain: val(post, "domain"),
flair: Flair( flair: Flair{
val(post, "link_flair_text"), flair_parts: parse_rich_flair(val(post, "link_flair_type"), post["data"]["link_flair_richtext"].as_array(), post["data"]["link_flair_text"].as_str()),
val(post, "link_flair_background_color"), background_color: val(post, "link_flair_background_color"),
if val(post, "link_flair_text_color") == "dark" { foreground_color: if val(post, "link_flair_text_color") == "dark" {
"black".to_string() "black".to_string()
} else { } else {
"white".to_string() "white".to_string()
}, },
), },
flags: Flags { flags: Flags {
nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(), nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(),
stickied: post["data"]["stickied"].as_bool().unwrap_or_default(), stickied: post["data"]["stickied"].as_bool().unwrap_or_default(),
}, },
permalink: val(post, "permalink"), permalink: val(post, "permalink"),
time: OffsetDateTime::from_unix_timestamp(unix_time).format("%b %d '%y"), // %b %e '%y time: time(unix_time),
}); });
} }

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

View File

@ -223,7 +223,7 @@ aside {
/* Sorting and Search */ /* Sorting and Search */
.search_label { .search_label {
max-width: 100px; max-width: 300px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@ -499,6 +499,16 @@ input[type="submit"]:hover { color: var(--accent); }
font-weight: bold; font-weight: bold;
} }
.emoji {
width: 1em;
height: 1em;
display: inline-block;
background-size: contain;
background-position: 50% 50%;
background-repeat: no-repeat;
vertical-align: middle;
}
.nsfw { .nsfw {
color: var(--nsfw); color: var(--nsfw);
margin-top: 20px; margin-top: 20px;
@ -779,6 +789,7 @@ input[type="submit"] {
margin-top: 10px; margin-top: 10px;
border-radius: 5px; border-radius: 5px;
box-shadow: var(--shadow); box-shadow: var(--shadow);
overflow: auto;
} }
.md table { .md table {

View File

@ -8,6 +8,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<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">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
{% endblock %} {% endblock %}
</head> </head>

View File

@ -22,12 +22,12 @@
</div> </div>
<details class="comment_right" open> <details class="comment_right" open>
<summary class="comment_data"><a class="comment_author {% if item.author == post.author %}op{% endif %}" href="/u/{{ item.author }}">u/{{ item.author }}</a> <summary class="comment_data"><a class="comment_author {% if item.author == post.author %}op{% endif %}" href="/u/{{ item.author }}">u/{{ item.author }}</a>
{% if item.flair.0 != "" %} {% if item.flair.flair_parts.len() > 0 %}
<small class="author_flair">{{ item.flair.0 }}</small> <small class="author_flair">{% call utils::render_flair(item.flair.flair_parts) %}</small>
{% endif %} {% endif %}
<span class="datetime">{{ item.time }}</span> <span class="datetime">{{ item.time }}</span>
</summary> </summary>
<p class="comment_body">{{ item.body }}</p> <div class="comment_body">{{ item.body }}</div>
{%- endmacro %} {%- endmacro %}
<!-- CLOSE COMMENT MACRO --> <!-- CLOSE COMMENT MACRO -->
@ -50,23 +50,23 @@
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a> <a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
<span class="dot">&bull;</span> <span class="dot">&bull;</span>
<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 != "" %} {% if post.author_flair.flair_parts.len() > 0 %}
<small class="author_flair">{{ post.author_flair.0 }}</small> <small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
{% endif %} {% endif %}
<span class="dot">&bull;</span> <span class="dot">&bull;</span>
<span class="datetime">{{ post.time }}</span> <span class="datetime">{{ post.time }}</span>
</p> </p>
<a href="{{ post.permalink }}" class="post_title"> <a href="{{ post.permalink }}" class="post_title">
{{ post.title }} {{ post.title }}
{% if post.flair.0 != "" %} {% if post.flair.flair_parts.len() > 0 %}
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small> <small class="post_flair" style="color:{{ post.flair.foreground_color }}; background:{{ post.flair.background_color }}">{% call utils::render_flair(post.flair.flair_parts) %}</small>
{% endif %} {% endif %}
</a> </a>
<!-- POST MEDIA --> <!-- POST MEDIA -->
{% if post.post_type == "image" %} {% if post.post_type == "image" %}
<img class="post_media" src="{{ post.media }}"/> <img class="post_media" src="{{ post.media }}"/>
{% else if post.post_type == "video" %} {% else if post.post_type == "video" || post.post_type == "gif" %}
<video class="post_media" src="{{ post.media }}" controls autoplay loop></video> <video class="post_media" src="{{ post.media }}" controls autoplay loop></video>
{% else if post.post_type == "link" %} {% else if post.post_type == "link" %}
<a id="post_url" href="{{ post.media }}">{{ post.media }}</a> <a id="post_url" href="{{ post.media }}">{{ post.media }}</a>

View File

@ -34,15 +34,15 @@
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a> <a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
<span class="dot">&bull;</span> <span class="dot">&bull;</span>
<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 != "" %} {% if post.author_flair.flair_parts.len() > 0 %}
<small class="author_flair">{{ post.author_flair.0 }}</small> <small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
{% endif %} {% endif %}
<span class="dot">&bull;</span> <span class="dot">&bull;</span>
<span class="datetime">{{ post.time }}</span> <span class="datetime">{{ post.time }}</span>
</p> </p>
<p class="post_title"> <p class="post_title">
{% if post.flair.0 != "" %} {% if post.flair.flair_parts.len() > 0 %}
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small> <small class="post_flair" style="color:{{ post.flair.foreground_color }}; background:{{ post.flair.background_color }}">{% call utils::render_flair(post.flair.flair_parts) %}</small>
{% endif %} {% endif %}
<a href="{{ post.permalink }}">{{ post.title }}</a> <a href="{{ post.permalink }}">{{ post.title }}</a>
</p> </p>

View File

@ -46,8 +46,8 @@
<span class="datetime">{{ post.time }}</span> <span class="datetime">{{ post.time }}</span>
</p> </p>
<p class="post_title"> <p class="post_title">
{% if post.flair.0 != "" %} {% if post.flair.flair_parts.len() > 0 %}
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small> <small class="post_flair" style="color:{{ post.flair.foreground_color }}; background:{{ post.flair.background_color }}">{% call utils::render_flair(post.flair.flair_parts) %}</small>
{% endif %} {% endif %}
<a href="{{ post.permalink }}">{{ post.title }}</a> <a href="{{ post.permalink }}">{{ post.title }}</a>
</p> </p>

View File

@ -32,17 +32,17 @@
<div class="post_text"> <div class="post_text">
<p class="post_header"> <p class="post_header">
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a> <a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a>
{% if post.author_flair.0 != "" %} {% if post.author_flair.flair_parts.len() > 0 %}
<small class="author_flair">{{ post.author_flair.0 }}</small> <small class="author_flair">{% call utils::render_flair(post.author_flair.flair_parts) %}</small>
{% endif %} {% endif %}
<span class="dot">&bull;</span> <span class="dot">&bull;</span>
<span class="datetime">{{ post.time }}</span> <span class="datetime">{{ post.time }}</span>
</p> </p>
<p class="post_title"> <p class="post_title">
{% if post.flair.0 == "Comment" %} {% if post.flair.background_color == "Comment" %}
{% else if post.flair.0 == "" %} {% else if post.flair.background_color == "" %}
{% else %} {% else %}
<small class="post_flair" style="color:{{ post.flair.2 }}; background:{{ post.flair.1 }}">{{ post.flair.0 }}</small> <small class="post_flair" style="color:{{ post.flair.foreground_color }}; background:{{ post.flair.background_color }}">{% call utils::render_flair(post.flair.flair_parts) %}</small>
{% endif %} {% endif %}
<a href="{{ post.permalink }}">{{ post.title }}</a> <a href="{{ post.permalink }}">{{ post.title }}</a>
</p> </p>

View File

@ -26,3 +26,7 @@
<input type="submit" value="&rarr;"> <input type="submit" value="&rarr;">
</form> </form>
{%- endmacro %} {%- endmacro %}
{% macro render_flair(flair) -%}
{% for flair_part in flair %}{% if flair_part.flair_part_type == "emoji" %}<span class="emoji" style="background-image:url('{{ flair_part.value }}')"></span>{% else if flair_part.flair_part_type == "text" %}<span>{{ flair_part.value }}</span>{% endif %}{% endfor %}
{%- endmacro %}