diff --git a/src/proxy.rs b/src/proxy.rs index 88aa413..ab047b2 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -24,14 +24,14 @@ use crate::AppData; pub mod routes { pub struct Proxy { - pub update: &'static str, + pub index: &'static str, pub page: &'static str, } impl Proxy { pub const fn new() -> Self { Self { - update: "/api/v1/update", + index: "/", page: "/{username}/{post}", } } @@ -104,12 +104,21 @@ impl StringUtils for str { struct GetPost; #[derive(TemplateOnce)] -#[template(path = "index.html")] +#[template(path = "post.html")] pub struct Post { pub data: get_post::GetPostPost, pub id: String, } +const INDEX: &str = include_str!("../templates/index.html"); + +#[my_codegen::get(path = "crate::V1_API_ROUTES.proxy.index")] +async fn index() -> impl Responder { + HttpResponse::Ok() + .content_type("text/html; charset=utf-8") + .body(INDEX) +} + #[my_codegen::get(path = "crate::V1_API_ROUTES.proxy.page")] async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responder { let post_id = path.1.split("-").last(); @@ -140,6 +149,7 @@ async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responde pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(page); + cfg.service(index); } #[cfg(test)] @@ -156,6 +166,7 @@ mod tests { "/@ftrain/big-data-small-effort-b62607a43a8c", "/geekculture/rest-api-best-practices-decouple-long-running-tasks-from-http-request-processing-9fab2921ace8", "/illumination/5-bugs-that-turned-into-features-e9a0e972a4e7", + "/" ]; for uri in urls.iter() { diff --git a/templates/index.html b/templates/index.html index ffdff6c..85dac3d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,35 +3,52 @@ - <.= data.title .> + LibMedium -
-

<.= data.title .>

- <. use chrono::{TimeZone, Utc}; .> - <. let dt = Utc.timestamp_millis(data.created_at); .> -

- - <.= data.creator.name .> - on <.= dt.format("%b %e, %Y").to_string() .> -

-
- <. let paragraphs = data.content.body_model.paragraphs; .> - <. for (pindex, p) in paragraphs.iter().enumerate() {.> - <. if pindex == 1 && p.type_ == "H3" {.> - <. continue; .> - <.}.> - <. if p.type_ == "IMG" {.> - <. include!("./img.html"); .> - <.} else if p.type_ == "P" {.> - <. include!("./p.html"); .> - <.}.> - <.}.> -
-
+
+
+

LibMedium

+

A free and privacy-respecting medium proxy

+

+ Demo Article + | Source Code +

+
+
diff --git a/templates/post.html b/templates/post.html new file mode 100644 index 0000000..ffdff6c --- /dev/null +++ b/templates/post.html @@ -0,0 +1,37 @@ + + + + + + <.= data.title .> + + +
+

<.= data.title .>

+ <. use chrono::{TimeZone, Utc}; .> + <. let dt = Utc.timestamp_millis(data.created_at); .> +

+ + <.= data.creator.name .> + on <.= dt.format("%b %e, %Y").to_string() .> +

+
+ <. let paragraphs = data.content.body_model.paragraphs; .> + <. for (pindex, p) in paragraphs.iter().enumerate() {.> + <. if pindex == 1 && p.type_ == "H3" {.> + <. continue; .> + <.}.> + <. if p.type_ == "IMG" {.> + <. include!("./img.html"); .> + <.} else if p.type_ == "P" {.> + <. include!("./p.html"); .> + <.}.> + <.}.> +
+
+ + +