diff options
| author | Xe Iaso <me@christine.website> | 2022-07-04 16:35:14 +0000 |
|---|---|---|
| committer | Xe Iaso <me@christine.website> | 2022-07-04 16:35:14 +0000 |
| commit | 7f6de2cb092cdd0675ae393a0a737a2c08329046 (patch) | |
| tree | 29d74b18042f00f4b0d52cf3d9586135f5c9ce08 /lib | |
| parent | 8b6056fc09320473577f458fa86bda26159ea43b (diff) | |
| download | xesite-7f6de2cb092cdd0675ae393a0a737a2c08329046.tar.xz xesite-7f6de2cb092cdd0675ae393a0a737a2c08329046.zip | |
add _xesite_frontmatter extension
Signed-off-by: Xe Iaso <me@christine.website>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/jsonfeed/Cargo.toml | 2 | ||||
| -rw-r--r-- | lib/jsonfeed/src/builder.rs | 8 | ||||
| -rw-r--r-- | lib/jsonfeed/src/item.rs | 9 | ||||
| -rw-r--r-- | lib/xesite_types/Cargo.toml | 10 | ||||
| -rw-r--r-- | lib/xesite_types/src/lib.rs | 37 |
5 files changed, 66 insertions, 0 deletions
diff --git a/lib/jsonfeed/Cargo.toml b/lib/jsonfeed/Cargo.toml index 99172fd..ad17ccd 100644 --- a/lib/jsonfeed/Cargo.toml +++ b/lib/jsonfeed/Cargo.toml @@ -13,3 +13,5 @@ error-chain = "0.12" serde = "1" serde_derive = "1" serde_json = "1" + +xesite_types = { path = "../xesite_types" } diff --git a/lib/jsonfeed/src/builder.rs b/lib/jsonfeed/src/builder.rs index 640a280..4ce47a4 100644 --- a/lib/jsonfeed/src/builder.rs +++ b/lib/jsonfeed/src/builder.rs @@ -90,6 +90,7 @@ pub struct ItemBuilder { pub author: Option<Author>, pub tags: Option<Vec<String>>, pub attachments: Option<Vec<Attachment>>, + pub xesite_frontmater: Option<xesite_types::Frontmatter>, } impl ItemBuilder { @@ -108,6 +109,7 @@ impl ItemBuilder { author: None, tags: None, attachments: None, + xesite_frontmater: None, } } @@ -180,6 +182,11 @@ impl ItemBuilder { self } + pub fn xesite_frontmatter(mut self, fm: xesite_types::Frontmatter) -> ItemBuilder { + self.xesite_frontmater = Some(fm); + self + } + pub fn build(self) -> Result<Item> { if self.id.is_none() || self.content.is_none() { return Err("missing field 'id' or 'content_*'".into()); @@ -198,6 +205,7 @@ impl ItemBuilder { author: self.author, tags: self.tags, attachments: self.attachments, + xesite_frontmatter: self.xesite_frontmater, }) } } diff --git a/lib/jsonfeed/src/item.rs b/lib/jsonfeed/src/item.rs index 0f7d6ab..7b5d734 100644 --- a/lib/jsonfeed/src/item.rs +++ b/lib/jsonfeed/src/item.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::default::Default; use std::fmt; @@ -31,6 +32,9 @@ pub struct Item { pub author: Option<Author>, pub tags: Option<Vec<String>>, pub attachments: Option<Vec<Attachment>>, + + // xesite extensions + pub xesite_frontmatter: Option<xesite_types::Frontmatter>, } impl Item { @@ -55,6 +59,7 @@ impl Default for Item { author: None, tags: None, attachments: None, + xesite_frontmatter: None, } } } @@ -113,6 +118,9 @@ impl Serialize for Item { if self.attachments.is_some() { state.serialize_field("attachments", &self.attachments)?; } + if self.xesite_frontmatter.is_some() { + state.serialize_field("_xesite_frontmatter", &self.xesite_frontmatter)?; + } state.end() } } @@ -319,6 +327,7 @@ impl<'de> Deserialize<'de> for Item { author, tags, attachments, + xesite_frontmatter: None, }) } } diff --git a/lib/xesite_types/Cargo.toml b/lib/xesite_types/Cargo.toml new file mode 100644 index 0000000..5aec478 --- /dev/null +++ b/lib/xesite_types/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "xesite_types" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +chrono = { version = "0.4", features = [ "serde" ] } +serde = { version = "1.0", features = [ "derive" ] } diff --git a/lib/xesite_types/src/lib.rs b/lib/xesite_types/src/lib.rs new file mode 100644 index 0000000..68ae4c4 --- /dev/null +++ b/lib/xesite_types/src/lib.rs @@ -0,0 +1,37 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Eq, PartialEq, Deserialize, Default, Debug, Serialize, Clone)] +pub struct Frontmatter { + #[serde(default = "frontmatter_about")] + pub about: String, + #[serde(skip_serializing)] + pub title: String, + #[serde(skip_serializing)] + pub date: String, + #[serde(skip_serializing)] + pub author: Option<String>, + #[serde(skip_serializing_if = "Option::is_none")] + pub series: Option<String>, + #[serde(skip_serializing)] + pub tags: Option<Vec<String>>, + #[serde(skip_serializing_if = "Option::is_none")] + pub slides_link: Option<String>, + #[serde(skip_serializing_if = "Option::is_none")] + pub image: Option<String>, + #[serde(skip_serializing_if = "Option::is_none")] + pub thumb: Option<String>, + #[serde(skip_serializing)] + pub redirect_to: Option<String>, + #[serde(skip_serializing_if = "Option::is_none")] + pub vod: Option<Vod>, +} + +fn frontmatter_about() -> String { + "https://xeiaso.net/blog/api-jsonfeed-extensions#_xesite_frontmatter".to_string() +} + +#[derive(Eq, PartialEq, Deserialize, Default, Debug, Serialize, Clone)] +pub struct Vod { + pub twitch: String, + pub youtube: String, +} |
