main
Pantonshire 4 years ago
parent 81f6998b4e
commit 2d9d19d5cd

1
Cargo.lock generated

@ -168,6 +168,7 @@ dependencies = [
"libshire",
"maud",
"miette",
"mime",
"notify",
"pulldown-cmark",
"rss",

@ -13,6 +13,8 @@ axum = "0.5"
# Middleware for the web server
tower = { version = "0.4", features = ["limit"] }
tower-http = { version = "0.3", features = ["fs", "trace"] }
# MIME type implementation
mime = "0.3"
# Compile-time HTTP templating
maud = "0.23"
# Serialisation for RSS and Atom

@ -27,6 +27,8 @@ pub struct Config {
#[knuffel(child, unwrap(argument))]
static_dir: PathBuf,
#[knuffel(child, unwrap(argument))]
favicon_dir: PathBuf,
#[knuffel(child, unwrap(argument))]
posts_dir: PathBuf,
#[knuffel(child, unwrap(argument))]
post_media_dir: PathBuf,

@ -131,9 +131,17 @@ impl IntoResponse for Html {
html {
head {
meta charset="utf-8";
meta name="robots" content=(self.crawler_hints);
meta name="viewport" content="width=device-width, initial-scale=1";
title { (self.title) }
link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png";
link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png";
link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png";
link rel="manifest" href="/site.webmanifest";
@if let Some(head) = self.head {
(head)
}

@ -33,13 +33,20 @@ pub fn service(
{
Router::new()
.route("/", get(index::handle))
.route("/rss.xml", get(rss::handle))
.route("/atom.xml", get(atom::handle))
.route("/contact", get(contact::handle))
.route("/articles", get(posts_list::handle))
.route("/rss.xml", get(rss::handle))
.route("/atom.xml", get(atom::handle))
.route("/articles/:post_id", get(post::handle))
.nest("/static", static_content::service(&config.static_dir))
.nest("/article_media", static_content::service(&config.post_media_dir))
.route("/favicon.ico", static_content::file_service(&config.favicon_dir.join("favicon.ico"), None))
.route("/favicon-16x16.png", static_content::file_service(&config.favicon_dir.join("favicon-16x16.png"), None))
.route("/favicon-32x32.png", static_content::file_service(&config.favicon_dir.join("favicon-32x32.png"), None))
.route("/apple-touch-icon.png", static_content::file_service(&config.favicon_dir.join("apple-touch-icon.png"), None))
.route("/android-chrome-192x192.png", static_content::file_service(&config.favicon_dir.join("android-chrome-192x192.png"), None))
.route("/android-chrome-512x512.png", static_content::file_service(&config.favicon_dir.join("android-chrome-512x512.png"), None))
.route("/site.webmanifest", static_content::file_service(&config.favicon_dir.join("site.webmanifest"), None))
.nest("/static", static_content::dir_service(&config.static_dir))
.nest("/article_media", static_content::dir_service(&config.post_media_dir))
.fallback(handle_fallback.into_service())
.layer(ConcurrencyLimitLayer::new(config.concurrency_limit))
.layer(TraceLayer::new_for_http())

@ -11,18 +11,29 @@ use axum::{
routing::{get_service, MethodRouter},
};
use libshire::convert::Empty;
use mime::Mime;
use tower::ServiceExt;
use tower_http::services::ServeDir;
use tower_http::services::{ServeDir, ServeFile};
use tracing::{info, error};
use super::response::Error;
pub fn service(static_dir: &Path) -> MethodRouter<Body, Infallible> {
pub fn file_service(file_path: &Path, mime: Option<&Mime>) -> MethodRouter<Body, Infallible> {
let serve_file = match mime {
Some(mime) => ServeFile::new_with_mime(file_path, mime),
None => ServeFile::new(file_path),
};
get_service(serve_file)
.handle_error(handle_error)
}
pub fn dir_service(dir_path: &Path) -> MethodRouter<Body, Infallible> {
let fallback_service = handle_fallback
.into_service()
.map_err(Empty::elim::<io::Error>);
let serve_dir = ServeDir::new(static_dir)
let serve_dir = ServeDir::new(dir_path)
.fallback(fallback_service);
get_service(serve_dir)

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
Loading…
Cancel
Save