From 6b2c88a44f85765b16b4081e72ee1421436a9e61 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 18 May 2023 22:15:05 +0300 Subject: [PATCH] web: show list topics on site --- Cargo.lock | 1 + mailpot-tests/src/lib.rs | 2 +- rest-http/src/main.rs | 6 +++- web/Cargo.toml | 1 + web/src/main.rs | 13 ++++++++- web/src/minijinja_utils.rs | 16 +++++++++++ web/src/templates/css.html | 48 +++++++++++++++++++++++++++++++ web/src/templates/lists.html | 2 +- web/src/templates/lists/list.html | 4 +++ 9 files changed, 89 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fcba1a..95f65b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2036,6 +2036,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "stderrlog", "tempfile", "tokio", "tower", diff --git a/mailpot-tests/src/lib.rs b/mailpot-tests/src/lib.rs index dccb32b..d759938 100644 --- a/mailpot-tests/src/lib.rs +++ b/mailpot-tests/src/lib.rs @@ -42,7 +42,7 @@ pub fn init_stderr_logging() { INIT_STDERR_LOGGING.call_once(|| { stderrlog::new() .quiet(false) - .verbosity(15) + .verbosity(log::LevelFilter::Trace) .show_module_names(true) .timestamp(stderrlog::Timestamp::Millisecond) .init() diff --git a/rest-http/src/main.rs b/rest-http/src/main.rs index 180de46..704e406 100644 --- a/rest-http/src/main.rs +++ b/rest-http/src/main.rs @@ -7,9 +7,13 @@ async fn main() { let config_path = std::env::args() .nth(1) .expect("Expected configuration file path as first argument."); + #[cfg(test)] + let verbosity = log::LevelFilter::Trace; + #[cfg(not(test))] + let verbosity = log::LevelFilter::Info; stderrlog::new() .quiet(false) - .verbosity(15) + .verbosity(verbosity) .show_module_names(true) .timestamp(stderrlog::Timestamp::Millisecond) .init() diff --git a/web/Cargo.toml b/web/Cargo.toml index a203fc7..3e0bef5 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -34,6 +34,7 @@ percent-encoding = { version = "^2.1" } rand = { version = "^0.8", features = ["min_const_gen"] } serde = { version = "^1", features = ["derive", ] } serde_json = "^1" +stderrlog = "^0.5" tempfile = { version = "^3.5" } tokio = { version = "1", features = ["full"] } tower-http = { version = "^0.3" } diff --git a/web/src/main.rs b/web/src/main.rs index 231ac2c..df233ad 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -20,7 +20,7 @@ use std::{collections::HashMap, sync::Arc}; use chrono::TimeZone; -use mailpot::{Configuration, Connection}; +use mailpot::{log, Configuration, Connection}; use mailpot_web::*; use minijinja::value::Value; use rand::Rng; @@ -156,6 +156,17 @@ async fn main() { return; } + #[cfg(test)] + let verbosity = log::LevelFilter::Trace; + #[cfg(not(test))] + let verbosity = log::LevelFilter::Info; + stderrlog::new() + .quiet(false) + .verbosity(verbosity) + .show_module_names(true) + .timestamp(stderrlog::Timestamp::Millisecond) + .init() + .unwrap(); let conf = Configuration::from_file(config_path).unwrap(); let app = create_app(new_state(conf)); diff --git a/web/src/minijinja_utils.rs b/web/src/minijinja_utils.rs index b7b0c04..ce77da1 100644 --- a/web/src/minijinja_utils.rs +++ b/web/src/minijinja_utils.rs @@ -19,6 +19,8 @@ //! Utils for templates with the [`minijinja`] crate. +use std::fmt::Write; + use super::*; mod compressed; @@ -150,6 +152,20 @@ impl Object for MailingList { "unsubscription_mailto" => Ok(Value::from_serializable( &self.inner.unsubscription_mailto(), )), + "topics" => { + let mut ul = String::new(); + write!(&mut ul, r#""#)?; + Ok(Value::from_safe_string(ul)) + } _ => Err(Error::new( minijinja::ErrorKind::UnknownMethod, format!("object has no method named {name}"), diff --git a/web/src/templates/css.html b/web/src/templates/css.html index c389ad1..2029514 100644 --- a/web/src/templates/css.html +++ b/web/src/templates/css.html @@ -161,6 +161,7 @@ --code-foreground: #124; --code-background: #8fbcbb; --a-visited-text: var(--a-normal-text); + --tag-border-color: black; } @media (prefers-color-scheme: light) { @@ -237,6 +238,7 @@ --a-hover-bg: #bfbfbf40; --a-active-text: #c00; --a-active-underline: #c00; + --tag-border-color: #0000005e; color-scheme: light; } } @@ -316,6 +318,7 @@ --a-hover-bg: #bfbfbf40; --a-active-text: #c00; --a-active-underline: #c00; + --tag-border-color: #000; color-scheme: dark; } @@ -995,4 +998,49 @@ height:1px; overflow:hidden; } + + < + ul.tags.inline { + display: contents; + } + + ul.tags { + list-style: none; + margin: 0; + padding: 0; + height: max-content; + vertical-align: baseline; + display: inline-flex; + gap: 0.8ex; + flex-flow: row wrap; + } + + .tag { + --padding-top-bottom: 1px; + --padding-left-right: 5.4px; + + display: inline-block; + border: 1px solid var(--tag-border-color); + border-radius:.2rem; + color: #555; + font-size: .9rem; + padding: 0px 0.4em 1px 0.4em; + padding: var(--padding-top-bottom) var(--padding-left-right); + text-decoration: none; + + --aa-brightness: ((var(--red) * 299) + (var(--green) * 587) + (var(--blue) * 114)) / 1000; + --aa-color: calc((var(--aa-brightness) - 128) * -1000); + background: rgb(var(--red), var(--green), var(--blue)); + color: rgb(var(--aa-color), var(--aa-color), var(--aa-color)); + min-width: max-content; + max-height: calc(1.5cap + var(--padding-top-bottom)); + min-height: calc(1.5cap + var(--padding-top-bottom)); + } + + + + span.tag-name a { + text-decoration: none; + color: inherit; + } diff --git a/web/src/templates/lists.html b/web/src/templates/lists.html index b9582bc..e1f8c45 100644 --- a/web/src/templates/lists.html +++ b/web/src/templates/lists.html @@ -5,7 +5,7 @@
{% for l in lists %}
{{ l.list.name }}
-
{{ l.list.description if l.list.description else "no description" }} | {{ l.posts|length }} post{{ l.posts|length|pluralize("","s") }}{% if l.newest %} | {% endif %}
+
{{ l.list.description if l.list.description else "no description" }} | {{ l.posts|length }} post{{ l.posts|length|pluralize("","s") }}{% if l.newest %} | {% endif %}{% if l.list.topics|length > 0 %}Topics: {{ l.list.topics() }}{% endif %}
{% endfor %}
diff --git a/web/src/templates/lists/list.html b/web/src/templates/lists/list.html index dcd335d..4844855 100644 --- a/web/src/templates/lists/list.html +++ b/web/src/templates/lists/list.html @@ -1,5 +1,9 @@ {% include "header.html" %}
+ {% if list.topics|length > 0 %}Topics: {{ list.topics() }} + + + {% endif %} {% if list.description %}

List description: {{ list.description }}

{% else %}