From 7f6de2cb092cdd0675ae393a0a737a2c08329046 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Mon, 4 Jul 2022 16:35:14 +0000 Subject: add _xesite_frontmatter extension Signed-off-by: Xe Iaso --- lib/jsonfeed/src/builder.rs | 8 ++++++++ lib/jsonfeed/src/item.rs | 9 +++++++++ 2 files changed, 17 insertions(+) (limited to 'lib/jsonfeed/src') 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, pub tags: Option>, pub attachments: Option>, + pub xesite_frontmater: Option, } 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 { 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, pub tags: Option>, pub attachments: Option>, + + // xesite extensions + pub xesite_frontmatter: Option, } 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, }) } } -- cgit v1.2.3