diff --git a/src/app/models/mod.rs b/src/app/models/mod.rs index 40d1b51..69d39bb 100644 --- a/src/app/models/mod.rs +++ b/src/app/models/mod.rs @@ -1,3 +1,7 @@ mod post; -pub use post::Post; \ No newline at end of file +pub use post::Post; + +mod tag; + +pub use tag::{Tags, Tag}; diff --git a/src/app/models/tag.rs b/src/app/models/tag.rs new file mode 100644 index 0000000..dda9a88 --- /dev/null +++ b/src/app/models/tag.rs @@ -0,0 +1,41 @@ +use std::collections::HashMap; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Serialize, Deserialize, Debug)] +pub struct Tag { + pub name : String, + pub url : String, + pub groups : Vec, +} + +#[derive(Clone, Serialize, Deserialize, Debug)] +pub struct Tags { + pub tags : HashMap, +} + +cfg_if::cfg_if! { + if #[cfg(feature = "ssr")] { + impl Tags { + fn from_content(content: String) -> Option { + let tags = serde_yaml::from_str(&content).ok()?; + + Some(Self { + tags + }) + } + + fn from_path(path: &std::path::Path) -> Option { + let content = std::fs::read_to_string(path); + let content = match content { + Ok(content) => content, + Err(e) => { + eprintln!("{:?}", e); + return None; + } + }; + + Self::from_content(content) + } + } + } +}