💥 Optional title and description in pages

This commit is contained in:
Manuel Cillero 2023-10-21 21:23:38 +02:00
parent 861a9648e8
commit 03dbb39bbc
2 changed files with 6 additions and 11 deletions

View file

@ -1,4 +1,3 @@
use crate::base::component::L10n;
use crate::core::component::{ComponentTrait, Context};
use crate::core::module::ModuleTrait;
use crate::html::{html, Favicon, Markup};
@ -51,20 +50,18 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
}
fn prepare_head(&self, page: &mut Page) -> Markup {
let title = page.title();
let description = page.description();
let viewport = "width=device-width, initial-scale=1, shrink-to-fit=no";
html! {
head {
meta charset="utf-8";
@if !title.is_empty() {
@if let Some(title) = page.title() {
title { (config::SETTINGS.app.name) (" - ") (title) }
} @else {
title { (config::SETTINGS.app.name) }
}
@if !description.is_empty() {
@if let Some(description) = page.description() {
meta name="description" content=(description);
}

View file

@ -100,14 +100,12 @@ impl Page {
// Page GETTERS.
pub fn title(&mut self) -> String {
self.title.using(self.context.langid()).unwrap_or_default()
pub fn title(&mut self) -> Option<String> {
self.title.using(self.context.langid())
}
pub fn description(&mut self) -> String {
self.description
.using(self.context.langid())
.unwrap_or_default()
pub fn description(&mut self) -> Option<String> {
self.description.using(self.context.langid())
}
pub fn metadata(&self) -> &Vec<(&str, &str)> {