Typstify /text endpoint
This commit is contained in:
parent
6112a8c02f
commit
98071dfe32
6 changed files with 30 additions and 73 deletions
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
#let data = json("data.json")
|
||||
|
||||
#if data.at("force_wrap", default: false) {
|
||||
#if data.force_wrap {
|
||||
show regex("."): it => it + sym.zws
|
||||
data.text
|
||||
} else { data.text }
|
||||
|
||||
#if data.at("feed", default: false) {
|
||||
#if data.feed {
|
||||
lib.feed
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
use axum::{Form, extract::State};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use showbits_typst::Typst;
|
||||
|
||||
use crate::{
|
||||
drawer::{Command, NewTypstDrawing},
|
||||
server::Server,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Text {
|
||||
pub struct Data {
|
||||
pub text: String,
|
||||
#[serde(default)]
|
||||
pub force_wrap: bool,
|
||||
|
|
@ -10,10 +15,13 @@ pub struct Text {
|
|||
pub feed: bool,
|
||||
}
|
||||
|
||||
impl From<Text> for Typst {
|
||||
fn from(value: Text) -> Self {
|
||||
super::typst_with_lib()
|
||||
.with_json("/data.json", &value)
|
||||
.with_main_file(include_str!("main.typ"))
|
||||
}
|
||||
pub async fn post(server: State<Server>, request: Form<Data>) {
|
||||
let typst = super::typst_with_lib()
|
||||
.with_json("/data.json", &request.0)
|
||||
.with_main_file(include_str!("main.typ"));
|
||||
|
||||
let _ = server
|
||||
.tx
|
||||
.send(Command::draw(NewTypstDrawing::new(typst)))
|
||||
.await;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue