codoseo_web/routes/
landing.rs1use askama::Template;
4use axum::http::StatusCode;
5use axum::response::{IntoResponse, Response};
6
7use crate::error::AppError;
8use crate::render::html;
9use crate::state::AppState;
10
11#[derive(Template)]
12#[template(path = "landing/index.html")]
13pub struct Landing {
14 pub url: String,
16 pub error: Option<String>,
17 pub checks: usize,
18 pub base: String,
19 pub turnstile_site_key: Option<String>,
21}
22
23fn view(state: &AppState, url: &str, error: Option<String>) -> Landing {
24 Landing {
25 url: url.to_owned(),
26 error,
27 checks: codoseo_checks::CHECKS.len(),
28 base: state.config.origin(),
29 turnstile_site_key: state.config.turnstile.as_ref().map(|t| t.site_key.clone()),
30 }
31}
32
33pub fn page(state: &AppState) -> Result<Response, AppError> {
35 Ok(html(&view(state, "", None))?.into_response())
36}
37
38pub fn refuse(
40 state: &AppState,
41 url: &str,
42 status: StatusCode,
43 message: String,
44) -> Result<Response, AppError> {
45 Ok((status, html(&view(state, url.trim(), Some(message)))?).into_response())
46}