diff --git a/Cargo.lock b/Cargo.lock index b2de02a..cd80199 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,6 +1130,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2199,7 +2209,10 @@ dependencies = [ "http", "http-body", "http-range-header", + "httpdate", "mime", + "mime_guess", + "percent-encoding", "pin-project-lite", "tokio", "tokio-util", @@ -2277,6 +2290,15 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abd2fc5d32b590614af8b0a20d837f32eca055edd0bbead59a9cfe80858be003" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.13" diff --git a/Cargo.toml b/Cargo.toml index 2b7e1d3..01aae5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,9 @@ sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "sqlite" ] serde = { version = "1.0.167", features = ["derive"] } tokio = { version = "1.29.1", features = ["full"] } maud = { version = "*", features = ["axum"] } -tower = "0.4.13" +tower = { version = "0.4.13", features = ["util"] } hyper = { version = "0.14", features = ["full"] } -tower-http = { version = "0.4.1", features = ["add-extension", "auth", "compression-full", "trace"] } +tower-http = { version = "0.4.1", features = ["fs", "add-extension", "auth", "compression-full", "trace"] } sha2 = "0.10.7" hex = "0.4" lazy_static = "1.4.0" diff --git a/Dockerfile b/Dockerfile index c4041d6..4dab1e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,5 +18,6 @@ WORKDIR /app COPY --from=builder /usr/src/app/gabrielsimmerdotcom /app/gabrielsimmerdotcom COPY litefs.yml /etc COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs +COPY --from=builder /usr/src/app/posts/ /app/posts/ ENTRYPOINT litefs mount \ No newline at end of file diff --git a/assets/styles.css b/assets/styles.css new file mode 100644 index 0000000..46fc9a1 --- /dev/null +++ b/assets/styles.css @@ -0,0 +1,37 @@ +:root { + --background-colour: #fff; + --text-colour: #222; + --php: rgb(136, 146, 191); + --javascript: #83CD29; + --go: #00ADD8; + --flutter: #02569B; + --clojure: #62B132; + --rust: #DEA584; + --python: #4584B6; + --svelte: #ff3e00; +} + +@media (prefers-color-scheme: dark) { + :root { + --background-colour: #202225; + --text-colour: #dcddde; + --flutter: #0175C2; + --python: #FFDE57; + } +} + +body { + font-family: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif; color: var(--text-colour); + font-weight: 400; + background-color: var(--background-colour); +} + +main { + margin: auto; + padding: 2rem; + max-width: 38rem; +} + +h1, h2 { + font-weight: 500; +} diff --git a/flake.lock b/flake.lock index 9dea5f5..2755e26 100644 --- a/flake.lock +++ b/flake.lock @@ -47,11 +47,11 @@ "rust-analyzer-src": [] }, "locked": { - "lastModified": 1689747703, - "narHash": "sha256-abwTXTz2u2P32fN9XRQKV+TUkcRZDfNIQ73mq9fyTxg=", + "lastModified": 1689834114, + "narHash": "sha256-btRpL43gvbP+5+gHjaaeZ9Uv6x8LkjaO1kyvEN5rQTE=", "owner": "nix-community", "repo": "fenix", - "rev": "5e70fbab6c431bd8454d336ef06ef609f4d6e6f3", + "rev": "d55d856bcc50ae831f9355465f6a651034f6c8d4", "type": "github" }, "original": { diff --git a/src/main.rs b/src/main.rs index 40e954d..9f02626 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,12 +18,13 @@ use axum::{ Router, }; use hyper::body::Bytes; -use maud::{html, Markup}; +use maud::{html, Markup, DOCTYPE}; use orgize::Org; use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions}; use sqlx::{FromRow, Pool, Sqlite}; use tokio::sync::Mutex; use clap::Parser; +use tower_http::services::ServeDir; lazy_static! { static ref CACHE: Mutex> = Mutex::new(HashMap::new()); @@ -66,6 +67,7 @@ async fn main() -> Result<(), sqlx::Error> { .route("/", get(homepage)) .route("/blog", get(list_blog_posts)) .route("/blog/:post", get(blog_post)) + .nest_service("/assets", ServeDir::new("assets")) .layer(middleware::from_fn_with_state(state.clone(), cached_page)) .with_state(state); @@ -80,8 +82,14 @@ async fn main() -> Result<(), sqlx::Error> { async fn homepage() -> Markup { html! { - h1 { "Gabriel Simmer" } - h2 { "Infrastructure and DevOps" } + (DOCTYPE) + meta charset="utf-8"; + link rel="stylesheet" href="/assets/styles.css"; + title { "Gabriel Simmer" } + main { + h1 { "Gabriel Simmer" } + h2 { "Infrastructure and DevOps" } + } } } @@ -90,6 +98,7 @@ async fn list_blog_posts() -> Markup { for entry in fs::read_dir("./posts").unwrap() { let entry = entry.unwrap(); let path = entry.path(); + println!("{}", path.display()); let filename = path.file_name().unwrap().to_str().unwrap(); let ext = path.extension().unwrap().to_str().unwrap(); // strip extension