static pages are rendered and cached

This commit is contained in:
realaravinth 2021-05-04 15:45:53 +05:30
parent f817f49182
commit fe02c43c2c
No known key found for this signature in database
GPG Key ID: AD9F0F08E855ED88
7 changed files with 49 additions and 65 deletions

View File

@ -16,29 +16,27 @@
*/ */
use actix_web::{HttpResponse, Responder}; use actix_web::{HttpResponse, Responder};
use lazy_static::lazy_static;
use sailfish::TemplateOnce; use sailfish::TemplateOnce;
use crate::pages::TITLE;
#[derive(Clone, TemplateOnce)] #[derive(Clone, TemplateOnce)]
#[template(path = "auth/login/index.html")] #[template(path = "auth/login/index.html")]
struct IndexPage<'a> { struct IndexPage;
name: &'a str,
title: &'a str,
}
impl<'a> Default for IndexPage<'a> { const PAGE: &str = "Login";
impl Default for IndexPage {
fn default() -> Self { fn default() -> Self {
IndexPage { IndexPage
name: TITLE,
title: "Login",
}
} }
} }
lazy_static! {
static ref INDEX: String = IndexPage::default().render_once().unwrap();
}
pub async fn login() -> impl Responder { pub async fn login() -> impl Responder {
let body = IndexPage::default().render_once().unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(body) .body(&*INDEX)
} }

View File

@ -16,29 +16,27 @@
*/ */
use actix_web::{HttpResponse, Responder}; use actix_web::{HttpResponse, Responder};
use lazy_static::lazy_static;
use sailfish::TemplateOnce; use sailfish::TemplateOnce;
use crate::pages::TITLE; #[derive(Clone, TemplateOnce)]
#[derive(TemplateOnce, Clone)]
#[template(path = "auth/register/index.html")] #[template(path = "auth/register/index.html")]
struct IndexPage<'a> { struct IndexPage;
name: &'a str,
title: &'a str,
}
impl<'a> Default for IndexPage<'a> { const PAGE: &str = "Join";
impl Default for IndexPage {
fn default() -> Self { fn default() -> Self {
IndexPage { IndexPage
name: TITLE,
title: "Join",
}
} }
} }
lazy_static! {
static ref INDEX: String = IndexPage::default().render_once().unwrap();
}
pub async fn join() -> impl Responder { pub async fn join() -> impl Responder {
let body = IndexPage::default().render_once().unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(body) .body(&*INDEX)
} }

View File

@ -21,7 +21,7 @@ mod auth;
mod panel; mod panel;
pub mod routes; pub mod routes;
pub const TITLE: &str = "mCaptcha"; pub const NAME: &str = "mCaptcha";
pub fn services(cfg: &mut ServiceConfig) { pub fn services(cfg: &mut ServiceConfig) {
auth::services(cfg); auth::services(cfg);

View File

@ -16,28 +16,25 @@
*/ */
use actix_web::{HttpResponse, Responder}; use actix_web::{HttpResponse, Responder};
use lazy_static::lazy_static;
use sailfish::TemplateOnce; use sailfish::TemplateOnce;
use crate::pages::TITLE;
pub mod sitekey; pub mod sitekey;
#[derive(TemplateOnce, Clone)] #[derive(TemplateOnce, Clone)]
#[template(path = "panel/index.html")] #[template(path = "panel/index.html")]
pub struct IndexPage<'a> { pub struct IndexPage;
pub name: &'a str,
pub title: &'a str, const PAGE: &str = "Dashboard";
impl Default for IndexPage {
fn default() -> Self {
IndexPage
}
} }
const COMPONENT: &str = "Dashboard"; lazy_static! {
static ref INDEX: String = IndexPage::default().render_once().unwrap();
impl<'a> Default for IndexPage<'a> {
fn default() -> Self {
IndexPage {
name: TITLE,
title: COMPONENT,
}
}
} }
pub fn services(cfg: &mut actix_web::web::ServiceConfig) { pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
@ -49,10 +46,9 @@ pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
} }
async fn panel() -> impl Responder { async fn panel() -> impl Responder {
let body = IndexPage::default().render_once().unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(body) .body(&*INDEX)
} }
pub mod routes { pub mod routes {

View File

@ -16,39 +16,37 @@
*/ */
use actix_web::{HttpResponse, Responder}; use actix_web::{HttpResponse, Responder};
use lazy_static::lazy_static;
use sailfish::TemplateOnce; use sailfish::TemplateOnce;
use crate::pages::TITLE; const PAGE: &str = "Add Sitekey";
lazy_static! {
static ref INDEX: String = IndexPage::default().render_once().unwrap();
}
#[derive(TemplateOnce, Clone)] #[derive(TemplateOnce, Clone)]
#[template(path = "panel/add-site-key/index.html")] #[template(path = "panel/add-site-key/index.html")]
pub struct IndexPage<'a> { pub struct IndexPage<'a> {
pub name: &'a str,
pub title: &'a str,
pub levels: usize, pub levels: usize,
pub form_title: &'a str, pub form_title: &'a str,
pub form_description: &'a str, pub form_description: &'a str,
pub form_duration: usize, pub form_duration: usize,
} }
const COMPONENT: &str = "Add Site Key";
impl<'a> Default for IndexPage<'a> { impl<'a> Default for IndexPage<'a> {
fn default() -> Self { fn default() -> Self {
IndexPage { IndexPage {
name: TITLE,
title: COMPONENT,
levels: 1, levels: 1,
form_description: "", form_description: "",
form_title: "Add Site Key", form_title: PAGE,
form_duration: 30, form_duration: 30,
} }
} }
} }
pub async fn add_sitekey() -> impl Responder { pub async fn add_sitekey() -> impl Responder {
let body = IndexPage::default().render_once().unwrap();
HttpResponse::Ok() HttpResponse::Ok()
.content_type("text/html; charset=utf-8") .content_type("text/html; charset=utf-8")
.body(body) .body(&*INDEX)
} }

View File

@ -20,19 +20,13 @@ use sailfish::TemplateOnce;
#[derive(TemplateOnce, Clone)] #[derive(TemplateOnce, Clone)]
#[template(path = "panel/site-keys/index.html")] #[template(path = "panel/site-keys/index.html")]
pub struct IndexPage<'a> { pub struct IndexPage;
pub name: &'a str,
pub title: &'a str,
}
const TITLE: &str = "Add Site Key"; const PAGE: &str = "SiteKeys";
impl<'a> Default for IndexPage<'a> { impl Default for IndexPage {
fn default() -> Self { fn default() -> Self {
IndexPage { IndexPage
name: "mCaptcha",
title: TITLE,
}
} }
} }

View File

@ -3,6 +3,6 @@
<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><.= title .> | <.= name .></title> <title><.= PAGE .> | <.= crate::pages::NAME .></title>
</head> </head>
<body> <body>