Skip to content
Snippets Groups Projects
Commit 3ad00b0b authored by Stephen D's avatar Stephen D
Browse files

content-type fixes

parent 07849872
No related branches found
No related tags found
No related merge requests found
......@@ -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>"#
)
}
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)
}
......@@ -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(),
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment