Skip to content

Commit

Permalink
add is_draft field to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurk committed Nov 16, 2023
1 parent 93156ee commit 9c5cf90
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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)"
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
//!
//! ## 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
//! ---
//! title: Yamd - yet another markdown document flavour
//! 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
Expand Down
8 changes: 7 additions & 1 deletion src/nodes/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct Metadata {
pub preview: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_draft: Option<bool>,
#[serde(skip)]
pub consumed_length: Option<usize>,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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()),
Expand All @@ -156,6 +160,7 @@ mod tests {
image: None,
preview: None,
tags: None,
is_draft: None,
consumed_length: Some(7)
})
);
Expand All @@ -176,6 +181,7 @@ mod tests {
date: None,
image: None,
tags: None,
is_draft: None,
consumed_length: Some(21)
})
);
Expand Down
1 change: 1 addition & 0 deletions src/nodes/yamd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down

0 comments on commit 9c5cf90

Please sign in to comment.