fix metadata?

This commit is contained in:
Mylloon 2023-10-24 12:21:30 +02:00
parent 73b059b155
commit 68814cdd20
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 24 additions and 22 deletions

View file

@ -115,6 +115,7 @@ pub fn get_config(file_path: &str) -> Config {
directory: format!("{}/{}", files_root, templates_dir),
app_name: internal_config.app_name.unwrap(),
url: internal_config.domain.unwrap(),
name: internal_config.name,
},
}
}

View file

@ -9,6 +9,8 @@ pub struct Template {
pub app_name: String,
/// URL of app
pub url: String,
/// Name of user
pub name: Option<String>,
}
/// Structure used by /routes/*.rs
@ -45,15 +47,12 @@ struct Data<T> {
page_desc: Option<String>,
/// Keywords of the the page
page_kw: Option<String>,
/// Author's name
page_author: Option<String>,
/// Data needed to render the page
data: T,
}
/// Add quotes around a string
fn add_quotes(string: String) -> String {
format!("\"{}\"", string)
}
impl Template {
pub fn render<C: Content>(&self, template: &str, data: C, info: Infos) -> String {
let mut templates: Ramhorns = Ramhorns::lazy(&self.directory).unwrap();
@ -61,10 +60,11 @@ impl Template {
tplt.render(&Data {
app_name: self.app_name.to_owned(),
url: add_quotes(self.url.to_owned()),
url: self.url.to_owned(),
page_title: info.page_title,
page_desc: info.page_desc.map(add_quotes),
page_kw: info.page_kw.map(add_quotes),
page_desc: info.page_desc,
page_kw: info.page_kw,
page_author: self.name.clone(),
data,
})
}

View file

@ -2,28 +2,29 @@
{{#page_title}}
<meta name="title" content="{{page_title}} " />
{{/page_title}} {{#page_desc}}
<!-- prettier-ignore-attribute content -->
<meta name="description" content={{&page_desc}} />
<meta name="description" content="{{page_desc}} " />
{{/page_desc}} {{#page_kw}}
<!-- prettier-ignore-attribute content -->
<meta name="keywords" content={{&page_kw}} />
{{/page_kw}}
<meta name="author" content="Mylloon" />
<meta name="keywords" content="{{page_kw}} " />
{{/page_kw}} {{#page_author}}
<meta name="author" content="{{page_author}} " />
{{/page_author}}
<!-- Open Graph -->
{{#page_title}}
<meta property="og:title" content="{{page_title}} " />
<!-- prettier-ignore-attribute content -->
<meta property="og:description" content={{&page_desc}} />
<!-- prettier-ignore-attribute content -->
<meta property="og:url" content={{&url}} />
{{/page_title}} {{#page_desc}}
<meta property="og:description" content="{{page_desc}} " />
{{/page_desc}}
<meta property="og:url" content="{{url}} " />
<meta property="og:image" content="/icons/apple-touch-icon.png" />
<meta property="og:type" content="website" />
<meta name="theme-color" content="#43B581" />
<!-- Twitter -->
{{#page_title}}
<meta property="twitter:title" content="{{page_title}} " />
<!-- prettier-ignore-attribute content -->
<meta property="twitter:description" content={{&page_desc}} />
<!-- prettier-ignore-attribute content -->
<meta property="twitter:url" content={{&url}} />
{{/page_title}} {{#page_desc}}
<meta property="twitter:description" content="{{page_desc}} " />
{{/page_desc}}
<meta property="twitter:url" content="{{url}} " />
<meta property="twitter:image" content="/icons/apple-touch-icon.png" />