diff --git a/src/blog.rs b/src/blog.rs index abf7d19f745369a0a9d37d59d5ad0be3c4bfc5c3..35d3e94ab51fb0d4b273895ef2f033742d82fb72 100644 --- a/src/blog.rs +++ b/src/blog.rs @@ -68,7 +68,7 @@ impl TryFrom<Blog> for RenderedBlog { pages.insert( "/style.css".to_string(), - Response::html(include_str!("assets/style.css").to_string()), + Response::css(include_str!("assets/style.css").to_string()), ); let home = b.home()?; @@ -97,6 +97,6 @@ impl TryFrom<Blog> for RenderedBlog { fn dress_page(title: &str, content: &str) -> String { format!( - r#"<html><head><link rel="stylesheet" href="/style.css" /><title>{title}</title></head><body><a href="/">Home</a><hr>{content}</body></html>"# + r#"<!DOCTYPE html><html><head><link rel="stylesheet" href="/style.css" /><title>{title}</title></head><body><a href="/">Home</a><hr>{content}</body></html>"# ) } diff --git a/src/misc.rs b/src/misc.rs index b62d64c16c804d5911d0e5270b2b4b6c831600d4..5330415d80c6e2e77202d5c84ed819e489eaecfa 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -1,6 +1,6 @@ use std::{fs::File, io::Read}; -use anyhow::Context; +use anyhow::{bail, Context}; use crate::{load::Loadable, resp::Response, util::slugify}; @@ -19,6 +19,12 @@ impl Loadable for Misc { .context("Could not convert filename into string")? .to_owned(); + let extension = path + .extension() + .with_context(|| format!("Could not get extension for {file_name}"))? + .to_str() + .context("Extension could not be converted to a string")?; + let url = slugify(&format!("/{slug_prefix}/{file_name}")); let mut data = vec![]; @@ -26,7 +32,7 @@ impl Loadable for Misc { Ok(Self { data, - content_type: "todo", + content_type: content_type(extension)?, url, }) } @@ -40,3 +46,13 @@ impl Misc { } } } + +fn content_type(ext: &str) -> anyhow::Result<&'static str> { + let c = match ext { + "webm" => "video/webm", + "mp4" => "video/mp4", + _ => bail!("Unsure how to handle extension {ext}"), + }; + + Ok(c) +} diff --git a/src/resp.rs b/src/resp.rs index 07c25e1c3e914b7dfa0982efadf10e58aef3e52a..d700b0f8769be7db75d24416ae645d41ff7e8abc 100644 --- a/src/resp.rs +++ b/src/resp.rs @@ -11,4 +11,11 @@ impl Response { data: html.into_bytes(), } } + + pub fn css(css: String) -> Self { + Self { + content_type: "text/css; charset=utf-8", + data: css.into_bytes(), + } + } }