Multiple backgrounds
This commit is contained in:
parent
296ec44fe4
commit
aa1893feb2
|
@ -1 +1,8 @@
|
|||
hard_tabs = true
|
||||
newline_style = "unix"
|
||||
|
||||
unstable_features = true
|
||||
format_code_in_doc_comments = true
|
||||
format_macro_bodies = true
|
||||
format_macro_matchers = true
|
||||
format_strings = true
|
||||
|
|
|
@ -160,12 +160,7 @@ async fn serve_index<'a>(
|
|||
.render(
|
||||
"index.html",
|
||||
&IndexTemplate {
|
||||
common: CommonTemplate {
|
||||
lang: "fr",
|
||||
root_url: &config.root_url,
|
||||
title: &config.title,
|
||||
errors,
|
||||
},
|
||||
common: CommonTemplate::new(&config, errors),
|
||||
ads: &to_json(
|
||||
dbs.ad_by_group
|
||||
.scan_prefix(ROOT_GROUP_ID)
|
||||
|
@ -209,9 +204,11 @@ async fn serve_group<'a>(
|
|||
) -> tide::Result<tide::Response> {
|
||||
if let Ok(group_name) = req.param("group") {
|
||||
if let Some(group_id) = dbs.group_by_name.get(group_name).unwrap() {
|
||||
if let Some(group) = dbs.group.get(&group_id).unwrap() {
|
||||
if let Ok(group) = bincode::deserialize::<Group>(&group) {
|
||||
let selected_ad = req.param("ad").ok();
|
||||
|
||||
Ok(tide::Response::builder(200)
|
||||
return Ok(tide::Response::builder(200)
|
||||
.content_type(tide::http::mime::HTML)
|
||||
.body(
|
||||
templates
|
||||
|
@ -219,12 +216,7 @@ async fn serve_group<'a>(
|
|||
.render(
|
||||
"group.html",
|
||||
&GroupTemplate {
|
||||
common: CommonTemplate {
|
||||
lang: "fr",
|
||||
root_url: &config.root_url,
|
||||
title: &config.title,
|
||||
errors,
|
||||
},
|
||||
common: CommonTemplate::new(&config, errors),
|
||||
ads: &to_json(
|
||||
dbs.ad_by_group
|
||||
.scan_prefix(group_id.clone())
|
||||
|
@ -235,21 +227,26 @@ async fn serve_group<'a>(
|
|||
);
|
||||
Some(AdWithId {
|
||||
ad: bincode::deserialize::<Ad>(&ad).ok()?,
|
||||
selected: selected_ad.map_or(false, |i| i == ad_id),
|
||||
selected: selected_ad
|
||||
.map_or(false, |i| i == ad_id),
|
||||
id: ad_id,
|
||||
})
|
||||
})
|
||||
.collect::<Vec<AdWithId>>(),
|
||||
),
|
||||
group: &to_json(group),
|
||||
groups: &to_json(
|
||||
dbs.group_by_group
|
||||
.scan_prefix(group_id)
|
||||
.keys()
|
||||
.filter_map(|k| {
|
||||
GroupId::try_from(&k.ok()?.as_ref()[16..32]).ok()
|
||||
GroupId::try_from(&k.ok()?.as_ref()[16..32])
|
||||
.ok()
|
||||
})
|
||||
.filter_map(|subgroup_id| {
|
||||
bincode::deserialize(&dbs.group.get(subgroup_id).ok()??)
|
||||
bincode::deserialize(
|
||||
&dbs.group.get(subgroup_id).ok()??,
|
||||
)
|
||||
.ok()
|
||||
})
|
||||
.collect::<Vec<Group>>(),
|
||||
|
@ -259,8 +256,10 @@ async fn serve_group<'a>(
|
|||
)
|
||||
.unwrap_or_else(|e| e.to_string()),
|
||||
)
|
||||
.build())
|
||||
} else {
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
serve_index(
|
||||
req,
|
||||
config,
|
||||
|
@ -272,7 +271,6 @@ async fn serve_group<'a>(
|
|||
None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
} else {
|
||||
serve_index(req, config, templates, dbs, &[], None).await
|
||||
}
|
||||
|
@ -300,12 +298,7 @@ async fn serve_admin_group<'a>(
|
|||
.render(
|
||||
"admin_group.html",
|
||||
&AdminGroupTemplate {
|
||||
common: CommonTemplate {
|
||||
lang: "fr",
|
||||
root_url: &config.root_url,
|
||||
title: &config.title,
|
||||
errors,
|
||||
},
|
||||
common: CommonTemplate::new(&config, errors),
|
||||
ads: &to_json(
|
||||
dbs.ad_by_group
|
||||
.scan_prefix(group_id.clone())
|
||||
|
@ -380,12 +373,7 @@ async fn serve_admin<'a>(
|
|||
.render(
|
||||
"admin.html",
|
||||
&AdminTemplate {
|
||||
common: CommonTemplate {
|
||||
lang: "fr",
|
||||
root_url: &config.root_url,
|
||||
title: &config.title,
|
||||
errors,
|
||||
},
|
||||
common: CommonTemplate::new(&config, errors),
|
||||
ads: &to_json(
|
||||
dbs.ad_by_group
|
||||
.scan_prefix(ROOT_GROUP_ID)
|
||||
|
@ -432,12 +420,7 @@ async fn serve_admin_login<'a>(
|
|||
.render(
|
||||
"admin_login.html",
|
||||
&AdminLoginTemplate {
|
||||
common: CommonTemplate {
|
||||
lang: "fr",
|
||||
root_url: &config.root_url,
|
||||
title: &config.title,
|
||||
errors,
|
||||
},
|
||||
common: CommonTemplate::new(&config, errors),
|
||||
},
|
||||
)
|
||||
.unwrap_or_else(|e| e.to_string()),
|
||||
|
@ -477,7 +460,8 @@ async fn handle_new_ad(
|
|||
} else {
|
||||
Some(match format_pubkey(&query.pubkey) {
|
||||
Ok(pubkey) => pubkey,
|
||||
Err(e) => return serve_index(
|
||||
Err(e) => {
|
||||
return serve_index(
|
||||
req,
|
||||
config,
|
||||
templates,
|
||||
|
@ -485,7 +469,8 @@ async fn handle_new_ad(
|
|||
&[ErrorTemplate {
|
||||
text: match e {
|
||||
PubkeyDecodeError::BadChecksum => {
|
||||
"La somme de contrôle de la clé publique est incorrecte."
|
||||
"La somme de contrôle de la clé publique est \
|
||||
incorrecte."
|
||||
}
|
||||
PubkeyDecodeError::BadFormat => {
|
||||
"Le format de la clé publique est incorrect."
|
||||
|
@ -494,7 +479,8 @@ async fn handle_new_ad(
|
|||
}],
|
||||
Some(query),
|
||||
)
|
||||
.await,
|
||||
.await
|
||||
}
|
||||
})
|
||||
},
|
||||
author: query.author,
|
||||
|
|
|
@ -11,9 +11,16 @@ static STATIC_FILES: &[(&str, &[u8])] = &[
|
|||
"LinBiolinum_R.otf",
|
||||
include_bytes!("../static/LinBiolinum_R.otf"),
|
||||
),
|
||||
("background.jpg", include_bytes!("../static/background.jpg")),
|
||||
("bg0.jpg", include_bytes!("../static/bg0.jpg")),
|
||||
("bg1.jpg", include_bytes!("../static/bg1.jpg")),
|
||||
("bg2.jpg", include_bytes!("../static/bg2.jpg")),
|
||||
("script1.js", include_bytes!("../static/script1.js")),
|
||||
];
|
||||
pub static BACKGROUND_ABOUT: &[&str] = &[
|
||||
"Claudia Peters, FreeImages.com",
|
||||
r#"<a href="https://commons.wikimedia.org/wiki/File:Jukung_Pasar_Terapung.jpg">Muhammad Haris</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>"#,
|
||||
r#"<a href="https://commons.wikimedia.org/wiki/File:Municipal_Market_of_S%C3%A3o_Paulo_city.jpg">Wilfredor</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>"#,
|
||||
];
|
||||
|
||||
pub fn init_static_files(dir: &Path) {
|
||||
let dir = dir.join(STATIC_DIR);
|
||||
|
@ -27,3 +34,9 @@ pub fn init_static_files(dir: &Path) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_background() -> usize {
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.map_or(0, |t| t.as_secs() as usize / 86400 % 3)
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use super::queries::*;
|
||||
use crate::{config::Config, queries::*};
|
||||
|
||||
use handlebars::Handlebars;
|
||||
use serde::Serialize;
|
||||
use serde_json::value::Value as Json;
|
||||
use std::path::Path;
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
const TEMPLATES_DIR: &str = "templates";
|
||||
static TEMPLATE_FILES: &[(&str, &str)] = &[
|
||||
|
@ -57,6 +57,22 @@ pub struct CommonTemplate<'a> {
|
|||
pub root_url: &'a str,
|
||||
pub title: &'a str,
|
||||
pub errors: &'a [ErrorTemplate<'a>],
|
||||
pub bg_id: usize,
|
||||
pub bg_about: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> CommonTemplate<'a> {
|
||||
pub fn new(config: &'a Arc<Config>, errors: &'a [ErrorTemplate<'a>]) -> Self {
|
||||
let bg_id = crate::static_files::get_background();
|
||||
Self {
|
||||
lang: "fr",
|
||||
root_url: &config.as_ref().root_url,
|
||||
title: &config.as_ref().title,
|
||||
errors,
|
||||
bg_id,
|
||||
bg_about: crate::static_files::BACKGROUND_ABOUT[bg_id],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -82,12 +98,12 @@ pub struct AdminTemplate<'a> {
|
|||
pub groups: &'a Json,
|
||||
}
|
||||
|
||||
// TODO add subgroups, parent groups, title
|
||||
#[derive(Serialize)]
|
||||
pub struct GroupTemplate<'a> {
|
||||
#[serde(flatten)]
|
||||
pub common: CommonTemplate<'a>,
|
||||
pub ads: &'a Json,
|
||||
pub group: &'a Json,
|
||||
pub groups: &'a Json,
|
||||
pub new_ad_form_refill: Option<NewAdQuery>,
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
Binary file not shown.
After Width: | Height: | Size: 3.5 MiB |
Binary file not shown.
After Width: | Height: | Size: 3.1 MiB |
|
@ -17,10 +17,6 @@ html, body {
|
|||
font-size: 110%;
|
||||
}
|
||||
|
||||
body {
|
||||
background-image: linear-gradient(rgba(255,255,255,0.2), rgba(255,255,255,0.2)), url("/static/background.jpg");
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
font-family: "Karma";
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<link rel="shortcut icon" href="{{root_url}}static/icon.png"/>
|
||||
<script type="text/javascript" src="{{root_url}}static/script1.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<body style="background-image: linear-gradient(rgba(255,255,255,0.2),rgba(255,255,255,0.2)), url('/static/bg{{bg_id}}.jpg');">
|
||||
<div class="center page">
|
||||
<header>
|
||||
<a href="{{root_url}}"><img id="banner" alt="Bannière {{title}}" src="{{root_url}}static/banner.jpg"/></a>
|
||||
|
@ -15,6 +15,7 @@
|
|||
|
||||
<main>
|
||||
<h1>Administration – {{title}}</h1>
|
||||
<h2>{{group.title}}</h2>
|
||||
|
||||
{{#if errors}}
|
||||
<div id="errors">
|
||||
|
@ -88,7 +89,7 @@
|
|||
|
||||
<p><a href="https://git.p2p.legal/tuxmain/gmarche-rs">Code source</a> sous licence <a href="https://www.gnu.org/licenses/licenses.html#AGPL">GNU AGPL v3</a>. 🦀 Écrit en <a href="https://www.rust-lang.org">Rust</a>. Images de Attilax.<br/>
|
||||
CopyLeft 2020-2022 Pascal Engélibert<br/>
|
||||
Image de fond : Claudia Peters, FreeImages.com</p>
|
||||
Image de fond : {{{bg_about}}}</p>
|
||||
|
||||
<p><a href="{{root_url}}">Accueil</a> – <a href="{{root_url}}admin/logout">Verrouiller</a></p>
|
||||
</footer>
|
||||
|
|
|
@ -7,14 +7,17 @@
|
|||
<link rel="shortcut icon" href="{{root_url}}static/icon.png"/>
|
||||
<script type="text/javascript" src="{{root_url}}static/script1.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<body style="background-image: linear-gradient(rgba(255,255,255,0.2),rgba(255,255,255,0.2)), url('/static/bg{{bg_id}}.jpg');">
|
||||
<div class="center page">
|
||||
<header>
|
||||
<a href="{{root_url}}"><img id="banner" alt="Bannière {{title}}" src="{{root_url}}static/banner.jpg"/></a>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<h1>{{group.title}} – Administration – {{title}}</h1>
|
||||
<h1>Administration – {{title}}</h1>
|
||||
<h2>{{group.title}}</h2>
|
||||
|
||||
<a href="{{root_url}}admin/g/{{group.parent}}">Groupe parent</a><br/>
|
||||
|
||||
{{#if errors}}
|
||||
<div id="errors">
|
||||
|
@ -88,7 +91,7 @@
|
|||
|
||||
<p><a href="https://git.p2p.legal/tuxmain/gmarche-rs">Code source</a> sous licence <a href="https://www.gnu.org/licenses/licenses.html#AGPL">GNU AGPL v3</a>. 🦀 Écrit en <a href="https://www.rust-lang.org">Rust</a>. Images de Attilax.<br/>
|
||||
CopyLeft 2020-2022 Pascal Engélibert<br/>
|
||||
Image de fond : Claudia Peters, FreeImages.com</p>
|
||||
Image de fond : {{{bg_about}}}</p>
|
||||
|
||||
<p><a href="{{root_url}}">Accueil</a> – <a href="{{root_url}}admin/logout">Verrouiller</a></p>
|
||||
</footer>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<link rel="stylesheet" href="{{root_url}}static/style1.css"/>
|
||||
<link rel="shortcut icon" href="{{root_url}}static/icon.png"/>
|
||||
</head>
|
||||
<body>
|
||||
<body style="background-image: linear-gradient(rgba(255,255,255,0.2),rgba(255,255,255,0.2)), url('/static/bg{{bg_id}}.jpg');">
|
||||
<div class="center page">
|
||||
<header>
|
||||
<a href="{{root_url}}"><img id="banner" alt="Bannière {{title}}" src="{{root_url}}static/banner.jpg"/></a>
|
||||
|
@ -43,7 +43,7 @@
|
|||
|
||||
<p><a href="https://git.p2p.legal/tuxmain/gmarche-rs">Code source</a> sous licence <a href="https://www.gnu.org/licenses/licenses.html#AGPL">GNU AGPL v3</a>. 🦀 Écrit en <a href="https://www.rust-lang.org">Rust</a>. Images de Attilax.<br/>
|
||||
CopyLeft 2020-2022 Pascal Engélibert<br/>
|
||||
Image de fond : Claudia Peters, FreeImages.com</p>
|
||||
Image de fond : {{{bg_about}}}</p>
|
||||
|
||||
<p><a href="{{root_url}}">Accueil</a></p>
|
||||
</footer>
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
<html lang="{{lang}}">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>{{group-title}} | {{title}}</title>
|
||||
<title>{{group.title}} | {{title}}</title>
|
||||
<link rel="stylesheet" href="{{root_url}}static/style1.css"/>
|
||||
<link rel="shortcut icon" href="{{root_url}}static/icon.png"/>
|
||||
<script type="text/javascript" src="{{root_url}}static/script1.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<body style="background-image: linear-gradient(rgba(255,255,255,0.2),rgba(255,255,255,0.2)), url('/static/bg{{bg_id}}.jpg');">
|
||||
<div class="center page">
|
||||
<header>
|
||||
<a href="{{root_url}}"><img id="banner" alt="Bannière {{title}}" src="{{root_url}}static/banner.jpg"/></a>
|
||||
|
@ -15,6 +15,9 @@
|
|||
|
||||
<main>
|
||||
<h1>{{title}}</h1>
|
||||
<h2>{{group.title}}</h2>
|
||||
|
||||
<a href="{{root_url}}admin/g/{{group.parent}}">Groupe parent</a><br/>
|
||||
|
||||
{{#if errors}}
|
||||
<div id="errors">
|
||||
|
@ -100,7 +103,7 @@
|
|||
|
||||
<p><a href="https://git.p2p.legal/tuxmain/gmarche-rs">Code source</a> sous licence <a href="https://www.gnu.org/licenses/licenses.html#AGPL">GNU AGPL v3</a>. 🦀 Écrit en <a href="https://www.rust-lang.org">Rust</a>. Images de Attilax.<br/>
|
||||
CopyLeft 2020-2022 Pascal Engélibert<br/>
|
||||
Image de fond : Claudia Peters, FreeImages.com</p>
|
||||
Image de fond : {{{bg_about}}}</p>
|
||||
|
||||
<p><a href="{{root_url}}admin">Administration</a></p>
|
||||
</footer>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<link rel="shortcut icon" href="{{root_url}}static/icon.png"/>
|
||||
<script type="text/javascript" src="{{root_url}}static/script1.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<body style="background-image: linear-gradient(rgba(255,255,255,0.2),rgba(255,255,255,0.2)), url('/static/bg{{bg_id}}.jpg');">
|
||||
<div class="center page">
|
||||
<header>
|
||||
<a href="{{root_url}}"><img id="banner" alt="Bannière {{title}}" src="{{root_url}}static/banner.jpg"/></a>
|
||||
|
@ -15,6 +15,7 @@
|
|||
|
||||
<main>
|
||||
<h1>{{title}}</h1>
|
||||
<h2>{{group.title}}</h2>
|
||||
|
||||
{{#if errors}}
|
||||
<div id="errors">
|
||||
|
@ -102,7 +103,7 @@
|
|||
|
||||
<p><a href="https://git.p2p.legal/tuxmain/gmarche-rs">Code source</a> sous licence <a href="https://www.gnu.org/licenses/licenses.html#AGPL">GNU AGPL v3</a>. 🦀 Écrit en <a href="https://www.rust-lang.org">Rust</a>. Images de Attilax.<br/>
|
||||
CopyLeft 2020-2022 Pascal Engélibert<br/>
|
||||
Image de fond : Claudia Peters, FreeImages.com</p>
|
||||
Image de fond : {{{bg_about}}}</p>
|
||||
|
||||
<p><a href="{{root_url}}admin">Administration</a></p>
|
||||
</footer>
|
||||
|
|
Loading…
Reference in New Issue