show reading time

This commit is contained in:
Aravinth Manivannan 2021-11-02 21:04:02 +05:30
parent 745d97acfd
commit 7fdf255678
Signed by untrusted user: realaravinth
GPG key ID: AD9F0F08E855ED88
4 changed files with 11 additions and 8 deletions

View file

@ -2,6 +2,7 @@ query GetPost($id: ID!) {
post(id: $id) { post(id: $id) {
title title
createdAt createdAt
readingTime
creator { creator {
name name
id id

View file

@ -53,6 +53,7 @@ type User { id: String! name: String! imageId: String! }
type Post { type Post {
id: ID! id: ID!
readingTime: Float!
title: String! title: String!
createdAt: Int! createdAt: Int!
content: Content! content: Content!

View file

@ -123,17 +123,20 @@ async fn index() -> impl Responder {
#[my_codegen::get(path = "crate::V1_API_ROUTES.proxy.asset")] #[my_codegen::get(path = "crate::V1_API_ROUTES.proxy.asset")]
async fn assets(path: web::Path<String>, data: AppData) -> impl Responder { async fn assets(path: web::Path<String>, data: AppData) -> impl Responder {
println!("asset name: {}", path);
let res = data let res = data
.client .client
.get(format!("https://miro.medium.com/{}", path)) .get(format!("https://miro.medium.com/{}", path))
.send() .send()
.await .await
.unwrap(); .unwrap();
print!("got res");
let headers = res.headers(); let headers = res.headers();
let content_type = headers.get(CONTENT_TYPE).unwrap(); let content_type = headers.get(CONTENT_TYPE).unwrap();
HttpResponse::Ok() 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) .content_type(content_type)
.body(res.bytes().await.unwrap()) .body(res.bytes().await.unwrap())
} }
@ -153,11 +156,6 @@ async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responde
.render_once() .render_once()
.unwrap(); .unwrap();
HttpResponse::Ok() 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") .content_type("text/html; charset=utf-8")
.body(page) .body(page)
} }

View file

@ -20,7 +20,7 @@
/> />
<.= data.creator.name .></a <.= data.creator.name .></a
> >
on <.= &date .> on <.= &date .> &#183; <.= data.reading_time.floor() as usize .> min read
</p> </p>
<article> <article>
<. let paragraphs = data.content.body_model.paragraphs; .> <. let paragraphs = data.content.body_model.paragraphs; .>
@ -42,6 +42,9 @@
<h5><.= p.text .></h5> <h5><.= p.text .></h5>
<.} else if p.type_ == "H6" {.> <.} else if p.type_ == "H6" {.>
<h6><.= p.text .></h6> <h6><.= p.text .></h6>
<.} else if p.type_ == "IFRAME" {.>
<. let src = &p.iframe.as_ref().unwrap().media_resource.as_ref().unwrap().href; .>
<iframe src="<.= src .>" frameborder="0"></iframe>
<.}.> <.}.>
<.}.> <.}.>
</article> </article>