From e8ee2850aaba95feacf02ab7028a10de08f206b6 Mon Sep 17 00:00:00 2001
From: Kay Faraday
Date: Tue, 23 Jul 2024 01:31:44 +0000
Subject: [PATCH] display by category
---
src/main.rs | 13 +++++++++++--
templates/emojo.html | 33 +++++++++++++++++----------------
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 1e8e996..7e4428b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,6 +13,7 @@ use rocket::{get, routes, Request, Response, State};
use serde::Deserialize;
use std::io::Cursor;
use std::str::FromStr;
+use std::collections::BTreeMap;
#[rocket::launch]
fn rocket() -> _ {
@@ -54,6 +55,8 @@ impl Responder<'_, 'static> for Html {
struct Emojo {
shortcode: String,
url: String,
+ #[serde(default)]
+ category: Option,
static_url: String,
visible_in_picker: Option,
}
@@ -63,7 +66,7 @@ struct Emojo {
struct Output {
instance: String,
show_animated: bool,
- emojo: Vec,
+ emojo: BTreeMap>,
}
#[get("/?&")]
@@ -97,10 +100,16 @@ async fn instance(
emojo.retain(|x| x.visible_in_picker.unwrap_or(true));
}
+ let mut emojo_by_category: BTreeMap> = BTreeMap::new();
+ for emoj in emojo {
+ let category = emoj.category.clone().unwrap_or("(No category)".to_string());
+ emojo_by_category.entry(category).or_default().push(emoj);
+ }
+
Ok(Html(Output {
instance,
show_animated,
- emojo,
+ emojo: emojo_by_category,
}))
}
diff --git a/templates/emojo.html b/templates/emojo.html
index ecab656..3d8a5f1 100644
--- a/templates/emojo.html
+++ b/templates/emojo.html
@@ -5,23 +5,24 @@
{{ instance }} emojo list
click/touch to copy to clipboard
-
- {% if show_animated %}
- {% for emoj in emojo %}
-
-
-
- :{{ emoj.shortcode }}:
-
+{% for category in emojo.keys() %}
+ {{ category }}
+
+ {% for emoj in emojo[category] %}
+ {% if show_animated %}
+
+
+
- :{{ emoj.shortcode }}:
+
+ {% else %}
+
+
+
- :{{ emoj.shortcode }}:
+
+ {% endif %}
{% endfor %}
- {% else %}
- {% for emoj in emojo %}
-
-
-
- :{{ emoj.shortcode }}:
-
- {% endfor %}
- {% endif %}
-
+
+{% endfor %}
{% endblock body %}
{% block script %}