diff --git a/schemas/query.graphql b/schemas/query.graphql index c5e7366..b66c3fb 100644 --- a/schemas/query.graphql +++ b/schemas/query.graphql @@ -2,6 +2,7 @@ query GetPost($id: ID!) { post(id: $id) { title createdAt + readingTime creator { name id diff --git a/schemas/schema.graphql b/schemas/schema.graphql index 88649ad..c63d697 100644 --- a/schemas/schema.graphql +++ b/schemas/schema.graphql @@ -53,6 +53,7 @@ type User { id: String! name: String! imageId: String! } type Post { id: ID! + readingTime: Float! title: String! createdAt: Int! content: Content! diff --git a/src/proxy.rs b/src/proxy.rs index 791ab9e..09ec7ab 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -123,17 +123,20 @@ async fn index() -> impl Responder { #[my_codegen::get(path = "crate::V1_API_ROUTES.proxy.asset")] async fn assets(path: web::Path, data: AppData) -> impl Responder { - println!("asset name: {}", path); let res = data .client .get(format!("https://miro.medium.com/{}", path)) .send() .await .unwrap(); - print!("got res"); let headers = res.headers(); let content_type = headers.get(CONTENT_TYPE).unwrap(); HttpResponse::Ok() + .insert_header(header::CacheControl(vec![ + header::CacheDirective::Public, + header::CacheDirective::Extension("immutable".into(), None), + header::CacheDirective::MaxAge(CACHE_AGE), + ])) .content_type(content_type) .body(res.bytes().await.unwrap()) } @@ -153,11 +156,6 @@ async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responde .render_once() .unwrap(); HttpResponse::Ok() - .insert_header(header::CacheControl(vec![ - header::CacheDirective::Public, - header::CacheDirective::Extension("immutable".into(), None), - header::CacheDirective::MaxAge(CACHE_AGE), - ])) .content_type("text/html; charset=utf-8") .body(page) } diff --git a/templates/post.html b/templates/post.html index ad6f9f3..6f66e06 100644 --- a/templates/post.html +++ b/templates/post.html @@ -20,7 +20,7 @@ /> <.= data.creator.name .> - on <.= &date .> + on <.= &date .> · <.= data.reading_time.floor() as usize .> min read

<. let paragraphs = data.content.body_model.paragraphs; .> @@ -42,6 +42,9 @@
<.= p.text .>
<.} else if p.type_ == "H6" {.>
<.= p.text .>
+ <.} else if p.type_ == "IFRAME" {.> + <. let src = &p.iframe.as_ref().unwrap().media_resource.as_ref().unwrap().href; .> + <.}.> <.}.>