hash statics
This commit is contained in:
parent
a45bf45015
commit
d925573629
12 changed files with 139 additions and 1464 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -2,5 +2,8 @@
|
||||||
e2e/node_modules
|
e2e/node_modules
|
||||||
e2e/playwright-report
|
e2e/playwright-report
|
||||||
e2e/test-results
|
e2e/test-results
|
||||||
some_user.db
|
/some_user.db
|
||||||
dbs
|
/dbs
|
||||||
|
/hashed_static
|
||||||
|
/users.db
|
||||||
|
/.sqlx
|
||||||
|
|
|
||||||
1461
Cargo.lock
generated
1461
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
66
Cargo.toml
66
Cargo.toml
|
|
@ -4,37 +4,37 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.100"
|
||||||
axum = { version = "0.8.6", features = ["macros", "form"] }
|
axum = { version = "0.8.6", features = ["macros", "form"] }
|
||||||
axum-extra = { version = "0.10.3", features = ["form"] }
|
axum-extra = { version = "0.10.3", features = ["form"] }
|
||||||
axum-htmx = "0.8.1"
|
axum-htmx = "0.8.1"
|
||||||
axum-login = "0.18.0"
|
axum-login = "0.18.0"
|
||||||
chrono = { version = "0.4.42", features = ["clock", "alloc"] }
|
cache_bust = { version = "0.2.0", features = ["macro"] }
|
||||||
clap = { version = "4.5.53", features = ["derive"] }
|
chrono = { version = "0.4.42", features = ["clock", "alloc"] }
|
||||||
http = "1.3.1"
|
clap = { version = "4.5.53", features = ["derive"] }
|
||||||
icalendar = "0.17.5"
|
http = "1.3.1"
|
||||||
itertools = "0.14.0"
|
icalendar = "0.17.5"
|
||||||
listenfd = "1.0.2"
|
itertools = "0.14.0"
|
||||||
markdown = "1.0.0"
|
listenfd = "1.0.2"
|
||||||
maud = { version = "0.27.0", features = ["axum"] }
|
markdown = "1.0.0"
|
||||||
password-auth = "1.0.0"
|
maud = { version = "0.27.0", features = ["axum"] }
|
||||||
radix_trie = "0.3.0"
|
password-auth = "1.0.0"
|
||||||
regex = "1.12.2"
|
radix_trie = "0.3.0"
|
||||||
rpassword = "7.4.0"
|
regex = "1.12.2"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
rpassword = "7.4.0"
|
||||||
serde_json = "1.0.145"
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
short-uuid = "0.2.0"
|
serde_json = "1.0.145"
|
||||||
sqlx = { version = "0.8", features = ["macros", "runtime-tokio", "sqlite", "tls-rustls"] }
|
short-uuid = "0.2.0"
|
||||||
thiserror = "2.0.17"
|
sqlx = { version = "0.8", features = ["macros", "runtime-tokio", "sqlite", "tls-rustls"] }
|
||||||
time = "0.3.44"
|
thiserror = "2.0.17"
|
||||||
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] }
|
time = "0.3.44"
|
||||||
tower-http = { version = "0.6.6", features = ["fs"] }
|
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] }
|
||||||
tower-sessions = { version = "0.14.0", features = ["signed"] }
|
tower-http = { version = "0.6.6", features = ["fs"] }
|
||||||
tower-sessions-sqlx-store = { version = "0.15.0", features = ["sqlite"] }
|
tower-sessions = { version = "0.14.0", features = ["signed"] }
|
||||||
tracing = "0.1.41"
|
tower-sessions-sqlx-store = { version = "0.15.0", features = ["sqlite"] }
|
||||||
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
tracing = "0.1.41"
|
||||||
vcard = "0.4.13"
|
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
|
||||||
|
vcard = "0.4.13"
|
||||||
|
|
||||||
[dev-dependencies]
|
[build-dependencies]
|
||||||
cargo-watch = "8.5.3"
|
cache_bust = "0.2.0"
|
||||||
systemfd = "0.4.6"
|
|
||||||
|
|
|
||||||
23
Taskfile
23
Taskfile
|
|
@ -16,18 +16,31 @@ refresh_sqlx_db() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_env() {
|
||||||
|
refresh_sqlx_db > /dev/null
|
||||||
|
DATABASE_URL=sqlite:some_user.db \
|
||||||
|
CACHE_BUST_ASSETS_DIR=static \
|
||||||
|
"$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
_cargo() {
|
||||||
|
_env cargo "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
edit() {
|
||||||
|
_env nvim
|
||||||
|
}
|
||||||
|
|
||||||
deploy_to_server() {
|
deploy_to_server() {
|
||||||
where="$1"
|
where="$1"
|
||||||
refresh_sqlx_db
|
_cargo build --release
|
||||||
env DATABASE_URL=sqlite:some_user.db cargo build --release
|
|
||||||
rsync -v -essh ./target/release/mascarpone "$where:~" \
|
rsync -v -essh ./target/release/mascarpone "$where:~" \
|
||||||
&& rsync -rav -essh ./static "$where:~" \
|
&& rsync -rav -essh ./hashed_static "$where:~/static" \
|
||||||
&& ssh -t "$where" "sudo mv -f mascarpone /usr/bin/ && sudo rm -rf /var/local/mascarpone/static && sudo mv -f static /var/local/mascarpone/ && sudo systemctl restart mascarpone"
|
&& ssh -t "$where" "sudo mv -f mascarpone /usr/bin/ && sudo rm -rf /var/local/mascarpone/static && sudo mv -f static /var/local/mascarpone/ && sudo systemctl restart mascarpone"
|
||||||
}
|
}
|
||||||
|
|
||||||
dev() {
|
dev() {
|
||||||
refresh_sqlx_db > /dev/null
|
_cargo run -- serve
|
||||||
env DATABASE_URL=sqlite:some_user.db cargo run -- serve
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"$@"
|
"$@"
|
||||||
|
|
|
||||||
9
build.rs
9
build.rs
|
|
@ -1,3 +1,12 @@
|
||||||
|
use cache_bust::CacheBust;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-changed=migrations");
|
println!("cargo:rerun-if-changed=migrations");
|
||||||
|
|
||||||
|
let cache_bust = CacheBust::builder()
|
||||||
|
.in_dir("static".to_owned())
|
||||||
|
.out_dir("hashed_static".to_owned())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
cache_bust.hash_dir().expect("Cache busting failed");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
[tools]
|
[tools]
|
||||||
"cargo:systemfd" = "latest"
|
|
||||||
"watchexec" = "latest"
|
|
||||||
"rust-analyzer" = "latest"
|
"rust-analyzer" = "latest"
|
||||||
"jj" = "latest"
|
"jj" = "latest"
|
||||||
"pnpm" = "latest"
|
"pnpm" = "latest"
|
||||||
|
|
|
||||||
13
src/main.rs
13
src/main.rs
|
|
@ -182,19 +182,12 @@ async fn serve(port: &u32) -> Result<(), anyhow::Error> {
|
||||||
.route_layer(login_required!(Backend, login_url = "/login"))
|
.route_layer(login_required!(Backend, login_url = "/login"))
|
||||||
.merge(auth::router())
|
.merge(auth::router())
|
||||||
.merge(ics::router())
|
.merge(ics::router())
|
||||||
.nest_service("/static", ServeDir::new("./static"))
|
.nest_service("/static", ServeDir::new("./hashed_static"))
|
||||||
.layer(auth_layer)
|
.layer(auth_layer)
|
||||||
.with_state(state);
|
.with_state(state);
|
||||||
|
|
||||||
let mut listenfd = listenfd::ListenFd::from_env();
|
let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).await?;
|
||||||
let listener = match listenfd.take_tcp_listener(0)? {
|
tracing::debug!("Starting axum on 0.0.0.0:{}...", port);
|
||||||
Some(listener) => {
|
|
||||||
listener.set_nonblocking(true)?;
|
|
||||||
TcpListener::from_std(listener)
|
|
||||||
}
|
|
||||||
None => TcpListener::bind(format!("0.0.0.0:{}", port)).await,
|
|
||||||
}?;
|
|
||||||
tracing::debug!("Starting axum on 0.0.0.0:3000...");
|
|
||||||
axum::serve(listener, app)
|
axum::serve(listener, app)
|
||||||
.with_graceful_shutdown(shutdown_signal(deletion_task.abort_handle()))
|
.with_graceful_shutdown(shutdown_signal(deletion_task.abort_handle()))
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use axum::{
|
||||||
response::{IntoResponse, Redirect},
|
response::{IntoResponse, Redirect},
|
||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
};
|
};
|
||||||
|
use cache_bust::asset;
|
||||||
use maud::{DOCTYPE, html};
|
use maud::{DOCTYPE, html};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
@ -78,8 +79,8 @@ mod get {
|
||||||
script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js" {}
|
script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js" {}
|
||||||
script src="https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4" integrity="sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg" crossorigin="anonymous" {}
|
script src="https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4" integrity="sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg" crossorigin="anonymous" {}
|
||||||
script src="https://cdn.jsdelivr.net/npm/alpinejs@3.15.0/dist/cdn.min.js" defer {}
|
script src="https://cdn.jsdelivr.net/npm/alpinejs@3.15.0/dist/cdn.min.js" defer {}
|
||||||
link rel="stylesheet" type="text/css" href="/static/index.css";
|
link rel="stylesheet" type="text/css" href=(format!("/static/{}", asset!("index.css")));
|
||||||
link rel="stylesheet" type="text/css" href="/static/login.css";
|
link rel="stylesheet" type="text/css" href=(format!("/static/{}", asset!("login.css")));
|
||||||
title { "Mascarpone" }
|
title { "Mascarpone" }
|
||||||
}
|
}
|
||||||
body hx-ext="response-targets" {
|
body hx-ext="response-targets" {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use axum::{
|
||||||
routing::{delete, get, post, put},
|
routing::{delete, get, post, put},
|
||||||
};
|
};
|
||||||
use axum_extra::extract::Form;
|
use axum_extra::extract::Form;
|
||||||
|
use cache_bust::asset;
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use maud::{Markup, PreEscaped, html};
|
use maud::{Markup, PreEscaped, html};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
@ -100,7 +101,7 @@ mod get {
|
||||||
.text_body;
|
.text_body;
|
||||||
|
|
||||||
Ok(layout.render(
|
Ok(layout.render(
|
||||||
Some(vec!["/static/contact.css", "/static/journal.css"]),
|
Some(vec![asset!("contact.css"), asset!("journal.css")]),
|
||||||
html! {
|
html! {
|
||||||
a href=(format!("/contact/{}/edit", contact_id)) { "Edit" }
|
a href=(format!("/contact/{}/edit", contact_id)) { "Edit" }
|
||||||
|
|
||||||
|
|
@ -210,7 +211,7 @@ mod get {
|
||||||
.text_body
|
.text_body
|
||||||
.unwrap_or(String::new());
|
.unwrap_or(String::new());
|
||||||
|
|
||||||
Ok(layout.render(Some(vec!["/static/contact.css"]), html! {
|
Ok(layout.render(Some(vec![asset!("contact.css")]), html! {
|
||||||
form hx-ext="response-targets" {
|
form hx-ext="response-targets" {
|
||||||
div {
|
div {
|
||||||
input type="button" value="Save" hx-put=(cid_url) hx-target-error="#error";
|
input type="button" value="Save" hx-put=(cid_url) hx-target-error="#error";
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
|
use cache_bust::asset;
|
||||||
use chrono::{Local, NaiveDate, TimeDelta};
|
use chrono::{Local, NaiveDate, TimeDelta};
|
||||||
use maud::{Markup, html};
|
use maud::{Markup, html};
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
|
|
@ -230,7 +231,7 @@ pub mod get {
|
||||||
.fetch_all(pool)
|
.fetch_all(pool)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(layout.render(
|
Ok(layout.render(
|
||||||
Some(vec!["/static/home.css", "/static/journal.css"]),
|
Some(vec![asset!("home.css"), asset!("journal.css")]),
|
||||||
html! {
|
html! {
|
||||||
(freshness_section(&freshens)?)
|
(freshness_section(&freshens)?)
|
||||||
(birthdays_section(&prev_birthdays, &upcoming_birthdays)?)
|
(birthdays_section(&prev_birthdays, &upcoming_birthdays)?)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use axum::RequestPartsExt;
|
use axum::RequestPartsExt;
|
||||||
use axum::extract::FromRequestParts;
|
use axum::extract::FromRequestParts;
|
||||||
// use axum::response::{IntoResponse, Redirect};
|
use cache_bust::asset;
|
||||||
use http::request::Parts;
|
use http::request::Parts;
|
||||||
use maud::{DOCTYPE, Markup, html};
|
use maud::{DOCTYPE, Markup, html};
|
||||||
use sqlx::FromRow;
|
use sqlx::FromRow;
|
||||||
|
|
@ -62,14 +62,14 @@ impl Layout {
|
||||||
(DOCTYPE)
|
(DOCTYPE)
|
||||||
html {
|
html {
|
||||||
head {
|
head {
|
||||||
link rel="stylesheet" type="text/css" href="/static/index.css";
|
link rel="stylesheet" type="text/css" href=(format!("/static/{}", asset!("index.css")));
|
||||||
meta name="viewport" content="width=device-width";
|
meta name="viewport" content="width=device-width";
|
||||||
script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js" {}
|
script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js" {}
|
||||||
script src="https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4" integrity="sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg" crossorigin="anonymous" {}
|
script src="https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.4" integrity="sha384-T41oglUPvXLGBVyRdZsVRxNWnOOqCynaPubjUVjxhsjFTKrFJGEMm3/0KGmNQ+Pg" crossorigin="anonymous" {}
|
||||||
script src="https://cdn.jsdelivr.net/npm/alpinejs@3.15.0/dist/cdn.min.js" defer {}
|
script src="https://cdn.jsdelivr.net/npm/alpinejs@3.15.0/dist/cdn.min.js" defer {}
|
||||||
@if let Some(hrefs) = css {
|
@if let Some(hrefs) = css {
|
||||||
@for href in hrefs {
|
@for href in hrefs {
|
||||||
link rel="stylesheet" type="text/css" href=(href);
|
link rel="stylesheet" type="text/css" href=(format!("/static/{}", href));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use axum::{
|
||||||
routing::{delete, get, post, put},
|
routing::{delete, get, post, put},
|
||||||
};
|
};
|
||||||
use axum_extra::extract::Form;
|
use axum_extra::extract::Form;
|
||||||
|
use cache_bust::asset;
|
||||||
use maud::{Markup, html};
|
use maud::{Markup, html};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
@ -61,7 +62,7 @@ mod get {
|
||||||
let ics_path: Option<String> = ics_path.0;
|
let ics_path: Option<String> = ics_path.0;
|
||||||
|
|
||||||
Ok(layout.render(
|
Ok(layout.render(
|
||||||
Some(vec!["static/settings.css"]),
|
Some(vec![asset!("settings.css")]),
|
||||||
html! {
|
html! {
|
||||||
h2 { "Birthdays Calendar URL" }
|
h2 { "Birthdays Calendar URL" }
|
||||||
(calendar_link(ics_path))
|
(calendar_link(ics_path))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue