add index page
This commit is contained in:
parent
6ea970e7a6
commit
c23943a796
3 changed files with 94 additions and 29 deletions
17
src/proxy.rs
17
src/proxy.rs
|
@ -24,14 +24,14 @@ use crate::AppData;
|
||||||
|
|
||||||
pub mod routes {
|
pub mod routes {
|
||||||
pub struct Proxy {
|
pub struct Proxy {
|
||||||
pub update: &'static str,
|
pub index: &'static str,
|
||||||
pub page: &'static str,
|
pub page: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Proxy {
|
impl Proxy {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
update: "/api/v1/update",
|
index: "/",
|
||||||
page: "/{username}/{post}",
|
page: "/{username}/{post}",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,12 +104,21 @@ impl StringUtils for str {
|
||||||
struct GetPost;
|
struct GetPost;
|
||||||
|
|
||||||
#[derive(TemplateOnce)]
|
#[derive(TemplateOnce)]
|
||||||
#[template(path = "index.html")]
|
#[template(path = "post.html")]
|
||||||
pub struct Post {
|
pub struct Post {
|
||||||
pub data: get_post::GetPostPost,
|
pub data: get_post::GetPostPost,
|
||||||
pub id: String,
|
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")]
|
#[my_codegen::get(path = "crate::V1_API_ROUTES.proxy.page")]
|
||||||
async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responder {
|
async fn page(path: web::Path<(String, String)>, data: AppData) -> impl Responder {
|
||||||
let post_id = path.1.split("-").last();
|
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) {
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(page);
|
cfg.service(page);
|
||||||
|
cfg.service(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -156,6 +166,7 @@ mod tests {
|
||||||
"/@ftrain/big-data-small-effort-b62607a43a8c",
|
"/@ftrain/big-data-small-effort-b62607a43a8c",
|
||||||
"/geekculture/rest-api-best-practices-decouple-long-running-tasks-from-http-request-processing-9fab2921ace8",
|
"/geekculture/rest-api-best-practices-decouple-long-running-tasks-from-http-request-processing-9fab2921ace8",
|
||||||
"/illumination/5-bugs-that-turned-into-features-e9a0e972a4e7",
|
"/illumination/5-bugs-that-turned-into-features-e9a0e972a4e7",
|
||||||
|
"/"
|
||||||
];
|
];
|
||||||
|
|
||||||
for uri in urls.iter() {
|
for uri in urls.iter() {
|
||||||
|
|
|
@ -3,35 +3,52 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title><.= data.title .></title>
|
<title>LibMedium</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main class="container">
|
<main>
|
||||||
<h1><.= data.title .></h1>
|
<div class="center">
|
||||||
<. use chrono::{TimeZone, Utc}; .>
|
<h1>LibMedium</h1>
|
||||||
<. let dt = Utc.timestamp_millis(data.created_at); .>
|
<p>A free and privacy-respecting medium proxy</p>
|
||||||
<p class="meta">
|
<p>
|
||||||
<a href="https://medium.com/u/<.= data.creator.id .>" rel="noreferrer">
|
<a
|
||||||
<.= data.creator.name .></a
|
href="https://libmedium.batsense.net/@tylerneely/fear-and-loathing-in-lock-free-programming-7158b1cdd50c"
|
||||||
>
|
>Demo Article</a
|
||||||
on <.= dt.format("%b %e, %Y").to_string() .>
|
>
|
||||||
</p>
|
| <a href="https://github.com/realaravinth/libmedium">Source Code</a>
|
||||||
<article>
|
</p>
|
||||||
<. let paragraphs = data.content.body_model.paragraphs; .>
|
</div>
|
||||||
<. for (pindex, p) in paragraphs.iter().enumerate() {.>
|
</main>
|
||||||
<. if pindex == 1 && p.type_ == "H3" {.>
|
|
||||||
<. continue; .>
|
|
||||||
<.}.>
|
|
||||||
<. if p.type_ == "IMG" {.>
|
|
||||||
<. include!("./img.html"); .>
|
|
||||||
<.} else if p.type_ == "P" {.>
|
|
||||||
<. include!("./p.html"); .>
|
|
||||||
<.}.>
|
|
||||||
<.}.>
|
|
||||||
</article>
|
|
||||||
</main>
|
|
||||||
</body>
|
</body>
|
||||||
<style>
|
<style>
|
||||||
<. include!("./main.css"); .>
|
* {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
main {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
width: 80%;
|
||||||
|
height: 100vh;
|
||||||
|
margin: auto;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
margin: auto;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 3rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</html>
|
</html>
|
||||||
|
|
37
templates/post.html
Normal file
37
templates/post.html
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title><.= data.title .></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="container">
|
||||||
|
<h1><.= data.title .></h1>
|
||||||
|
<. use chrono::{TimeZone, Utc}; .>
|
||||||
|
<. let dt = Utc.timestamp_millis(data.created_at); .>
|
||||||
|
<p class="meta">
|
||||||
|
<a href="https://medium.com/u/<.= data.creator.id .>" rel="noreferrer">
|
||||||
|
<.= data.creator.name .></a
|
||||||
|
>
|
||||||
|
on <.= dt.format("%b %e, %Y").to_string() .>
|
||||||
|
</p>
|
||||||
|
<article>
|
||||||
|
<. 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"); .>
|
||||||
|
<.}.>
|
||||||
|
<.}.>
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
<style>
|
||||||
|
<. include!("./main.css"); .>
|
||||||
|
</style>
|
||||||
|
</html>
|
Loading…
Reference in a new issue