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

video working. need to add the correct content type

parent 5a429edc
No related branches found
No related tags found
No related merge requests found
......@@ -40,7 +40,13 @@ a:visited {
.header-container {
display: flex;
}
.header-date {
white-space: nowrap;
margin: 1em 1em 1em auto;
}
img, video {
max-width: 100%;
max-width: 100%;
}
......@@ -2,12 +2,13 @@ use anyhow::Error;
use std::collections::HashMap;
use warp::hyper::StatusCode;
use crate::{image::MyImage, load::load_from_path, post::Post, resp::Response};
use crate::{image::MyImage, load::load_from_path, misc::Misc, post::Post, resp::Response};
pub struct Blog {
//pages: Vec<Page>,
posts: Vec<Post>,
imgs: Vec<MyImage>,
misc: Vec<Misc>,
}
impl Blog {
......@@ -20,7 +21,9 @@ impl Blog {
let imgs = load_from_path("assets/img", "")?;
Ok(Self { posts, imgs })
let misc = load_from_path("assets/misc", "misc")?;
Ok(Self { posts, imgs, misc })
}
fn home(&self) -> Result<String, Error> {
......@@ -77,6 +80,10 @@ impl TryFrom<Blog> for RenderedBlog {
pages.insert(original_url, original);
}
for m in b.misc {
pages.insert(m.url.clone(), m.response());
}
let not_found = Response::html(dress_page(
"Page not found",
include_str!("assets/404.html"),
......
......@@ -13,6 +13,7 @@ mod blog;
mod date;
mod image;
mod load;
mod misc;
mod parser;
mod post;
mod resp;
......
use std::{fs::File, io::Read};
use anyhow::Context;
use crate::{load::Loadable, resp::Response, util::slugify};
pub struct Misc {
pub url: String,
content_type: &'static str,
data: Vec<u8>,
}
impl Loadable for Misc {
fn load(path: &std::path::Path, slug_prefix: &str) -> anyhow::Result<Self> {
let file_name = path
.file_name()
.context("Could not get file name")?
.to_str()
.context("Could not convert filename into string")?
.to_owned();
let url = slugify(&format!("/{slug_prefix}/{file_name}"));
let mut data = vec![];
File::open(path)?.read_to_end(&mut data)?;
Ok(Self {
data,
content_type: "todo",
url,
})
}
}
impl Misc {
pub fn response(self) -> Response {
Response {
content_type: self.content_type,
data: self.data,
}
}
}
use anyhow::bail;
use anyhow::Context;
use anyhow::Error;
use orgize::elements::Keyword;
use orgize::elements::Link;
use orgize::elements::Timestamp;
use orgize::{
......@@ -89,6 +90,12 @@ impl HtmlHandler<Error> for CustomHtmlHandler {
Element::Link(Link { path, desc }) if desc.is_none() => {
write!(w, r#"<a href="/img/{path}"><img src="/thumb/{path}">"#)?;
}
Element::Keyword(Keyword { key, value, .. }) if key == "VIDEO" => {
write!(
w,
r#"<video controls="controls"><source src="{value}"></video>"#
)?;
}
// fallback to default handler
_ => self.fallback.start(w, element)?,
}
......
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