Compare commits

...

10 Commits

Author SHA1 Message Date
Kay Faraday e8ee2850aa display by category 2024-07-23 01:31:44 +00:00
Kay Faraday 4a3ee534ca update source code links 2024-07-23 01:31:18 +00:00
Kay Faraday 2644cc7f5a remove /code 2024-07-23 01:30:59 +00:00
iliana etaoin 85823d3ade cargo update 2024-04-20 09:17:37 -07:00
iliana etaoin f9f89fdce9 cargo update (rocket v0.5!!) 2023-11-17 12:47:50 -08:00
iliana etaoin fdaf025192 cargo update 2023-09-24 10:49:58 -07:00
iliana etaoin 5986f2b1a5 cargo update 2023-07-06 23:45:16 -07:00
iliana etaoin db35bd0048 cargo update 2023-05-21 13:56:58 -07:00
iliana etaoin 95bc8085cf
Merge pull request #29 from sean-clayton/main
Add IDs to inputs
2023-05-21 13:55:25 -07:00
🎷🐢 S. P. O. Clayton b5c3bafc0b
Add IDs to inputs 2023-05-20 11:25:12 -04:00
8 changed files with 741 additions and 533 deletions

1155
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
name = "emojos-dot-in"
version = "2.0.0"
edition = "2021"
rust-version = "1.73" # kept in sync with nixos stable
license = "AGPL-3.0-or-later"
description = "Shows custom emoji for Mastodon/Pleroma instances"
homepage = "https://emojos.in"
@ -11,8 +12,8 @@ include = ["/build.rs", "/src", "/static", "/templates", "/LICENSE", ".gitignore
[dependencies]
askama = { version = "0.12", default-features = false }
reqwest = { version = "0.11", features = ["gzip", "brotli", "deflate", "json"] }
rocket = { version = "0.5.0-rc.3", default-features = false }
reqwest = { version = "0.12", features = ["gzip", "brotli", "deflate", "json"] }
rocket = { version = "0.5", default-features = false }
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["rt-multi-thread"] }

View File

@ -1,33 +0,0 @@
use std::fs::File;
use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;
use zip::ZipWriter;
fn main() {
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let output = Command::new("cargo")
.args(["package", "--list", "--allow-dirty"])
.output()
.unwrap();
if !output.status.success() {
panic!("cargo package failed");
}
let mut writer = ZipWriter::new(File::create(out_dir.join("source.zip")).unwrap());
for path in String::from_utf8(output.stdout).unwrap().lines() {
if path == "Cargo.toml.orig" {
continue;
}
writer.start_file(path, Default::default()).unwrap();
io::copy(
&mut File::open(Path::new(env!("CARGO_MANIFEST_DIR")).join(path)).unwrap(),
&mut writer,
)
.unwrap();
}
writer.finish().unwrap();
}

View File

@ -13,12 +13,13 @@ 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() -> _ {
let client = Client::builder()
.user_agent(format!(
"emojos.in/{} (+https://github.com/iliana/emojos.in)",
"emojos.in/{} (+https://lab.freak.university/FreakU/emojos)",
env!("CARGO_PKG_VERSION")
))
.build()
@ -28,7 +29,6 @@ fn rocket() -> _ {
"/",
routes![
instance,
trivial::code,
trivial::copy_js,
trivial::css,
trivial::favicon_ico,
@ -55,6 +55,8 @@ impl<T: Template> Responder<'_, 'static> for Html<T> {
struct Emojo {
shortcode: String,
url: String,
#[serde(default)]
category: Option<String>,
static_url: String,
visible_in_picker: Option<bool>,
}
@ -64,7 +66,7 @@ struct Emojo {
struct Output {
instance: String,
show_animated: bool,
emojo: Vec<Emojo>,
emojo: BTreeMap<String, Vec<Emojo>>,
}
#[get("/<instance>?<show_all>&<show_animated>")]
@ -98,10 +100,16 @@ async fn instance(
emojo.retain(|x| x.visible_in_picker.unwrap_or(true));
}
let mut emojo_by_category: BTreeMap<String, Vec<Emojo>> = 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,
}))
}

View File

@ -3,9 +3,9 @@
use crate::Html;
use askama::Template;
use rocket::form::{Form, FromForm};
use rocket::http::{Header, Status};
use rocket::http::Status;
use rocket::response::content::{RawCss, RawJavaScript};
use rocket::response::{status::NoContent, Redirect, Responder};
use rocket::response::{status::NoContent, Redirect};
use rocket::{get, post, uri};
#[derive(Template)]
@ -33,24 +33,6 @@ pub(crate) fn instance_form(form: Form<InstanceForm<'_>>) -> Redirect {
)))
}
#[derive(Responder)]
#[response(content_type = "application/zip")]
pub(crate) struct Code {
zip: &'static [u8],
disposition: Header<'static>,
}
#[get("/code")]
pub(crate) fn code() -> Code {
Code {
zip: include_bytes!(concat!(env!("OUT_DIR"), "/source.zip")),
disposition: Header::new(
"content-disposition",
r#"attachment; filename="emojos.in.zip""#,
),
}
}
#[get("/static/site.css")]
pub(crate) fn css() -> RawCss<&'static [u8]> {
RawCss(include_bytes!("site.css"))

View File

@ -10,13 +10,11 @@
{% endblock body %}
<footer>
<p>
emojos.in by iliana
emojos.in by iliana &amp; kay
&middot;
AGPLv3
&middot;
<a href="/code">source code download</a>
&middot;
<a href="https://github.com/iliana/emojos.in">github</a>
<a href="https://lab.freak.university/FreakU/emojos">source code</a>
</p>
</footer>
{% block script %}

View File

@ -5,23 +5,24 @@
<b>{{ instance }}</b> emojo list<br>
click/touch to copy to clipboard
</p>
<dl class="emojo">
{% if show_animated %}
{% for emoj in emojo %}
<div>
<dt><img src="{{ emoj.url }}" alt=":{{ emoj.shortcode }}:" loading=lazy></dt>
<dd>:{{ emoj.shortcode }}:</dd>
</div>
{% for category in emojo.keys() %}
<h2 id={{ category }}>{{ category }}</h2>
<dl class="emojo">
{% for emoj in emojo[category] %}
{% if show_animated %}
<div>
<dt><img src="{{ emoj.url }}" alt=":{{ emoj.shortcode }}:" loading=lazy></dt>
<dd>:{{ emoj.shortcode }}:</dd>
</div>
{% else %}
<div>
<dt><img src="{{ emoj.static_url }}" alt=":{{ emoj.shortcode }}:" loading=lazy></dt>
<dd>:{{ emoj.shortcode }}:</dd>
</div>
{% endif %}
{% endfor %}
{% else %}
{% for emoj in emojo %}
<div>
<dt><img src="{{ emoj.static_url }}" alt=":{{ emoj.shortcode }}:" loading=lazy></dt>
<dd>:{{ emoj.shortcode }}:</dd>
</div>
{% endfor %}
{% endif %}
</dl>
</dl>
{% endfor %}
{% endblock body %}
{% block script %}
<script src="/static/copy.js"></script>

View File

@ -7,11 +7,11 @@
<input type="text" name="instance" placeholder="instance.domain">
</div>
<div>
<input type="checkbox" name="show_all">
<input type="checkbox" id="show_all" name="show_all">
<label for="show_all">See unlisted emojos</label>
</div>
<div>
<input type="checkbox" name="show_animated">
<input type="checkbox" id="show_animated" name="show_animated">
<label for="show_animated">See animated emojos</label>
</div>
<input type="submit" value="go">