diff options
author | cel 🌸 <cel@blos.sm> | 2024-01-31 18:55:36 +0000 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2024-01-31 18:55:36 +0000 |
commit | d1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0 (patch) | |
tree | c54999785bf7ae865ca571a475da222e9e376873 /src/poetry.rs | |
parent | b78d026c242e8d95e611e050afd5b72eb562d56d (diff) | |
download | blossom-d1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0.tar.gz blossom-d1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0.tar.bz2 blossom-d1bfe2eb0ba8836d4eef4ca5dd6e20611dc3a8c0.zip |
changed Post tags() to return a Vec<&str>
Diffstat (limited to 'src/poetry.rs')
-rw-r--r-- | src/poetry.rs | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/poetry.rs b/src/poetry.rs index f5f194c..6429bd3 100644 --- a/src/poetry.rs +++ b/src/poetry.rs @@ -1,6 +1,10 @@ use chrono::{DateTime, Utc}; +use serde::Deserialize; -use crate::posts::Post; +use crate::Result; +use crate::{article::Article, posts::Post}; + +static DIRECTORY: &str = "./poetry"; pub struct Poem { file_name: String, @@ -13,6 +17,41 @@ pub struct Poem { lang: String, } +#[derive(Deserialize)] +pub struct PoemMetadata { + title: Option<String>, + created_at: String, + published_at: String, + updated_at: Option<String>, +} + +impl Article for Poem { + type Article = Poem; + + type Metadata = PoemMetadata; + + fn directory() -> &'static str { + DIRECTORY + } + + fn new(file_name: String, metadata: Self::Metadata, content: String) -> Result<Self::Article> { + let updated_at = if let Some(updated_at) = metadata.updated_at { + Some(updated_at.parse::<DateTime<Utc>>()?) + } else { + None + }; + Ok(Poem { + file_name, + title: metadata.title, + created_at: metadata.created_at.parse::<DateTime<Utc>>()?, + published_at: metadata.published_at.parse::<DateTime<Utc>>()?, + updated_at, + content, + lang: "en".to_string(), + }) + } +} + impl Post for Poem { fn id(&self) -> &str { &self.file_name @@ -30,8 +69,8 @@ impl Post for Poem { self.updated_at.as_ref() } - fn tags(&self) -> &Vec<String> { - todo!() + fn tags(&self) -> Vec<&str> { + vec!["poetry"] } fn lang(&self) -> &str { |