diff --git a/minijinja/blog/block_post_content.jinja b/minijinja/blog/block_post_content.jinja index 9477ea2..d5dc2a1 100644 --- a/minijinja/blog/block_post_content.jinja +++ b/minijinja/blog/block_post_content.jinja @@ -32,7 +32,7 @@ - {{ cat.title }} + {{ cat.title_vi if lang == 'vi' and cat.title_vi else cat.title }} {% else %} Uncategorized diff --git a/minijinja/navbar.jinja b/minijinja/navbar.jinja index 5f730b7..1862247 100644 --- a/minijinja/navbar.jinja +++ b/minijinja/navbar.jinja @@ -41,7 +41,7 @@ x-show='open' x-on:click.away='open = false' x-cloak> {% for cat in categories %}
  • - {{ cat.title }} + {{ cat.title_vi if lang == 'vi' and cat.title_vi else cat.title }}
  • {% endfor %}
  • diff --git a/src/front/views/mod.rs b/src/front/views/mod.rs index c2337ff..8c94681 100644 --- a/src/front/views/mod.rs +++ b/src/front/views/mod.rs @@ -1,39 +1,41 @@ pub mod blog; -pub mod minors; pub mod feeds; +pub mod minors; pub mod old_urls; use std::num::NonZeroU16; -use axum_sessions::extractors::{WritableSession, ReadableSession}; use axum::extract::Form; -use serde::ser::Serialize; -use minijinja::Environment; -use http::{StatusCode, Uri, HeaderName}; -use axum::extract::{Query, State, OriginalUri}; +use axum::extract::{OriginalUri, Query, State}; use axum::response::{Html, IntoResponse, Result as AxumResult}; +use axum_sessions::extractors::{ReadableSession, WritableSession}; +use http::{HeaderName, StatusCode, Uri}; use minijinja::context; +use minijinja::Environment; +use serde::ser::Serialize; use unic_langid::LanguageIdentifier; -pub use crate::errors::PageError; -use crate::auth::Auth; -use crate::types::{AppState, Paginator, StaticFile}; use super::structs::{LaxPaging, SetLangReq}; +use crate::auth::Auth; +use crate::consts::{DEFAULT_LANG, DEFAULT_PAGE_SIZE, KEY_LANG, STATIC_URL}; +pub use crate::errors::PageError; use crate::stores; -use crate::consts::{DEFAULT_PAGE_SIZE, STATIC_URL, KEY_LANG, DEFAULT_LANG}; +use crate::types::{AppState, Paginator, StaticFile}; -pub fn render_with(template_name: &str, context: S, engine: Environment) -> Result { +pub fn render_with( + template_name: &str, + context: S, + engine: Environment, +) -> Result { let tpl = engine.get_template(template_name)?; let content = tpl.render(context)?; Ok(content) } - pub async fn fallback_view() -> (StatusCode, &'static str) { (StatusCode::NOT_FOUND, "Not found") } - pub async fn home( auth: Auth, OriginalUri(current_url): OriginalUri, @@ -65,7 +67,9 @@ pub async fn home( .await .map_err(PageError::EdgeDBQueryError)?; let no_tracking = auth.current_user.is_some(); - let lang = session.get::(KEY_LANG).unwrap_or(DEFAULT_LANG.into()); + let lang = session + .get::(KEY_LANG) + .unwrap_or(DEFAULT_LANG.into()); let context = context!( lang => lang, posts => posts, @@ -89,10 +93,17 @@ pub async fn static_handler(uri: Uri) -> impl IntoResponse { type HTMXResponse = ([(HeaderName, &'static str); 1], Html); -pub async fn set_lang(mut session: WritableSession, Form(payload): Form) -> AxumResult -{ - let li: LanguageIdentifier = payload.lang.parse().map_err(|_e| StatusCode::UNPROCESSABLE_ENTITY)?; - session.insert(KEY_LANG, li.clone()).map_err(|_e| StatusCode::SERVICE_UNAVAILABLE)?; +pub async fn set_lang( + mut session: WritableSession, + Form(payload): Form, +) -> AxumResult { + let li: LanguageIdentifier = payload + .lang + .parse() + .map_err(|_e| StatusCode::UNPROCESSABLE_ENTITY)?; + session + .insert(KEY_LANG, li.clone()) + .map_err(|_e| StatusCode::SERVICE_UNAVAILABLE)?; let lang_code = li.to_string(); let header_name = HeaderName::from_static("hx-refresh"); let r = ([(header_name, "true")], Html(lang_code));