Skip to content

Commit

Permalink
Merge pull request #3 from ekkolon/feat-website-metadata-builder
Browse files Browse the repository at this point in the history
Refine `ObjectType` properties
  • Loading branch information
ekkolon committed Dec 3, 2023
2 parents c7a8e67 + 034cfa6 commit 7fb309f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub struct Metadata {
pub site_name: Option<String>,

/// The title of your article without any branding such as your site name.
#[serde(rename = "og:determinator")]
pub determinator: Option<String>,
#[serde(rename = "og:determiner")]
pub determiner: Option<String>,

/// The title of your article without any branding such as your site name.
#[serde(rename = "og:locale")]
Expand Down Expand Up @@ -145,11 +145,8 @@ impl MetadataBuilder {
self
}

pub fn set_determinator(
&mut self,
determinator: impl Into<String>,
) -> &mut Self {
self.metadata.determinator.insert(determinator.into());
pub fn set_determiner(&mut self, determiner: impl Into<String>) -> &mut Self {
self.metadata.determiner.insert(determiner.into());
self
}

Expand Down
50 changes: 50 additions & 0 deletions src/object_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,53 @@ pub enum ObjectType {
#[serde(rename = "website")]
Website,
}

impl ObjectType {
pub fn from_string(value: impl Into<String>) -> ObjectType {
let obj_type: &str = &value.into();

match obj_type {
"article" => ObjectType::Article,
"book" => ObjectType::Book,
"profile" => ObjectType::Profile,
"website" => ObjectType::Website,
"music.song" => ObjectType::MusicSong,
"music.album" => ObjectType::MusicAlbum,
"music.playlist" => ObjectType::MusicPlaylist,
"music.radio_station" => ObjectType::MusicRadioStation,
"video.movie" => ObjectType::VideoMovie,
"video.episode" => ObjectType::VideoEpisode,
"video.tv_show" => ObjectType::VideoTvShow,
"video.other" => ObjectType::VideoOther,
_ => ObjectType::Website,
}
}
}

#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq)]
pub enum Determiner {
#[serde(rename = "a")]
A,
#[serde(rename = "an")]
An,
#[serde(rename = "the")]
The,
#[default]
#[serde(rename = "")]
Blank,
#[serde(rename = "auto")]
Auto,
}

impl Determiner {
pub fn from_string(value: impl Into<String>) -> Determiner {
let determ: &str = &value.into();
match determ {
"a" => Determiner::A,
"an" => Determiner::An,
"the" => Determiner::The,
"auto" => Determiner::Auto,
_ => Determiner::Blank,
}
}
}

0 comments on commit 7fb309f

Please sign in to comment.