From 9c5cf900c0cd474e76fe8f6a8ff1c10ca48186ce Mon Sep 17 00:00:00 2001 From: Serhiy Barhamon Date: Thu, 16 Nov 2023 22:20:57 +0100 Subject: [PATCH] add is_draft field to metadata --- Cargo.toml | 2 +- src/lib.rs | 7 +++++-- src/nodes/metadata.rs | 8 +++++++- src/nodes/yamd.rs | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d30f2dc..2c03248 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yamd" -version = "0.10.0" +version = "0.11.0" edition = "2021" license = "MIT OR Apache-2.0" description = "Yet Another Markdown Document (flavor)" diff --git a/src/lib.rs b/src/lib.rs index f408efe..33520b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,13 +4,15 @@ //! //! ## Syntax //! -//! Each yamd document starts with metadata section which is YAML document surrounded by "---". Metadata has five -//! fields: title, date, image, preview, and tags. +//! Each yamd document starts with metadata section which is YAML document surrounded by "---". Metadata has next +//! fields: title, date, image, preview, is_draft, and tags. //! //! Timestamp format: "%Y-%m-%dT%H:%M:%S%z" ([specifiers description](https://docs.rs/chrono/latest/chrono/format/strftime/index.html)) //! //! Tags are array of strings. //! +//! is_draft is a boolean value. +//! //! Example: //! ```text //! --- @@ -18,6 +20,7 @@ //! date: 2023-01-01 00:00:00 +0000 //! image: /image.png //! preview: Here you can find out more about yamd +//! is_draft: true //! tags: //! - markdown //! - rust diff --git a/src/nodes/metadata.rs b/src/nodes/metadata.rs index 7505889..07a883b 100644 --- a/src/nodes/metadata.rs +++ b/src/nodes/metadata.rs @@ -16,6 +16,8 @@ pub struct Metadata { pub preview: Option, #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub is_draft: Option, #[serde(skip)] pub consumed_length: Option, } @@ -33,6 +35,7 @@ impl Metadata { date: timestamp, image: image.map(|i| i.into()), preview: preview.map(|p| p.into()), + is_draft: None, tags, consumed_length: None, } @@ -138,7 +141,8 @@ mod tests { image: Some("image".to_string()), preview: Some("preview".to_string()), tags: Some(vec!["tag1".to_string(), "tag2".to_string()]), - consumed_length: Some(102), + is_draft: Some(true), + consumed_length: Some(117), }; assert_eq!( Metadata::deserialize(metadata.to_string().as_str()), @@ -156,6 +160,7 @@ mod tests { image: None, preview: None, tags: None, + is_draft: None, consumed_length: Some(7) }) ); @@ -176,6 +181,7 @@ mod tests { date: None, image: None, tags: None, + is_draft: None, consumed_length: Some(21) }) ); diff --git a/src/nodes/yamd.rs b/src/nodes/yamd.rs index a509a5b..8b75a7c 100644 --- a/src/nodes/yamd.rs +++ b/src/nodes/yamd.rs @@ -333,6 +333,7 @@ end"#; image: Some("image".to_string()), preview: Some("preview".to_string()), tags: Some(vec!["tag1".to_string(), "tag2".to_string()]), + is_draft: None, consumed_length: Some(101), }), vec![