Add static file serving with favicons

- Serve the "static" directory as static files.
- Add favicons.
This commit is contained in:
Matthew Gordon 2024-02-10 14:17:45 -04:00
parent 856482ce17
commit 5e90f3436a
11 changed files with 37 additions and 1 deletions

2
.cargo/config.toml Normal file
View File

@ -0,0 +1,2 @@
[env]
STATIC_FILE_PATH = { value = "static", relative = true }

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.png filter=lfs diff=lfs merge=lfs -text

View File

@ -10,3 +10,4 @@ tokio = { version = "1", features = ["rt-multi-thread"]}
axum = "0.7" axum = "0.7"
askama = "0.12" askama = "0.12"
askama_axum = "0.4" askama_axum = "0.4"
tower-http = { version = "0.5", features = ["fs"] }

View File

@ -1,9 +1,13 @@
use std::env;
use askama::Template; use askama::Template;
use axum::{routing::get, Router}; use axum::{routing::get, Router};
use tower_http::services::ServeDir;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = Router::new().route("/", get(root)); let app = Router::new()
.route("/", get(root))
.nest_service("/static", ServeDir::new(env::var("STATIC_FILE_PATH")?));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?; let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?; axum::serve(listener, app).await?;

BIN
static/favicon-16.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-167.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-180.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-192.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-32.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
static/favicon-48.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -4,6 +4,16 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<title>{{title}}</title> <title>{{title}}</title>
<link rel="icon" type="image/png" sizes="32x32" href="static/favicon-32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/favicon-16.png">
<!-- For Google and Android -->
<link rel="icon" type="image/png" sizes="48x48" href="static/favicon-48.png">
<link rel="icon" type="image/png" sizes="192x192" href="static/favicon-192.png">
<!-- For iPad -->
<link rel="apple-touch-icon" type="image/png" sizes="167x167" href="static/favicon-167.png">
<!-- For iPhone -->
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="static/favicon-180.png">
</head> </head>
<body> <body>
It still works! It still works!