Compare commits
10 Commits
e0152d4bb5
...
e8ee2850aa
Author | SHA1 | Date |
---|---|---|
Kay Faraday | e8ee2850aa | |
Kay Faraday | 4a3ee534ca | |
Kay Faraday | 2644cc7f5a | |
iliana etaoin | 85823d3ade | |
iliana etaoin | f9f89fdce9 | |
iliana etaoin | fdaf025192 | |
iliana etaoin | 5986f2b1a5 | |
iliana etaoin | db35bd0048 | |
iliana etaoin | 95bc8085cf | |
🎷🐢 S. P. O. Clayton | b5c3bafc0b |
File diff suppressed because it is too large
Load Diff
|
@ -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"] }
|
||||
|
||||
|
|
33
build.rs
33
build.rs
|
@ -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();
|
||||
}
|
16
src/main.rs
16
src/main.rs
|
@ -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,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -10,13 +10,11 @@
|
|||
{% endblock body %}
|
||||
<footer>
|
||||
<p>
|
||||
emojos.in by iliana
|
||||
emojos.in by iliana & kay
|
||||
·
|
||||
AGPLv3
|
||||
·
|
||||
<a href="/code">source code download</a>
|
||||
·
|
||||
<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 %}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in New Issue