Skip to main content

webserver_base/templates/schema/
metadata.rs

1use serde::{Deserialize, Serialize};
2
3use super::twitter::Twitter;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Metadata {
7    pub language_code: String,
8    pub country_code: String,
9    pub charset: String,
10    pub description: String,
11    pub project: String,
12    pub author: String,
13    pub twitter: Twitter,
14    pub home_url: String,
15    pub keywords: Vec<String>,
16    pub theme_color: String,
17    pub social_image: String,
18}
19
20impl Metadata {
21    #[expect(clippy::too_many_arguments)]
22    #[must_use]
23    pub fn new(
24        language_code: String,
25        country_code: String,
26        charset: String,
27        description: String,
28        project: String,
29        author: String,
30        twitter: Twitter,
31        home_url: String,
32        keywords: Vec<String>,
33        theme_color: String,
34        social_image: String,
35    ) -> Self {
36        Self {
37            language_code,
38            country_code,
39            charset,
40            description,
41            project,
42            author,
43            twitter,
44            home_url,
45            keywords,
46            theme_color,
47            social_image,
48        }
49    }
50
51    #[must_use]
52    pub fn new_with_defaults(
53        project_description: &str,
54        project_name: &str,
55        home_url: &str,
56        keywords: &str,
57        theme_color: &str,
58        social_image: &str,
59    ) -> Self {
60        let keywords: Vec<String> = keywords
61            .split(',')
62            .map(String::from)
63            .collect::<Vec<String>>();
64
65        Self::new(
66            String::from("en"),
67            String::from("US"),
68            String::from("utf-8"),
69            String::from(project_description),
70            String::from(project_name),
71            String::from("Todd Everett Griffin"),
72            Twitter::new(String::from("@goddtriffin")),
73            String::from(home_url),
74            keywords,
75            String::from(theme_color),
76            String::from(social_image),
77        )
78    }
79}