Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6cc71fa47 | ||
|
|
bbb19754bd | ||
|
|
c2e208a20b | ||
|
|
b157703162 | ||
|
|
ea07d11034 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1367,7 +1367,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "karnaugh"
|
name = "karnaugh"
|
||||||
version = "0.1.0"
|
version = "0.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "karnaugh"
|
name = "karnaugh"
|
||||||
version = "0.1.0"
|
version = "0.1.4"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -10,7 +10,7 @@ itertools = "0.14.0"
|
|||||||
tar = "0.4.44"
|
tar = "0.4.44"
|
||||||
time = "0.3.47"
|
time = "0.3.47"
|
||||||
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
|
||||||
tower-http = { version = "0.6.8", features = ["compression-br", "fs", "trace"] }
|
tower-http = { version = "0.6.8", features = ["compression-br", "fs", "trace", "set-header"] }
|
||||||
tracing = "0.1.43"
|
tracing = "0.1.43"
|
||||||
tracing-subscriber = "0.3.22"
|
tracing-subscriber = "0.3.22"
|
||||||
typst-html = { git = "https://github.com/mkorje/typst.git", branch = "mathml" }
|
typst-html = { git = "https://github.com/mkorje/typst.git", branch = "mathml" }
|
||||||
|
|||||||
12
flake.nix
12
flake.nix
@ -21,9 +21,9 @@
|
|||||||
rec {
|
rec {
|
||||||
packages.karnaugh = pkgs.rustPlatform.buildRustPackage (final: {
|
packages.karnaugh = pkgs.rustPlatform.buildRustPackage (final: {
|
||||||
pname = "karnaugh";
|
pname = "karnaugh";
|
||||||
version = "0.1.0";
|
version = "0.1.4";
|
||||||
src = self;
|
src = self;
|
||||||
cargoHash = "sha256-4jmvuQiQz5TCkY//L2qyx0AiDTxHu8EocFfysgaTaHU=";
|
cargoHash = "sha256-pwZOy+9cnpEskNf4HYC81UbXPJIOnUCtxEKzEVTrNyQ=";
|
||||||
});
|
});
|
||||||
packages.container = pkgs.dockerTools.buildImage {
|
packages.container = pkgs.dockerTools.buildImage {
|
||||||
name = "karnaugh";
|
name = "karnaugh";
|
||||||
@ -31,16 +31,16 @@
|
|||||||
|
|
||||||
copyToRoot = pkgs.buildEnv {
|
copyToRoot = pkgs.buildEnv {
|
||||||
name = "karnaugh-root";
|
name = "karnaugh-root";
|
||||||
paths = [packages.karnaugh];
|
paths = [ packages.karnaugh ];
|
||||||
pathsToLink = ["/bin"];
|
pathsToLink = [ "/bin" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
Cmd = ["/bin/karnaugh"];
|
Entrypoint = [ "/bin/karnaugh" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
packages.default = packages.karnaugh;
|
packages.default = packages.karnaugh;
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
cargo
|
cargo
|
||||||
|
|||||||
21
src/main.rs
21
src/main.rs
@ -8,7 +8,7 @@ use ::typst::syntax::VirtualPath;
|
|||||||
use axum::{
|
use axum::{
|
||||||
Router,
|
Router,
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
http::StatusCode,
|
http::{HeaderValue, StatusCode, header::CACHE_CONTROL},
|
||||||
response::{Html, IntoResponse, Response},
|
response::{Html, IntoResponse, Response},
|
||||||
routing::get,
|
routing::get,
|
||||||
};
|
};
|
||||||
@ -17,6 +17,7 @@ use itertools::Itertools;
|
|||||||
use tower_http::{
|
use tower_http::{
|
||||||
compression::CompressionLayer,
|
compression::CompressionLayer,
|
||||||
services::{ServeDir, ServeFile},
|
services::{ServeDir, ServeFile},
|
||||||
|
set_header::SetResponseHeaderLayer,
|
||||||
trace::TraceLayer,
|
trace::TraceLayer,
|
||||||
};
|
};
|
||||||
use tracing::{Level, info};
|
use tracing::{Level, info};
|
||||||
@ -97,19 +98,29 @@ async fn main() {
|
|||||||
let mut favicon = state.config.get_full_assets_path();
|
let mut favicon = state.config.get_full_assets_path();
|
||||||
favicon.push(PathBuf::from("favicon.svg"));
|
favicon.push(PathBuf::from("favicon.svg"));
|
||||||
|
|
||||||
|
let assets_service = ServeDir::new(state.config.get_full_assets_path());
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(root_handler))
|
.route("/", get(root_handler))
|
||||||
.route("/{*path}", get(typst_handler))
|
.route("/{*path}", get(typst_handler))
|
||||||
.route_service("/favicon.ico", ServeFile::new(favicon))
|
.route_service("/favicon.ico", ServeFile::new(favicon))
|
||||||
.nest_service("/assets", ServeDir::new(&state.config.assets_root))
|
.nest_service("/assets", assets_service)
|
||||||
.with_state(state.clone())
|
.with_state(state.clone())
|
||||||
.layer(TraceLayer::new_for_http())
|
.layer(TraceLayer::new_for_http())
|
||||||
.layer(CompressionLayer::new());
|
.layer(CompressionLayer::new())
|
||||||
|
.layer(SetResponseHeaderLayer::overriding(
|
||||||
|
CACHE_CONTROL,
|
||||||
|
HeaderValue::from_static("public, max-age=86400, immutable"),
|
||||||
|
));
|
||||||
|
|
||||||
let socket = SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), state.config.port);
|
let socket = SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), state.config.port);
|
||||||
info!("Serving Karnaugh on socket {}", socket);
|
info!("Serving Karnaugh on socket {}", socket);
|
||||||
let listener = tokio::net::TcpListener::bind(socket).await.unwrap();
|
let listener = tokio::net::TcpListener::bind(socket)
|
||||||
axum::serve(listener, app).await.unwrap();
|
.await
|
||||||
|
.expect(&format!("Failed to bind to socket {}", socket));
|
||||||
|
axum::serve(listener, app)
|
||||||
|
.await
|
||||||
|
.expect("Failed to serve site");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn root_handler(State(state): State<AppState>) -> impl IntoResponse {
|
async fn root_handler(State(state): State<AppState>) -> impl IntoResponse {
|
||||||
|
|||||||
@ -138,7 +138,10 @@ impl<'a> DocumentWorld<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_package(&self, spec: &PackageSpec) -> PackageResult<PathBuf> {
|
fn get_package(&self, spec: &PackageSpec) -> PackageResult<PathBuf> {
|
||||||
let path = get_package_path(&VirtualPath::new("").unwrap(), spec);
|
let path = get_package_path(
|
||||||
|
&VirtualPath::new("").expect("Failed to create empty virtual path"),
|
||||||
|
spec,
|
||||||
|
);
|
||||||
let path = path.realize(&self.context.config.packages_root);
|
let path = path.realize(&self.context.config.packages_root);
|
||||||
|
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
@ -177,6 +180,9 @@ impl<'a> DocumentWorld<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_package_path(file_path: &VirtualPath, spec: &PackageSpec) -> VirtualPath {
|
fn get_package_path(file_path: &VirtualPath, spec: &PackageSpec) -> VirtualPath {
|
||||||
let package_path = VirtualPath::new(format!("{}/{}", spec.name, spec.version)).unwrap();
|
let package_path = VirtualPath::new(format!("{}/{}", spec.name, spec.version))
|
||||||
package_path.join(file_path.get_without_slash()).unwrap()
|
.expect("Failed to create virtual path representing package path.");
|
||||||
|
package_path
|
||||||
|
.join(file_path.get_without_slash())
|
||||||
|
.expect("Failed to join file path into package path.")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user