This commit is contained in:
realaravinth 2021-07-21 22:15:52 +05:30
parent 257b3a2b88
commit e9e6aac770
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
14 changed files with 156 additions and 41 deletions

View file

@ -103,6 +103,7 @@ jobs:
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
CACHE_BUSTER_FILE_MAP: '{"map":{"./static/bundle/main.js":"./prod/bundle/main.1417115E59909BE0A01040A45A398ADB09D928DF89CCF038FA44B14850442096.js"},"base_dir":"./prod"}'
COMPILED_DATE: "2021-07-21"
- name: Upload to Codecov
if: matrix.version == '1.51.0' && (github.ref == 'refs/heads/master' || github.event_name == 'pull_request')

View file

@ -93,6 +93,7 @@ jobs:
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres
GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value
OPEN_API_DOCS: 8e77345f1597e40c2e266cb4e6dee74888918a61
COMPILED_DATE: "2021-07-21"
- name: Deploy to GitHub Pages
if: matrix.version == 'stable' && (github.repository == 'mCaptcha/mCaptcha')

20
Cargo.lock generated
View file

@ -783,9 +783,9 @@ dependencies = [
[[package]]
name = "crypto-mac"
version = "0.10.0"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6"
checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a"
dependencies = [
"generic-array",
"subtle",
@ -1984,18 +1984,18 @@ dependencies = [
[[package]]
name = "pin-project"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4"
checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f"
checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389"
dependencies = [
"proc-macro2",
"quote",
@ -3042,9 +3042,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.2.0"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342"
checksum = "4ac2e1d4bd0f75279cfd5a076e0d578bbf02c22b7c39e766c437dd49b3ec43e0"
dependencies = [
"tinyvec_macros",
]
@ -3208,9 +3208,9 @@ checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
[[package]]
name = "universal-hash"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402"
checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05"
dependencies = [
"generic-array",
"subtle",

View file

@ -94,6 +94,7 @@ serde_json = "1"
yaml-rust = "0.4.5"
cache-buster = { version = "0.2.0", git = "https://github.com/realaravinth/cache-buster" }
mime = "0.3.16"
sqlx = { version = "0.5.5", features = [ "runtime-actix-rustls", "postgres", "time", "offline" ] }
[dev-dependencies]
pow_sha256 = { version = "0.2.1", git = "https://github.com/mcaptcha/pow_sha256" }

View file

@ -1,22 +1,23 @@
/*
* 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 std::process::Command;
use cache_buster::{BusterBuilder, NoHashCategory};
use std::process::Command;
use sqlx::types::time::OffsetDateTime;
fn main() {
// note: add error checking yourself.
@ -33,6 +34,10 @@ fn main() {
"cargo:rustc-env=OPEN_API_DOCS={}",
serde_json::to_string(&api_json).unwrap()
);
let now = OffsetDateTime::now_utc().format("%y-%m-%d");
println!("cargo:rustc-env=COMPILED_DATE={}", &now);
cache_bust();
}

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)
}

11
templates/sitemap.html Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<. for url in urls.iter(){ .>
<url>
<loc><.= url .></loc>
<lastmod><.= crate::COMPILED_DATE .></lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<. } .>
</urlset>