mirror of https://github.com/spikecodes/libreddit
Minor formatting and style changes
This commit is contained in:
parent
b22c9ff842
commit
e855c31f38
|
@ -11,7 +11,7 @@ pub(crate) static CONFIG: Lazy<Config> = Lazy::new(Config::load);
|
||||||
|
|
||||||
// This serves as the frontend for the Pushshift API - on removed comments, this URL will
|
// This serves as the frontend for the Pushshift API - on removed comments, this URL will
|
||||||
// be the base of a link, to display removed content (on another site).
|
// be the base of a link, to display removed content (on another site).
|
||||||
pub(crate) static DEFAULT_PUSHSHIFT_FRONTEND: &str = "www.unddit.com";
|
pub(crate) const DEFAULT_PUSHSHIFT_FRONTEND: &str = "www.unddit.com";
|
||||||
|
|
||||||
/// Stores the configuration parsed from the environment variables and the
|
/// Stores the configuration parsed from the environment variables and the
|
||||||
/// config file. `Config::Default()` contains None for each setting.
|
/// config file. `Config::Default()` contains None for each setting.
|
||||||
|
@ -79,7 +79,6 @@ impl Config {
|
||||||
// both are `None`, return a `None` via the `map_or_else` function
|
// both are `None`, return a `None` via the `map_or_else` function
|
||||||
let parse = |key: &str| -> Option<String> { var(key).ok().map_or_else(|| get_setting_from_config(key, &config), Some) };
|
let parse = |key: &str| -> Option<String> { var(key).ok().map_or_else(|| get_setting_from_config(key, &config), Some) };
|
||||||
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
sfw_only: parse("LIBREDDIT_SFW_ONLY"),
|
sfw_only: parse("LIBREDDIT_SFW_ONLY"),
|
||||||
default_theme: parse("LIBREDDIT_DEFAULT_THEME"),
|
default_theme: parse("LIBREDDIT_DEFAULT_THEME"),
|
||||||
|
@ -130,7 +129,8 @@ pub(crate) fn get_setting(name: &str) -> Option<String> {
|
||||||
use {sealed_test::prelude::*, std::fs::write};
|
use {sealed_test::prelude::*, std::fs::write};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize() { // Must handle empty input
|
fn test_deserialize() {
|
||||||
|
// Must handle empty input
|
||||||
let result = toml::from_str::<Config>("");
|
let result = toml::from_str::<Config>("");
|
||||||
assert!(result.is_ok(), "Error: {}", result.unwrap_err());
|
assert!(result.is_ok(), "Error: {}", result.unwrap_err());
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ impl InstanceInfo {
|
||||||
["Compile mode", &self.compile_mode],
|
["Compile mode", &self.compile_mode],
|
||||||
["SFW only", &convert(&self.config.sfw_only)],
|
["SFW only", &convert(&self.config.sfw_only)],
|
||||||
["Pushshift frontend", &convert(&self.config.pushshift)],
|
["Pushshift frontend", &convert(&self.config.pushshift)],
|
||||||
|
//TODO: fallback to crate::config::DEFAULT_PUSHSHIFT_FRONTEND
|
||||||
])
|
])
|
||||||
.with_header_row(["Settings"]),
|
.with_header_row(["Settings"]),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// CRATES
|
// CRATES
|
||||||
use crate::client::json;
|
use crate::client::json;
|
||||||
use crate::config::{get_setting, DEFAULT_PUSHSHIFT_FRONTEND};
|
use crate::config::get_setting;
|
||||||
use crate::server::RequestExt;
|
use crate::server::RequestExt;
|
||||||
use crate::subreddit::{can_access_quarantine, quarantine};
|
use crate::subreddit::{can_access_quarantine, quarantine};
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
|
@ -126,7 +126,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
|
||||||
let body = if (val(&comment, "author") == "[deleted]" && val(&comment, "body") == "[removed]") || val(&comment, "body") == "[ Removed by Reddit ]" {
|
let body = if (val(&comment, "author") == "[deleted]" && val(&comment, "body") == "[removed]") || val(&comment, "body") == "[ Removed by Reddit ]" {
|
||||||
format!(
|
format!(
|
||||||
"<div class=\"md\"><p>[removed] — <a href=\"https://{}{}{}\">view removed comment</a></p></div>",
|
"<div class=\"md\"><p>[removed] — <a href=\"https://{}{}{}\">view removed comment</a></p></div>",
|
||||||
get_setting("LIBREDDIT_PUSHSHIFT_FRONTEND").unwrap_or(String::from(DEFAULT_PUSHSHIFT_FRONTEND)),
|
get_setting("LIBREDDIT_PUSHSHIFT_FRONTEND").unwrap_or(String::from(crate::config::DEFAULT_PUSHSHIFT_FRONTEND)),
|
||||||
post_link,
|
post_link,
|
||||||
id
|
id
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue