adapt webmanifest (#36)

This commit is contained in:
Mylloon 2024-01-25 17:46:00 +01:00
parent c18c0adf34
commit 889573b4e7
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
6 changed files with 48 additions and 21 deletions

View file

@ -47,7 +47,7 @@ async fn main() -> Result<()> {
.service(agreements::security) .service(agreements::security)
.service(agreements::humans) .service(agreements::humans)
.service(agreements::robots) .service(agreements::robots)
.service(agreements::sitemap) .service(agreements::webmanifest)
.service(blog::index) .service(blog::index)
.service(blog::rss) .service(blog::rss)
.service(blog::page) .service(blog::page)

View file

@ -71,8 +71,29 @@ fn build_robotstxt() -> String {
"User-agent: * Allow: /".into() "User-agent: * Allow: /".into()
} }
#[get("/sitemap.xml")] #[get("/app.webmanifest")]
async fn sitemap() -> impl Responder { async fn webmanifest(config: web::Data<Config>) -> impl Responder {
// TODO HttpResponse::Ok()
actix_web::web::Redirect::to("/") .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(),
)
} }

View file

@ -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"
}

21
templates/app.webmanifest Normal file
View file

@ -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"
}
]
}

View file

@ -3,6 +3,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="author" href="/humans.txt" /> <link rel="author" href="/humans.txt" />
<link rel="manifest" href="/app.webmanifest" />
{{>icons.html}} {{>metadata.html}} {{>icons.html}} {{>metadata.html}}

View file

@ -16,7 +16,6 @@
sizes="16x16" sizes="16x16"
href="/icons/favicon-16x16.png" href="/icons/favicon-16x16.png"
/> />
<link rel="manifest" href="/icons/site.webmanifest" />
<link rel="mask-icon" href="/icons/safari-pinned-tab.svg" color="#5bbad5" /> <link rel="mask-icon" href="/icons/safari-pinned-tab.svg" color="#5bbad5" />
<link rel="shortcut icon" href="/icons/favicon.ico" /> <link rel="shortcut icon" href="/icons/favicon.ico" />
<meta name="msapplication-TileColor" content="#ffffff" /> <meta name="msapplication-TileColor" content="#ffffff" />