From 3c536471adb2a89d5ea20ddaec91ca1a0a42d5da Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Fri, 13 Jan 2023 15:27:52 -0500 Subject: [PATCH] Address comments --- src/instance_info.rs | 74 ++++++++++++++++++++++++++++---------------- src/main.rs | 4 +-- static/style.css | 25 ++++++++++++--- templates/base.html | 5 +-- 4 files changed, 70 insertions(+), 38 deletions(-) diff --git a/src/instance_info.rs b/src/instance_info.rs index 818caad..a98f78c 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -1,7 +1,7 @@ use crate::{ config::{Config, CONFIG}, server::RequestExt, - utils::Preferences, + utils::{ErrorTemplate, Preferences}, }; use askama::Template; use build_html::{Container, Html, HtmlContainer, Table}; @@ -21,10 +21,20 @@ pub async fn instance_info(req: Request) -> Result, String> // simply become the last option, an HTML page. let extension = req.param("extension").unwrap_or(String::new()); let response = match extension.as_str() { - "yaml" => info_yaml(), + "yaml" | "yml" => info_yaml(), "txt" => info_txt(), "json" => info_json(), - "html" | _ => info_html(req), + "html" | "" => info_html(req), + _ => { + let error = ErrorTemplate { + msg: "Error: Invalid info extension".into(), + prefs: Preferences::new(&req), + url: req.uri().to_string(), + } + .render() + .unwrap(); + Response::builder().status(404).header("content-type", "text/html; charset=utf-8").body(error.into()) + } }; response.map_err(|err| format!("{err}")) } @@ -83,31 +93,41 @@ impl InstanceInfo { } fn to_table(&self) -> String { let mut container = Container::default(); - let convert = |o: &Option| -> String { o.clone().unwrap_or("Unset".to_owned()) }; - container.add_header(3, "Instance banner"); + let convert = |o: &Option| -> String { o.clone().unwrap_or("Unset".to_owned()) }; + if let Some(banner) = &self.config.banner { + container.add_header(3, "Instance banner"); + container.add_raw("
"); + container.add_paragraph(banner); + container.add_raw("
"); + } + container.add_table( + Table::from([ + ["Crate version", &self.crate_version], + ["Git commit", &self.git_commit], + ["Deploy date", &self.deploy_date], + ["Deploy timestamp", &self.deploy_unix_ts.to_string()], + ["Compile mode", &self.compile_mode], + ]) + .with_header_row(["Settings"]), + ); container.add_raw("
"); - container.add_paragraph(convert(&self.config.banner)); - container.add_raw("
"); - container.add_table(Table::from([ - ["Crate version", &self.crate_version], - ["Git commit", &self.git_commit], - ["Deploy date", &self.deploy_date], - ["Deploy timestamp", &self.deploy_unix_ts.to_string()], - ["Compile mode", &self.compile_mode], - ["Settings", "Settings"], - ["SFW only", &convert(&self.config.sfw_only)], - ["Hide awards", &convert(&self.config.default_hide_awards)], - ["Default theme", &convert(&self.config.default_theme)], - ["Default front page", &convert(&self.config.default_front_page)], - ["Default layout", &convert(&self.config.default_layout)], - ["Default wide", &convert(&self.config.default_wide)], - ["Default comment sort", &convert(&self.config.default_comment_sort)], - ["Default post sort", &convert(&self.config.default_post_sort)], - ["Default show NSFW", &convert(&self.config.default_show_nsfw)], - ["Default blur NSFW", &convert(&self.config.default_blur_nsfw)], - ["Default use HLS", &convert(&self.config.default_use_hls)], - ["Default hide HLS notification", &convert(&self.config.default_hide_hls_notification)], - ])); + container.add_table( + Table::from([ + ["SFW only", &convert(&self.config.sfw_only)], + ["Hide awards", &convert(&self.config.default_hide_awards)], + ["Default theme", &convert(&self.config.default_theme)], + ["Default front page", &convert(&self.config.default_front_page)], + ["Default layout", &convert(&self.config.default_layout)], + ["Default wide", &convert(&self.config.default_wide)], + ["Default comment sort", &convert(&self.config.default_comment_sort)], + ["Default post sort", &convert(&self.config.default_post_sort)], + ["Default show NSFW", &convert(&self.config.default_show_nsfw)], + ["Default blur NSFW", &convert(&self.config.default_blur_nsfw)], + ["Default use HLS", &convert(&self.config.default_use_hls)], + ["Default hide HLS notification", &convert(&self.config.default_hide_hls_notification)], + ]) + .with_header_row(["Default preferences"]), + ); container.to_html_string() } fn to_string(&self, string_type: StringType) -> String { diff --git a/src/main.rs b/src/main.rs index 3e61ef5..7489aa0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -295,8 +295,8 @@ async fn main() { app.at("/about").get(|req| error(req, "About pages aren't added yet".to_string()).boxed()); // Instance info page - app.at("/instance-info").get(|r| instance_info::instance_info(r).boxed()); - app.at("/instance-info.:extension").get(|r| instance_info::instance_info(r).boxed()); + app.at("/info").get(|r| instance_info::instance_info(r).boxed()); + app.at("/info.:extension").get(|r| instance_info::instance_info(r).boxed()); app.at("/:id").get(|req: Request| { Box::pin(async move { diff --git a/static/style.css b/static/style.css index 4981555..91abdd3 100644 --- a/static/style.css +++ b/static/style.css @@ -173,13 +173,24 @@ body > footer { margin: 20px; } -body > footer > div#sfw-only { - color: var(--green); - border: 1px solid var(--green); - padding: 5px; +.info-button { + align-items: center; + border: 1px solid rgba(0, 0, 0, 0.1); + border-radius: .25rem; + box-shadow: rgba(0, 0, 0, 0.02) 0 1px 3px 0; box-sizing: border-box; - border-radius: 5px; + color: rgba(0, 0, 0, 0.85); + cursor: pointer; + display: inline-flex; + padding: 0.5em; } +.info-button:hover, +.info-button:focus { + border-color: rgba(0, 0, 0, 0.15); + box-shadow: rgba(0, 0, 0, 0.1) 0 4px 12px; + color: rgba(0, 0, 0, 0.65); +} + /* / Body footer. */ /* Footer in content block. */ @@ -1227,6 +1238,10 @@ input[type="submit"] { width: 250px; background: var(--highlighted) !important; } +/* Info page */ +.unset { + color: lightslategrey; +} /* Markdown */ diff --git a/templates/base.html b/templates/base.html index 34666bc..7ae1a41 100644 --- a/templates/base.html +++ b/templates/base.html @@ -67,13 +67,10 @@ {% endblock %} {% block footer %} - {% if crate::utils::sfw_only() %} - - {% endif %} {% endblock %}