Typstify /chat_message to /chat

This commit is contained in:
Joscha 2025-03-01 23:11:49 +01:00
parent 8bece23baf
commit de7ae63a5e
13 changed files with 93 additions and 153 deletions

View file

@ -0,0 +1,5 @@
{
"username": "John Argbuckle aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
"feed": false
}

View file

@ -0,0 +1 @@
../lib

View file

@ -0,0 +1,37 @@
#import "lib/main.typ" as lib;
#show: it => lib.init(it)
#let data = json("data.json")
#let max_width = 32 * 8pt + 4pt
#let limit_width(body) = context {
let width = measure(body).width
if width > max_width { box(body, width: max_width) } else { body }
}
// This way, the top line of the username box looks better.
#v(4pt)
#par(hanging-indent: 32pt)[
#limit_width(
box(
height: 10pt,
clip: true,
stroke: 1pt + black,
inset: (x: 2pt),
outset: (y: 3pt + .5pt, x: -.5pt),
{
// Ensure all characters that fit on the line are displayed on the line.
// We don't want a half-empty box.
show regex("."): it => it + sym.zws
data.username
},
),
)
#h(-4pt)
#data.content
]
#if data.feed {
lib.feed
}

View file

@ -0,0 +1,38 @@
use axum::{Form, extract::State};
use serde::{Deserialize, Serialize};
use crate::{
drawer::{Command, NewTypstDrawing},
server::Server,
};
#[derive(Serialize)]
struct Data {
username: String,
content: String,
feed: bool,
}
#[derive(Deserialize)]
pub struct FormData {
pub username: String,
pub content: String,
pub feed: Option<bool>,
}
pub async fn post(server: State<Server>, Form(form): Form<FormData>) {
let data = Data {
username: form.username,
content: form.content,
feed: form.feed.unwrap_or(false),
};
let typst = super::typst_with_lib()
.with_json("/data.json", &data)
.with_main_file(include_str!("main.typ"));
let _ = server
.tx
.send(Command::draw(NewTypstDrawing::new(typst)))
.await;
}