This commit is contained in:
realaravinth
2021-07-21 22:15:52 +05:30
parent 257b3a2b88
commit e9e6aac770
14 changed files with 156 additions and 41 deletions

View File

@@ -84,6 +84,7 @@ lazy_static! {
}
pub const OPEN_API_DOC: &str = env!("OPEN_API_DOCS");
pub const COMPILED_DATE: &str = env!("COMPILED_DATE");
pub const GIT_COMMIT_HASH: &str = env!("GIT_HASH");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const PKG_NAME: &str = env!("CARGO_PKG_NAME");

View File

@@ -36,5 +36,10 @@ pub mod routes {
join: "/join",
}
}
pub const fn get_sitemap() -> [&'static str; 2] {
const AUTH: Auth = Auth::new();
[AUTH.login, AUTH.join]
}
}
}

View File

@@ -1,18 +1,18 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use actix_web::web::ServiceConfig;
@@ -20,6 +20,7 @@ mod auth;
pub mod errors;
mod panel;
pub mod routes;
mod sitemap;
pub const NAME: &str = "mCaptcha";
@@ -27,6 +28,7 @@ pub fn services(cfg: &mut ServiceConfig) {
auth::services(cfg);
panel::services(cfg);
errors::services(cfg);
cfg.service(sitemap::sitemap);
}
#[cfg(not(tarpaulin_include))]
@@ -94,7 +96,7 @@ mod tests {
#[actix_rt::test]
async fn public_pages_tempaltes_work() {
let app = test::init_service(App::new().configure(services)).await;
let urls = vec![PAGES.auth.login, PAGES.auth.join];
let urls = vec![PAGES.auth.login, PAGES.auth.join, PAGES.sitemap];
for url in urls.iter() {
let resp =

View File

@@ -77,5 +77,18 @@ pub mod routes {
settings: Settings::new(),
}
}
pub const fn get_sitemap() -> [&'static str; 5] {
const PANEL: Panel = Panel::new();
const S: [&str; 2] = Sitekey::get_sitemap();
[
PANEL.home,
PANEL.notifications,
S[0],
S[1],
Settings::get_sitemap()[0],
]
}
}
}

View File

@@ -37,6 +37,12 @@ pub mod routes {
update_secret: "/settings/secret/update",
}
}
pub const fn get_sitemap() -> [&'static str; 1] {
const S: Settings = Settings::new();
[S.home]
}
}
}

View File

@@ -40,6 +40,10 @@ pub mod routes {
delete: "/sitekey/{key}/delete",
}
}
pub const fn get_sitemap() -> [&'static str; 2] {
const S: Sitekey = Sitekey::new();
[S.list, S.add]
}
}
}

View File

@@ -26,6 +26,7 @@ pub struct Routes {
pub panel: Panel,
pub errors: Errors,
pub about: &'static str,
pub sitemap: &'static str,
pub thanks: &'static str,
pub donate: &'static str,
pub security: &'static str,
@@ -42,10 +43,27 @@ impl Routes {
home,
errors: Errors::new(),
about: "/about",
sitemap: "/sitemap.xml",
thanks: "/thanks",
donate: "/donate",
security: "/security",
privacy: "/privacy-policy",
}
}
pub const fn get_sitemap() -> [&'static str; 7] {
let a = Auth::get_sitemap();
let p = Panel::get_sitemap();
[a[0], a[1], p[0], p[1], p[2], p[3], p[4]]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sitemap_works() {
Routes::get_sitemap();
}
}

47
src/pages/sitemap.rs Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use actix_web::{HttpResponse, Responder};
use lazy_static::lazy_static;
use my_codegen::get;
use sailfish::TemplateOnce;
use super::routes::Routes;
use crate::PAGES;
#[derive(Clone, TemplateOnce)]
#[template(path = "sitemap.html")]
struct IndexPage {
urls: [&'static str; 7],
}
impl Default for IndexPage {
fn default() -> Self {
let urls = Routes::get_sitemap();
Self { urls }
}
}
lazy_static! {
static ref INDEX: String = IndexPage::default().render_once().unwrap();
}
#[get(path = "PAGES.sitemap")]
pub async fn sitemap() -> impl Responder {
HttpResponse::Ok()
.content_type("application/xml; charset=utf-8")
.body(&*INDEX)
}