Serve static files (e.g css)
This commit is contained in:
parent
1ad416634d
commit
c43cf8b261
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -1130,6 +1130,16 @@ version = "0.3.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
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]]
|
[[package]]
|
||||||
name = "minimal-lexical"
|
name = "minimal-lexical"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
@ -2199,7 +2209,10 @@ dependencies = [
|
||||||
"http",
|
"http",
|
||||||
"http-body",
|
"http-body",
|
||||||
"http-range-header",
|
"http-range-header",
|
||||||
|
"httpdate",
|
||||||
"mime",
|
"mime",
|
||||||
|
"mime_guess",
|
||||||
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
|
@ -2277,6 +2290,15 @@ version = "0.1.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "abd2fc5d32b590614af8b0a20d837f32eca055edd0bbead59a9cfe80858be003"
|
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]]
|
[[package]]
|
||||||
name = "unicode-bidi"
|
name = "unicode-bidi"
|
||||||
version = "0.3.13"
|
version = "0.3.13"
|
||||||
|
|
|
@ -11,9 +11,9 @@ sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "sqlite" ]
|
||||||
serde = { version = "1.0.167", features = ["derive"] }
|
serde = { version = "1.0.167", features = ["derive"] }
|
||||||
tokio = { version = "1.29.1", features = ["full"] }
|
tokio = { version = "1.29.1", features = ["full"] }
|
||||||
maud = { version = "*", features = ["axum"] }
|
maud = { version = "*", features = ["axum"] }
|
||||||
tower = "0.4.13"
|
tower = { version = "0.4.13", features = ["util"] }
|
||||||
hyper = { version = "0.14", features = ["full"] }
|
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"
|
sha2 = "0.10.7"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
|
|
@ -18,5 +18,6 @@ WORKDIR /app
|
||||||
COPY --from=builder /usr/src/app/gabrielsimmerdotcom /app/gabrielsimmerdotcom
|
COPY --from=builder /usr/src/app/gabrielsimmerdotcom /app/gabrielsimmerdotcom
|
||||||
COPY litefs.yml /etc
|
COPY litefs.yml /etc
|
||||||
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
|
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
|
ENTRYPOINT litefs mount
|
37
assets/styles.css
Normal file
37
assets/styles.css
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -47,11 +47,11 @@
|
||||||
"rust-analyzer-src": []
|
"rust-analyzer-src": []
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1689747703,
|
"lastModified": 1689834114,
|
||||||
"narHash": "sha256-abwTXTz2u2P32fN9XRQKV+TUkcRZDfNIQ73mq9fyTxg=",
|
"narHash": "sha256-btRpL43gvbP+5+gHjaaeZ9Uv6x8LkjaO1kyvEN5rQTE=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "fenix",
|
"repo": "fenix",
|
||||||
"rev": "5e70fbab6c431bd8454d336ef06ef609f4d6e6f3",
|
"rev": "d55d856bcc50ae831f9355465f6a651034f6c8d4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -18,12 +18,13 @@ use axum::{
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use hyper::body::Bytes;
|
use hyper::body::Bytes;
|
||||||
use maud::{html, Markup};
|
use maud::{html, Markup, DOCTYPE};
|
||||||
use orgize::Org;
|
use orgize::Org;
|
||||||
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions};
|
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions};
|
||||||
use sqlx::{FromRow, Pool, Sqlite};
|
use sqlx::{FromRow, Pool, Sqlite};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CACHE: Mutex<HashMap<String, CachedPage>> = Mutex::new(HashMap::new());
|
static ref CACHE: Mutex<HashMap<String, CachedPage>> = Mutex::new(HashMap::new());
|
||||||
|
@ -66,6 +67,7 @@ async fn main() -> Result<(), sqlx::Error> {
|
||||||
.route("/", get(homepage))
|
.route("/", get(homepage))
|
||||||
.route("/blog", get(list_blog_posts))
|
.route("/blog", get(list_blog_posts))
|
||||||
.route("/blog/:post", get(blog_post))
|
.route("/blog/:post", get(blog_post))
|
||||||
|
.nest_service("/assets", ServeDir::new("assets"))
|
||||||
.layer(middleware::from_fn_with_state(state.clone(), cached_page))
|
.layer(middleware::from_fn_with_state(state.clone(), cached_page))
|
||||||
.with_state(state);
|
.with_state(state);
|
||||||
|
|
||||||
|
@ -80,16 +82,23 @@ async fn main() -> Result<(), sqlx::Error> {
|
||||||
|
|
||||||
async fn homepage() -> Markup {
|
async fn homepage() -> Markup {
|
||||||
html! {
|
html! {
|
||||||
|
(DOCTYPE)
|
||||||
|
meta charset="utf-8";
|
||||||
|
link rel="stylesheet" href="/assets/styles.css";
|
||||||
|
title { "Gabriel Simmer" }
|
||||||
|
main {
|
||||||
h1 { "Gabriel Simmer" }
|
h1 { "Gabriel Simmer" }
|
||||||
h2 { "Infrastructure and DevOps" }
|
h2 { "Infrastructure and DevOps" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn list_blog_posts() -> Markup {
|
async fn list_blog_posts() -> Markup {
|
||||||
let mut posts = Vec::new();
|
let mut posts = Vec::new();
|
||||||
for entry in fs::read_dir("./posts").unwrap() {
|
for entry in fs::read_dir("./posts").unwrap() {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
println!("{}", path.display());
|
||||||
let filename = path.file_name().unwrap().to_str().unwrap();
|
let filename = path.file_name().unwrap().to_str().unwrap();
|
||||||
let ext = path.extension().unwrap().to_str().unwrap();
|
let ext = path.extension().unwrap().to_str().unwrap();
|
||||||
// strip extension
|
// strip extension
|
||||||
|
|
Loading…
Reference in a new issue