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), directory: format!("{}/{}", files_root, templates_dir),
app_name: internal_config.app_name.unwrap(), app_name: internal_config.app_name.unwrap(),
url: internal_config.domain.unwrap(), url: internal_config.domain.unwrap(),
name: internal_config.name,
}, },
} }
} }

View file

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

View file

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