From 889573b4e789a42360d3e80076969c93cc13f088 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 25 Jan 2024 17:46:00 +0100 Subject: [PATCH] adapt webmanifest (#36) --- src/main.rs | 2 +- src/routes/agreements.rs | 29 +++++++++++++++++++++++++---- static/icons/site.webmanifest | 15 --------------- templates/app.webmanifest | 21 +++++++++++++++++++++ templates/head.html | 1 + templates/icons.html | 1 - 6 files changed, 48 insertions(+), 21 deletions(-) delete mode 100644 static/icons/site.webmanifest create mode 100644 templates/app.webmanifest diff --git a/src/main.rs b/src/main.rs index 289fa22..2fc17c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ async fn main() -> Result<()> { .service(agreements::security) .service(agreements::humans) .service(agreements::robots) - .service(agreements::sitemap) + .service(agreements::webmanifest) .service(blog::index) .service(blog::rss) .service(blog::page) diff --git a/src/routes/agreements.rs b/src/routes/agreements.rs index 3589c37..95acbee 100644 --- a/src/routes/agreements.rs +++ b/src/routes/agreements.rs @@ -71,8 +71,29 @@ fn build_robotstxt() -> String { "User-agent: * Allow: /".into() } -#[get("/sitemap.xml")] -async fn sitemap() -> impl Responder { - // TODO - actix_web::web::Redirect::to("/") +#[get("/app.webmanifest")] +async fn webmanifest(config: web::Data) -> impl Responder { + HttpResponse::Ok() + .content_type(ContentType("application/manifest+json".parse().unwrap())) + .body(build_webmanifest(config.get_ref().to_owned())) +} + +#[derive(Content, Debug)] +struct WebManifestTemplate { + name: String, + description: String, + url: String, +} + +#[once(time = 60)] +fn build_webmanifest(config: Config) -> String { + config.tmpl.render( + "app.webmanifest", + WebManifestTemplate { + name: config.fc.clone().app_name.unwrap(), + description: "Easy WebPage generator".to_owned(), + url: get_url(config.fc), + }, + Infos::default(), + ) } diff --git a/static/icons/site.webmanifest b/static/icons/site.webmanifest deleted file mode 100644 index 4fcd7f1..0000000 --- a/static/icons/site.webmanifest +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "Site Anri K.", - "short_name": "Site Anri K.", - "icons": [ - { - "src": "android-chrome-192x192.png", - "sizes": "192x192", - "type": "image/png" - } - ], - "theme_color": "#2a2424", - "background_color": "#2a2424", - "start_url": "https://www.mylloon.fr/", - "display": "standalone" -} diff --git a/templates/app.webmanifest b/templates/app.webmanifest new file mode 100644 index 0000000..e10e8f1 --- /dev/null +++ b/templates/app.webmanifest @@ -0,0 +1,21 @@ +{ + "name": "{{#data}}{{name}}{{/data}}", + "start_url": "{{#data}}{{url}}{{/data}}", + "display": "standalone", + "background_color": "#2a2424", + "description": "{{#data}}{{description}}{{/data}}", + "icons": [ + { + "src": "/icons/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + } + ], + "theme_color": "#2a2424", + "related_applications": [ + { + "platform": "source", + "url": "https://git.mylloon.fr/Anri/mylloon.fr" + } + ] +} diff --git a/templates/head.html b/templates/head.html index 36237f9..ee78fc0 100644 --- a/templates/head.html +++ b/templates/head.html @@ -3,6 +3,7 @@ + {{>icons.html}} {{>metadata.html}} diff --git a/templates/icons.html b/templates/icons.html index 506ba18..91c48ee 100644 --- a/templates/icons.html +++ b/templates/icons.html @@ -16,7 +16,6 @@ sizes="16x16" href="/icons/favicon-16x16.png" /> -