dashboard for your PDS

feat: setup

ptr.pet 2cec1c94 3380d75f

verified
Changed files
+143 -43
.cargo
src
+11 -1
.cargo/config.toml
···
[target.x86_64-unknown-linux-gnu]
linker = "clang"
-
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
+
rustflags = [
+
"-C",
+
"link-arg=-fuse-ld=lld",
+
"-Zshare-generics=n",
+
"-Zthreads=0",
+
]
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
+
rustdocflags = ["-Clinker=rust-lld.exe"]
+
rustflags = [
+
"-Zshare-generics=n",
+
"-Zthreads=0",
+
]
[unstable]
codegen-backend = true
+19 -37
Cargo.lock
···
]
[[package]]
+
name = "fun-html"
+
version = "1.8.0"
+
source = "git+https://github.com/90-008/fun-html.git#04cdde83b4b548083712ad487e3310683785531c"
+
dependencies = [
+
"axum-core",
+
"html-escape",
+
]
+
+
[[package]]
name = "futures-channel"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
···
]
[[package]]
-
name = "hypertext"
-
version = "0.12.1"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "eb73b82c6a76434fd87a0668ef3ff1a8182512dfb610eef9138169a7e2d3a0ed"
-
dependencies = [
-
"axum-core",
-
"html-escape",
-
"hypertext-macros",
-
"itoa",
-
"ryu",
-
]
-
-
[[package]]
-
name = "hypertext-macros"
-
version = "0.12.1"
-
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "c120534b9d41bd317a5b111aacc38a34071d15df9462c0e21f6093ade3a03660"
-
dependencies = [
-
"html-escape",
-
"proc-macro2",
-
"quote",
-
"syn",
-
]
-
-
[[package]]
name = "icu_collections"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
···
[[package]]
name = "regex"
-
version = "1.11.1"
+
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
+
checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912"
dependencies = [
"aho-corasick",
"memchr",
-
"regex-automata 0.4.9",
-
"regex-syntax 0.8.5",
+
"regex-automata 0.4.10",
+
"regex-syntax 0.8.6",
[[package]]
···
[[package]]
name = "regex-automata"
-
version = "0.4.9"
+
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
+
checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6"
dependencies = [
"aho-corasick",
"memchr",
-
"regex-syntax 0.8.5",
+
"regex-syntax 0.8.6",
[[package]]
···
[[package]]
name = "regex-syntax"
-
version = "0.8.5"
+
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
+
checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001"
[[package]]
name = "reqwest"
···
"anyhow",
"axum",
"axum-htmx",
-
"hypertext",
+
"fun-html",
"reqwest",
"scc",
-
"serde",
-
"serde_json",
"smol_str",
"tikv-jemallocator",
"tokio",
+7 -3
Cargo.toml
···
+
cargo-features = ["codegen-backend"]
+
[package]
name = "sightline"
version = "0.1.0"
···
smol_str = { version = "0.3", features = ["serde"] }
scc = "2"
ahash = { version = "0.8", features = ["serde"] }
-
serde = { version = "1", features = ["derive"] }
-
serde_json = "1"
-
hypertext = { version = "0.12", features = ["axum", "htmx"] }
+
fun-html = { git = "https://github.com/90-008/fun-html.git", features = ["axum"] }
[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.6"
+
+
[profile.dev]
+
debug = 0
+
strip = "debuginfo"
+45 -2
src/main.rs
···
-
fn main() {
-
println!("Hello, world!");
+
use std::{net::SocketAddr, sync::Arc};
+
+
use tracing::Level;
+
use tracing_subscriber::EnvFilter;
+
+
use crate::state::AppState;
+
+
pub mod router;
+
pub mod state;
+
pub mod templates;
+
+
#[tokio::main]
+
async fn main() {
+
tracing_subscriber::fmt::fmt()
+
.with_env_filter(
+
EnvFilter::builder()
+
.with_default_directive(Level::INFO.into())
+
.from_env_lossy(),
+
)
+
.compact()
+
.init();
+
+
let addr = SocketAddr::from((
+
[0, 0, 0, 0],
+
std::env::var("PORT")
+
.ok()
+
.and_then(|s| s.parse::<u16>().ok())
+
.unwrap_or(3713),
+
));
+
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
+
+
let state = Arc::new(AppState::new());
+
let app = router::build(state);
+
+
tracing::info!("hi! serving on {addr}... (^_^)");
+
tokio::select! {
+
res = axum::serve(listener, app) => {
+
if let Err(e) = res {
+
tracing::error!("oops: serve failed: {e}! (@,@)");
+
}
+
}
+
_ = tokio::signal::ctrl_c() => {
+
tracing::info!("received ctrl-c! bye bye... (T.T)/");
+
}
+
}
}
+13
src/router/index.rs
···
+
use std::sync::Arc;
+
+
use axum::{
+
extract::State,
+
response::{Html, IntoResponse},
+
};
+
use fun_html::elt::text;
+
+
use crate::{state::AppState, templates::document};
+
+
pub async fn handle(state: State<Arc<AppState>>) -> impl IntoResponse {
+
Html(document::tmpl(text("meow")))
+
}
+13
src/router/mod.rs
···
+
use std::sync::Arc;
+
+
use axum::{Router, routing::get};
+
+
use crate::state::AppState;
+
+
pub mod index;
+
+
pub fn build(state: Arc<AppState>) -> Router {
+
Router::new()
+
.route("/", get(index::handle))
+
.with_state(state)
+
}
+11
src/state.rs
···
+
pub struct AppState {
+
pub http: reqwest::Client,
+
}
+
+
impl AppState {
+
pub fn new() -> Self {
+
Self {
+
http: reqwest::Client::new(),
+
}
+
}
+
}
+23
src/templates/document.rs
···
+
use fun_html::{Document, Element, attr::*, conv::*, html};
+
+
const HTMX_SRC: &str = "https://unpkg.com/htmx.org@2";
+
const MATCHA_SRC: &str = "https://matcha.mizu.sh/matcha.lite.css";
+
+
pub fn tmpl(children: Element) -> Document {
+
html(
+
[lang("en")],
+
[
+
head([
+
title("sightline"),
+
meta(charset_utf8()),
+
meta([
+
name("viewport"),
+
content("width=device-width, initial-scale=1.0"),
+
]),
+
script(HTMX_SRC),
+
link_stylesheet(MATCHA_SRC),
+
]),
+
body(children),
+
],
+
)
+
}
+1
src/templates/mod.rs
···
+
pub mod document;