aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-02-12 01:39:00 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2024-02-12 01:39:00 +0000
commit2b8623fde242d379c66e4c532f7cad0dbb2198aa (patch)
treed875588258b57998a1e089a17124e21e9632059b /src/main.rs
parent82ef62654f58eb6212fad1beb3adb2c1c979fb56 (diff)
downloadblossom-2b8623fde242d379c66e4c532f7cad0dbb2198aa.tar.gz
blossom-2b8623fde242d379c66e4c532f7cad0dbb2198aa.tar.bz2
blossom-2b8623fde242d379c66e4c532f7cad0dbb2198aa.zip
add language select widget
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index d810159..8e31fee 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@ mod article;
mod atom;
mod blog;
mod error;
+mod i18n;
mod live;
mod poetry;
mod posts;
@@ -14,9 +15,12 @@ mod utils;
use std::{collections::HashSet, time::Duration};
+use i18n::set_language;
use poem::http::StatusCode;
use poem::i18n::unic_langid::langid;
-use poem::i18n::{I18NResources, Locale};
+use poem::i18n::I18NResources;
+use poem::session::{CookieConfig, CookieSession, ServerSession};
+use poem::web::cookie::{CookieKey, SameSite};
use poem::{
endpoint::EmbeddedFilesEndpoint,
get, handler,
@@ -36,6 +40,7 @@ use tracing_subscriber::FmtSubscriber;
use crate::article::Article;
use crate::blog::Blogpost;
+use crate::i18n::Locale;
use crate::poetry::Poem;
use crate::posts::Post;
@@ -208,6 +213,14 @@ async fn main() -> std::result::Result<(), std::io::Error> {
.build()
.unwrap();
+ let session = CookieSession::new(
+ // CookieConfig::private(CookieKey::generate())
+ // .name("blossom")
+ // .domain("blos.sm")
+ // .same_site(SameSite::Strict),
+ CookieConfig::default(),
+ );
+
let blossom = Route::new()
.at("/", get(home))
.at("/blog", get(get_blog))
@@ -220,7 +233,9 @@ async fn main() -> std::result::Result<(), std::io::Error> {
.nest("/static/", EmbeddedFilesEndpoint::<Static>::new())
.catch_all_error(custom_error)
.data(resources)
+ .around(set_language)
.with(Tracing)
+ .with(session)
.with(AddData::new(
reqwest::Client::builder()
.connect_timeout(Duration::from_secs(1))