mcaptcha/pages/
sitemap.rs

1// Copyright (C) 2022  Aravinth Manivannan <realaravinth@batsense.net>
2// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
3//
4// SPDX-License-Identifier: AGPL-3.0-or-later
5
6use actix_web::{HttpResponse, Responder};
7use lazy_static::lazy_static;
8use my_codegen::get;
9use sailfish::TemplateOnce;
10
11use super::routes::Routes;
12use crate::PAGES;
13
14#[derive(Clone, TemplateOnce)]
15#[template(path = "sitemap.html")]
16struct IndexPage {
17    urls: [&'static str; 7],
18    domain: &'static str,
19}
20
21impl Default for IndexPage {
22    fn default() -> Self {
23        let urls = Routes::get_sitemap();
24        let domain = if crate::SETTINGS.server.domain.ends_with('/') {
25            &crate::SETTINGS.server.domain[0..crate::SETTINGS.server.domain.len() - 1]
26        } else {
27            &crate::SETTINGS.server.domain
28        };
29
30        Self { urls, domain }
31    }
32}
33
34lazy_static! {
35    static ref INDEX: String = IndexPage::default().render_once().unwrap();
36}
37
38#[get(path = "PAGES.sitemap")]
39pub async fn sitemap() -> impl Responder {
40    HttpResponse::Ok()
41        .content_type("application/xml; charset=utf-8")
42        .body(&**INDEX)
43}