forked from realaravinth/libmedium
show reading time
This commit is contained in:
parent
745d97acfd
commit
7fdf255678
4 changed files with 11 additions and 8 deletions
|
@ -2,6 +2,7 @@ query GetPost($id: ID!) {
|
|||
post(id: $id) {
|
||||
title
|
||||
createdAt
|
||||
readingTime
|
||||
creator {
|
||||
name
|
||||
id
|
||||
|
|
|
@ -53,6 +53,7 @@ type User { id: String! name: String! imageId: String! }
|
|||
|
||||
type Post {
|
||||
id: ID!
|
||||
readingTime: Float!
|
||||
title: String!
|
||||
createdAt: Int!
|
||||
content: Content!
|
||||
|
|
12
src/proxy.rs
12
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<String>, 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)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
/>
|
||||
<.= data.creator.name .></a
|
||||
>
|
||||
on <.= &date .>
|
||||
on <.= &date .> · <.= data.reading_time.floor() as usize .> min read
|
||||
</p>
|
||||
<article>
|
||||
<. let paragraphs = data.content.body_model.paragraphs; .>
|
||||
|
@ -42,6 +42,9 @@
|
|||
<h5><.= p.text .></h5>
|
||||
<.} else if p.type_ == "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>
|
||||
|
|
Loading…
Reference in a new issue