💥 Optional title and description in pages
This commit is contained in:
parent
861a9648e8
commit
03dbb39bbc
2 changed files with 6 additions and 11 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::base::component::L10n;
|
|
||||||
use crate::core::component::{ComponentTrait, Context};
|
use crate::core::component::{ComponentTrait, Context};
|
||||||
use crate::core::module::ModuleTrait;
|
use crate::core::module::ModuleTrait;
|
||||||
use crate::html::{html, Favicon, Markup};
|
use crate::html::{html, Favicon, Markup};
|
||||||
|
|
@ -51,20 +50,18 @@ pub trait ThemeTrait: ModuleTrait + Send + Sync {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_head(&self, page: &mut Page) -> Markup {
|
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";
|
let viewport = "width=device-width, initial-scale=1, shrink-to-fit=no";
|
||||||
html! {
|
html! {
|
||||||
head {
|
head {
|
||||||
meta charset="utf-8";
|
meta charset="utf-8";
|
||||||
|
|
||||||
@if !title.is_empty() {
|
@if let Some(title) = page.title() {
|
||||||
title { (config::SETTINGS.app.name) (" - ") (title) }
|
title { (config::SETTINGS.app.name) (" - ") (title) }
|
||||||
} @else {
|
} @else {
|
||||||
title { (config::SETTINGS.app.name) }
|
title { (config::SETTINGS.app.name) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@if !description.is_empty() {
|
@if let Some(description) = page.description() {
|
||||||
meta name="description" content=(description);
|
meta name="description" content=(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,14 +100,12 @@ impl Page {
|
||||||
|
|
||||||
// Page GETTERS.
|
// Page GETTERS.
|
||||||
|
|
||||||
pub fn title(&mut self) -> String {
|
pub fn title(&mut self) -> Option<String> {
|
||||||
self.title.using(self.context.langid()).unwrap_or_default()
|
self.title.using(self.context.langid())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn description(&mut self) -> String {
|
pub fn description(&mut self) -> Option<String> {
|
||||||
self.description
|
self.description.using(self.context.langid())
|
||||||
.using(self.context.langid())
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn metadata(&self) -> &Vec<(&str, &str)> {
|
pub fn metadata(&self) -> &Vec<(&str, &str)> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue