(&data.client, URL, vars)
.await
.unwrap();
- println!("{:?}", res);
-
let response_data: get_post::ResponseData = res.data.expect("missing response data");
- for p in response_data
- .post
- .unwrap()
- .content
- .unwrap()
- .body_model
- .unwrap()
- .paragraphs
- .unwrap()
- .iter()
- {
- println!("paragraph content: {:?}", p.as_ref().unwrap());
- }
- // .bodyModel
- // .paragraphs
- // .iter();
- // println!("{:?}", response_data);
+ let page = Post {
+ id,
+ data: response_data.post.unwrap(),
+ }
+ .render_once()
+ .unwrap();
HttpResponse::Ok()
+ .content_type("text/html; charset=utf-8")
+ .body(page)
}
pub fn services(cfg: &mut web::ServiceConfig) {
@@ -97,42 +146,22 @@ pub fn services(cfg: &mut web::ServiceConfig) {
mod tests {
use actix_web::{http::StatusCode, test, App};
- use crate::services;
- use crate::*;
+ use crate::{services, Data};
- use super::*;
+ #[actix_rt::test]
+ async fn deploy_update_works() {
+ let data = Data::new();
+ let app = test::init_service(App::new().app_data(data.clone()).configure(services)).await;
+ let urls = vec![
+ "/@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",
+ ];
- // #[actix_rt::test]
- // async fn deploy_update_works() {
- // let app = test::init_service(App::new().configure(services)).await;
- //
- // let page = page.unwrap();
- //
- // let mut payload = ProxyEvent {
- // secret: page.secret.clone(),
- // branch: page.branch.clone(),
- // };
- //
- // let resp = test::call_service(
- // &app,
- // test::TestRequest::post()
- // .uri(V1_API_ROUTES.deploy.update)
- // .set_json(&payload)
- // .to_request(),
- // )
- // .await;
- // assert_eq!(resp.status(), StatusCode::OK);
- //
- // payload.secret = page.branch.clone();
- //
- // let resp = test::call_service(
- // &app,
- // test::TestRequest::post()
- // .uri(V1_API_ROUTES.deploy.update)
- // .set_json(&payload)
- // .to_request(),
- // )
- // .await;
- // assert_eq!(resp.status(), StatusCode::NOT_FOUND);
- // }
+ for uri in urls.iter() {
+ let resp =
+ test::call_service(&app, test::TestRequest::get().uri(uri).to_request()).await;
+ assert_eq!(resp.status(), StatusCode::OK);
+ }
+ }
}
diff --git a/templates/img.html b/templates/img.html
new file mode 100644
index 0000000..cd6e987
--- /dev/null
+++ b/templates/img.html
@@ -0,0 +1,9 @@
+<. let metadata = p.metadata.as_ref().unwrap(); .>
+
+
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..ffdff6c
--- /dev/null
+++ b/templates/index.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"); .>
+ <.}.>
+ <.}.>
+
+
+
+
+
diff --git a/templates/main.css b/templates/main.css
new file mode 100644
index 0000000..da59c78
--- /dev/null
+++ b/templates/main.css
@@ -0,0 +1,27 @@
+* {
+ margin: 0;
+ padding: 0;
+}
+
+body {
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+}
+
+main {
+ width: 60%;
+ margin: auto;
+ display: flex;
+ flex-direction: column;
+}
+
+p {
+ margin: 20px 0;
+}
+
+img {
+ margin: auto;
+ max-width: 80%;
+ /*! display: block; */
+}
diff --git a/templates/matcher.rs b/templates/matcher.rs
new file mode 100644
index 0000000..5f8842a
--- /dev/null
+++ b/templates/matcher.rs
@@ -0,0 +1,15 @@
+match p.type_.as_str() {
+ "IMG" => {
+ include!("./img.html");
+ },
+ _ => unimplemented!(),
+
+}
+
+//<. match p.type_ { .>
+// <. "IMG" => { .>
+// <. include!("./img.html") .>
+// <. }, .>
+// <. _ => log::error("Unable to find paragraph render class. Post ID: {}. Paragraph item {:?}", id, p),
+// <. } .>
+//
diff --git a/templates/p.html b/templates/p.html
new file mode 100644
index 0000000..44e8f41
--- /dev/null
+++ b/templates/p.html
@@ -0,0 +1,44 @@
+
+<. if p.markups.is_empty() {.>
+<.= p.text .>
+<.} else {.>
+ <. let mut cur: usize = 0; .>
+ <. for markup in &p.markups {.>
+ <.= &p.text.substring(cur, (markup.start -1) as usize) .>
+ <. cur = (markup.end + 1) as usize; .>
+ <. let text = &p.text.substring(markup.start as usize, markup.end as usize); .>
+ <. if markup.type_ == "A" {.>
+ <. if let Some(anchor_type) = &markup.anchor_type {.>
+ <. if anchor_type == "LINK" {.>
+ <.= text .>
+ <.} else if anchor_type == "USER" {.>
+
+ <.= text .>
+
+ <.} else {.>
+ <. log::error!("unknown markup.anchor_type: {:?} post id {}", anchor_type, id); .>
+ <.= text .>
+ <.}.>
+ <.}.>
+ <.} else if markup.type_ == "EM" {.>
+ <.= text .>
+ <.} else if markup.type_ == "STRONG" {.>
+ <.= text .>
+ <.} else if markup.type_ == "CODE" {.>
+ <.= text .>
+ <.} else {.>
+ <. log::error!("unknown markup.type_: {:?} post id {}", markup.type_, id); .>
+ <.= text .>
+ <.}.>
+
+ <. if cur < p.text.len() {.>
+ <.= p.text.slice(cur..) .>
+ <.}.>
+ <.}.>
+
+<.}.>
+
+